Problem/Motivation
In preparance of #3206365: Add an EntityFinder service, the unit tests for the FeedsTarget plugins "entity_reference", "file", "config_entity_reference" and "user_role" could use a little refactoring. In all tests, the target plugin to test with is created in the method setUp(). While working on that other issue I found out that I needed to mock some methods on objects that are passed to the target plugin. Mocking these methods on these objects need to happen before they are passed to the target plugin and they need to be different per test method. So it is inconvenient if the target plugin already exists at the start of the test method.
Example:
$this->entityFinder->findEntities('referenceable_entity_type', 'referenceable_entity_type label', 1, [], FALSE)
->willReturn([12, 13, 14])
->shouldBeCalled();
should happen before
new EntityReference($configuration, 'entity_reference', [], $this->entityTypeManager->reveal(), $this->entityFieldManager->reveal(), $this->entityFinder->reveal());
Proposed resolution
In the affected unit tests, add a method called createTargetPluginInstance(). Move the code from setUp() that creates the target plugin to there. Update test methods that use $this->targetPlugin to use $this->createTargetPluginInstance() instead.
Remaining tasks
- Add a method called
createTargetPluginInstance()to entity reference unit tests. - Move target plugin creation code from
setUp()tocreateTargetPluginInstance(). - Update test methods to use
$this->createTargetPluginInstance()instead of$this->targetPlugin.
User interface changes
None.
API changes
None. Changes only happen in tests.
Data model changes
None.
Issue fork feeds-3206367
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
megachrizCode is pushed to the issue fork and ready for the testbot to check.
Comment #5
megachrizMerged!