Problem
FieldUnitTestBase::createFieldWithInstance()
has a first$suffix
argument, which is used to dynamically create non-existing properties on the test class instance.- 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
- 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).
- #1932382: Use DrupalUnitTestBase for Field API tests. converted the test class into DUTB/KTB later on, but seemingly ignored that issue.
Proposed solution
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());