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

  1. Add a method called createTargetPluginInstance() to entity reference unit tests.
  2. Move target plugin creation code from setUp() to createTargetPluginInstance().
  3. 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

Command icon 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

MegaChriz created an issue. See original summary.

megachriz’s picture

Status: Active » Needs review

Code is pushed to the issue fork and ready for the testbot to check.

  • MegaChriz committed e8f3b36 on 8.x-3.x
    Issue #3206367 by MegaChriz: Refactored entity reference unit tests:...
megachriz’s picture

Status: Needs review » Fixed

Merged!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.