-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
dev/core#4088 Convert api4 helper functionality to a trait & make available #25412
Conversation
No issue was found matching the number given in the pull request title. Please check the issue number. |
(Standard links)
|
2340aa8
to
be7acd2
Compare
unset($record); | ||
$saved = civicrm_api4($entityName, 'save', $saveParams); | ||
foreach ($saved as $item) { | ||
$this->testRecords[] = [$entityName, [[$idField, '=', $item[$idField]]]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this $testRecords
property be extracted too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as in setTestRecords
& addTestRecord
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in public $testRecords = [];
or protected $testRecords = [];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm yeah ok - I'll add the getters & setters too if I'm going that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually - it can be private so I don't need them
be7acd2
to
937d757
Compare
Civi/Test/Api4TestTrait.php
Outdated
* @param int $len | ||
* @return string | ||
*/ | ||
protected function randomLetters(int $len = 10): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is called from one child class - tbh I'd rather make it private & have that class do it's own thing
Civi/Test/Api4TestTrait.php
Outdated
* @return array | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
public function getRequiredValuesToCreate(string $entity, array &$values = []): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is protected as the Conformance calls it directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we return $values
- maybe we can not pass-by-ref as well....
Civi/Test/Api4TestTrait.php
Outdated
* | ||
* @package Civi\Test | ||
* | ||
* This trait defines a number of helper functions for testing APIv4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd find it easier to understand with some kind of pointer about how to use the class. (Which of the 8 helpers should I care about?) Maybe like:
* This trait defines a number of helper functions for testing APIv4. | |
* Define helpers for generating, tracking, and cleaning test-data with APIv4. Specifically: | |
* - `createTestRecord()` will autofill a new record with example data. | |
* - `deleteTestRecords()` will batch-delete all the test-data created by `createTestRecord()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - I think those might be the only ones we would encourage people to use so that's probably right - I'm trying to privatise as much else as I can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten I've updated this but what I found is there are 2 functions
createTestRecord()
saveTestRecords()
I suppose that's consistent with apiv4 but it feels like they should use the same verb - given it would be work to change I am VERY happy to be convinced otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, they both use the APIv4 save
action, so changing to saveTestRecord()
would be more consistent all-round.
@eileenmcnaughton once you have resolved the comments from Tim I would say this is MOP |
@seamuslee001 thanks - I got one fail - not sure if it is co-incidental or related - trying again api\v4\Entity\ManagedEntityTest::testRevertSavedSearch /home/jenkins/bknix-dfl/build/build-1/web/sites/all/modules/civicrm/tests/phpunit/api/v4/Entity/ManagedEntityTest.php:119 |
500c7ff
to
09b8d53
Compare
Hmm - well I made it worse there! Fortunately local fails too so I'll find & fix |
It was doing both pass-by-ref and return to give back the value - this settles on using return.
I'm not sure if the test fail was an intermittent or related but this seems cleaner
09b8d53
to
72d3d0e
Compare
@seamuslee001 @totten it is passing now - the only hesitation I have is #25412 (comment) - but that is also ok for a follow up if we dither |
@eileenmcnaughton +1 on changing
I've seen a lot of unit-test authors struggle with the concept of cleanup. A lot of people try to clean stuff (if they do it at all) by putting some
|
@colemanw ok - I think both the rename & the tearDown fix are going to each involve touching quite a few classes so I think it would be helpful if we can merge this first |
Yeah, I agree the tear-down protocol is the fiddly thing. Let's verbalize some options:
|
I took a look at another place the I also hit the fact that the test was using #25432 yet another class for managing custom fields - which feels like it should be combined with the more heavily used We have 10 traits in various stages of maturity in the |
Overview
Convert api4 helper functionality to a trait & make available
First - ask jenkins....
Before
What is the old user-interface or technical-contract (as appropriate)?
For optimal clarity, include a concrete example such as a screenshot, GIF (LICEcap, SilentCast), or code-snippet.
After
What changed? What is new old user-interface or technical-contract?
For optimal clarity, include a concrete example such as a screenshot, GIF (LICEcap, SilentCast), or code-snippet.
Technical Details
If the PR involves technical details/changes/considerations which would not be manifest to a casual developer skimming the above sections, please describe the details here.
Comments
Anything else you would like the reviewer to note