Problem/Motivation

#2684095: Convert field kernel tests to KernelTestBaseTNG converted \Drupal\field\Tests\FieldUnitTestBase to the new phpunit-based kernel base test class and it didn't leave the old class for BC. This poses a problem for contrib projects which cannot use the same test class for core 8.0.x and 8.1.x.

Proposed resolution

Bring back a copy of the old class and keep it until 8.2.0 is released.

Remaining tasks

Agree/review.

User interface changes

Nope.

API changes

Tests are not considered APIs, so.. nope :)

Data model changes

Nope.

Comments

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
StatusFileSize
new7.44 KB

Here it is.

amateescu’s picture

Note that we have to duplicate the code instead of extending the current \Drupal\Tests\field\Kernel\FieldKernelTestBase because test classes that extend the old FieldUnitTestBase class will not run with phpunit.

berdir’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.27 KB

Looks good to me.

We did the same in other cases (EntityUnitTestBase, still has implementations in core though, views base classes, ..), not sure if we did it for migrate or not.

Attaching a diff against 8.0.x, to be sure that we're not introducing a bug here. It's the same except the deprecation notice, entity_create() calls and the router table that was removed from installSchema().

berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/field/src/Tests/FieldUnitTestBase.php
@@ -7,13 +7,18 @@
 
+use CommerceGuys\Intl\Language\LanguageInterface;
 use Drupal\Component\Utility\Unicode;

oh, missed that.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new7.43 KB
new610 bytes

Opps! Silly me :)

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Better :)

mile23’s picture

I'm not sure core needs to move backwards on it. I'll just be the same problem in 6 months.

The main practical problem is that D.O won't let you specify which version of core to use in tests, so you have to wait for it to finish failing, and then restart the test using 8.0.x.

berdir’s picture

When 8.1.0 comes out then 8.0.x is unsupported and does not need to work anymore. So by then, it will be safe for modules to update to use the new base classes and only support 8.1 and 8.2

Yes, the testbot situation is unfortunate but not really relevant. This is about allowing contrib to easily support the two relevant minor versions.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 57436e1 and pushed to 8.1.x. Thanks!

The differences to 8.0.x look totally sane...

diff --git a/core/modules/field/src/Tests/FieldUnitTestBase.php b/core/modules/field/src/Tests/FieldUnitTestBase.php
index ddcf3f9..a223d45 100644
--- a/core/modules/field/src/Tests/FieldUnitTestBase.php
+++ b/core/modules/field/src/Tests/FieldUnitTestBase.php
@@ -10,10 +10,15 @@
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Language\LanguageInterface;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\simpletest\KernelTestBase;
 
 /**
  * Parent class for Field API unit tests.
+ *
+ * @deprecated in Drupal 8.1.x, will be removed before Drupal 8.2.x. Use
+ *   \Drupal\Tests\field\Kernel\FieldKernelTestBase instead.
  */
 abstract class FieldUnitTestBase extends KernelTestBase {
 
@@ -50,7 +55,7 @@ protected function setUp() {
 
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('user');
-    $this->installSchema('system', ['router', 'sequences', 'key_value']);
+    $this->installSchema('system', ['sequences', 'key_value']);
 
     // Set default storage backend and configure the theme system.
     $this->installConfig(array('field', 'system'));
@@ -91,7 +96,7 @@ protected function createFieldWithStorage($suffix = '', $entity_type = 'entity_t
     $field_definition = 'field_definition' . $suffix;
 
     $this->fieldTestData->$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name' . $suffix);
-    $this->fieldTestData->$field_storage = entity_create('field_storage_config', array(
+    $this->fieldTestData->$field_storage = FieldStorageConfig::create(array(
       'field_name' => $this->fieldTestData->$field_name,
       'entity_type' => $entity_type,
       'type' => 'test_field',
@@ -108,7 +113,7 @@ protected function createFieldWithStorage($suffix = '', $entity_type = 'entity_t
         'test_field_setting' => $this->randomMachineName(),
       ),
     );
-    $this->fieldTestData->$field = entity_create('field_config', $this->fieldTestData->$field_definition);
+    $this->fieldTestData->$field = FieldConfig::create($this->fieldTestData->$field_definition);
     $this->fieldTestData->$field->save();
 
     entity_get_form_display($entity_type, $bundle, 'default')

  • alexpott committed 57436e1 on 8.1.x
    Issue #2692223 by amateescu, Berdir: Bring back the simpletest-based...
alexpott’s picture

Status: Fixed » Closed (fixed)

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