Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Cancel Recur Subscription test & setter for supports on Dummy processor #21895

Merged
merged 2 commits into from
Feb 23, 2022

Conversation

kartik1000
Copy link
Contributor

@kartik1000 kartik1000 commented Oct 20, 2021

Overview

Added Test in follow up to #18196. Have also added a function in CRM_Core_Payment_Dummy to set the return value for support functions.

This also allows the capabilities supported by the Dummy processor to be set from outside the class. This is done by adding a support array where the capabilities are initially set to TRUE but can be altered by using the setSupports Function. This can be highly useful to alter the capabilities of dummy processors from directly outside the class in future tests as well.

Comments

Functions used within the test have been extended from RecurForms.php added in #21588

@civibot
Copy link

civibot bot commented Oct 20, 2021

(Standard links)

@civibot civibot bot added the master label Oct 20, 2021
/**
* Class CRM_Contribute_Form_CancelRecurSubscriptionTest
*/
class CRM_Contribute_Form_CancelRecurSubscriptionTest extends CRM_Contribute_Form_RecurForms {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kartik1000 there is already a test class CRM_Contribute_Form_CancelSubscriptionTest which covers this form (& better matches the form class name) - can you add your test to that rather than add this class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kartik1000 please update per suggestion

@@ -17,6 +17,16 @@
class CRM_Core_Payment_Manual extends CRM_Core_Payment {

protected $result;
protected $_supports = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach is generally fine - we have been moving away from the underscore in class property names though - see the property above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kartik1000 Sorry I gave you this example :-) Please change to protected $supports =

@eileenmcnaughton
Copy link
Contributor

I think this makes sense. Minor comments inline

@mattwire
Copy link
Contributor

@kartik1000 The changes for $supports should be made on CRM_Core_Payment_Dummy and not CRM_Core_Payment_Manual because we use Dummy for testing. Manual is used for pay later and also extended by some extensions.

@kartik1000
Copy link
Contributor Author

@kartik1000 The changes for $supports should be made on CRM_Core_Payment_Dummy and not CRM_Core_Payment_Manual because we use Dummy for testing. Manual is used for pay later and also extended by some extensions.
@mattwire the processor created in addContribution() function is an instance of ‘CRM_Core_Payment_Manual’. I tried making changes in ‘CRM_Core_Payment_Dummy’ but it was not working as we are not creating an instance of it. Since, I am building on Eileen’s test, therefore I decided to continue with the same functions and thus make required changes in ‘CRM_Core_Payment_Manual’.

@eileenmcnaughton eileenmcnaughton changed the title Added Cancel Recur Subscription test Added Cancel Recur Subscription test & setter for supports on Dummy processor Oct 21, 2021
@eileenmcnaughton
Copy link
Contributor

@kartik1000 I updated the PR template slightly to reflect your setter for supports but I think it maybe needs more details about how it would be used - in the PR template & in code comments. There is no obvious core reason to do this. I'm Ok wtih this as a minor change in core to support an outside-core usage but a future 'cleaner-upper' might need to know the rationale to prevent them from saying 'that's silly why don't we just do x'

@kartik1000
Copy link
Contributor Author

@kartik1000 I updated the PR template slightly to reflect your setter for supports but I think it maybe needs more details about how it would be used - in the PR template & in code comments. There is no obvious core reason to do this. I'm Ok wtih this as a minor change in core to support an outside-core usage but a future 'cleaner-upper' might need to know the rationale to prevent them from saying 'that's silly why don't we just do x'

@eileenmcnaughton I agree, I will add a description both in template PR and the in code comments (above the support variable preferably).

@kartik1000
Copy link
Contributor Author

@eileenmcnaughton I have updated the PR description and added the same in in-code comments as well.

@@ -17,6 +17,8 @@
class CRM_Core_Payment_Manual extends CRM_Core_Payment {

protected $result;
// This support variable is used to allow the capabilities supported by the Dummy processor to be set from outside the class.
// Initially these capabilities are set to TRUE, however they can be altered by calling the setSupports function directly from outside the class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kartik1000 can you go a bit further & explain why someone would wan to do that? Your use case.

@demeritcowboy
Copy link
Contributor

I admit I'm confused by this

allow the capabilities supported by the Dummy processor to be set from outside the class

Wouldn't you just update the processor to support other capabilities?

@mattwire
Copy link
Contributor

Wouldn't you just update the processor to support other capabilities?

@demeritcowboy Normally yes. But dummy is being used here as a special case for testing. By "dynamically" updating the capabilities we can test multiple scenarios that would otherwise be untestable without finding/creating payment processors with specific combinations of "supportsX". And you get scenarios like eg. Stripe doesn't support updateSubscription but will do so if you chose that to test that "a processor does not support updateSubscription" the test would break once you introduce the new feature.

@demeritcowboy
Copy link
Contributor

Ok thanks I see. So then the remaining issues are:

  • Should it be Dummy or Manual?
  • There were test fails but they've disappeared now. Whatever that was about.

I think using "settings" over the Power of OO can be justified to avoid hundreds of subclasses. Just at the point where some function starts getting nested if supports this then (if not supports that but supports other thing then ...) else if (it's Tuesday...) a subclass should be created.

@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton
Copy link
Contributor

I'm actually OK with this being on Dummy or Manual or the parent class (would require a bit more care to ensure no defaults change) - but I don't know how interested @kartik1000 is in doing more on it

@demeritcowboy
Copy link
Contributor

Test fail is:

Manual.php:22 | VariableComment | WrongStyle | Error
You must use "/**" style comments for a member variable comment

@@ -18,6 +18,22 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {

protected $result;

/**
* This support variable is used to allow the capabilities supported by the Dummy processor to be set from outside the class.
* Initially these capabilities are set to TRUE, however they can be altered by calling the setSupports function directly from outside the class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're updating this anyway can we add some more explanation, and it's not the Dummy processor. Maybe something like

This support variable is used to allow the capabilities supported by the Manual processor to be set from unit tests so that we don't need to create a lot of new processors to test combinations of features.

@mattwire
Copy link
Contributor

Now cleaned up and tests should pass. Changes should be on Dummy processor because that's what is usually used in tests and it already has other "infrastructure" for testing (eg. setting doPayment result).
#22784 is the reason that @kartik1000 put it on Manual processor because there was a bug in the tests for setting payment processor.

@mattwire mattwire force-pushed the Test#18196 branch 3 times, most recently from 71f5b90 to 19c24ff Compare February 18, 2022 11:39
@demeritcowboy demeritcowboy added the merge ready PR will be merged after a few days if there are no objections label Feb 18, 2022
@demeritcowboy demeritcowboy merged commit 9ed895d into civicrm:master Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-test master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants