Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299251

FieldUnitTestBase::createFieldWithInstance() pollutes test class with arbitrary properties

$
0
0

Problem

  1. FieldUnitTestBase::createFieldWithInstance() has a first $suffix argument, which is used to dynamically create non-existing properties on the test class instance.
  2. It's fine to provide easy DX/access to fields/instances/definitions that have been created for a test, but setting + relying on dynamic properties that do not exist is not.

History

  1. This code was invented in #1821906: Allow more Field API public API functions to act on a single field within an entity (and unfortunately backported to D7).
  2. #1932382: Use DrupalUnitTestBase for Field API tests. converted the test class into DUTB/KTB later on, but seemingly ignored that issue.

Proposed solution

  1. Keep the DX idea (which is a fair one IMO), but move the dynamic properties into a single $this->fields bag.

API changes

Just in case we consider test base classes as "API"...

$this->createFieldWithInstance();
$this->createFieldWithInstance('_second');
...
-$this->assertTrue($this->field->id());
-$this->assertTrue($this->field_second->id());
+$this->assertTrue($this->fields->field->id());
+$this->assertTrue($this->fields->field_second->id());

Viewing all articles
Browse latest Browse all 299251

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>