Problem/Motivation

I'm working on tests for test coverage for #3306211: Deprecated function: trim(): Passing null is deprecated as of PHP 8. For that issue it would be handy if in unit tests target plugins can be instantiated all in the same way, namely by having a method called instantiatePlugin().

Almost all unit tests now have code looking similar to this:

$method = $this->getMethod(Link::class, 'prepareTarget')->getClosure();

$configuration = [
  'feed_type' => $this->createMock(FeedTypeInterface::class),
  'target_definition' => $method($this->getMockFieldDefinition()),
];
$target = new Link($configuration, 'link', []);

Some target unit tests already have methods for instantiating the plugin, but these have different names. There is:

  • createTargetPluginInstance()
  • instantiatePlugin()

Proposed resolution

To FieldTargetTestBase, add a method called instantiatePlugin(). Override it in child classes where needed. Additionally, add a method called testInstantiatePlugin() to make sure instantiatePlugin() works for every target unit test.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork feeds-3322691

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 committed f42cd0d on 8.x-3.x
    Issue #3322691 by MegaChriz: Refactor unit tests for targets
    
megachriz’s picture

Status: Active » Fixed

Merged the code!

Status: Fixed » Closed (fixed)

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