Problem/Motivation

We are currently trying to remove dependencies between the PHPUnit-based testing system and the Simpletest module: #2863044: [plan] Remove simpletest dependencies from PHPUnit-based tests

This was accomplished for BrowserTestBase in #2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits

Let's do it for KernelTestBase now.

KernelTestBase uses these two classes from the simpletest namespace:

  • Drupal\simpletest\AssertContentTrait
  • Drupal\simpletest\TestServiceProvider

Drupal\simpletest\TestServiceProvider itself has a dependency on Drupal\simpletest\RouteProvider, which should also be moved.

Proposed resolution

Similar to #2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits

  • Break these dependencies by moving the traits and classes somewhere under core/tests.
  • Ensure that we don't have a class loading problem within simpletest.
  • Ensure BC for existing simpletest-based tests.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mile23 created an issue. See original summary.

dawehner’s picture

Nice catch! Thank you for opening up this issue @Mile23! We are getting somewhere, one day :)

Mile23’s picture

Status: Active » Needs review
Issue tags: +Needs change record
FileSize
67.22 KB

Since #2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits is good for 8.4.x I filed this one for 8.4.x as well. Obviously maintainers may disagree.

This is a first pass to see what I missed.

We can update the change record from #2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits to reflect the changes here, if 8.4.x is our target. Otherwise we'll need to add one for 8.5.x.

Mile23’s picture

Mile23’s picture

Version: 8.4.x-dev » 8.5.x-dev
Component: other » simpletest.module
Issue tags: +Needs reroll

After 8.4.0 release, this should be in 8.5.x.

jofitz’s picture

Issue tags: -Needs reroll
FileSize
67.25 KB

Re-rolled.

Mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

No longer applies.

Mile23’s picture

Status: Needs review » Needs work

The last submitted patch, 8: 2907169_8.patch, failed testing. View results

Anonymous’s picture

Status: Needs work » Needs review

Revert status after random fail. Great work!

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

+1 to RTBC.

Samvel’s picture

Run retest for 8.6.x

Mile23’s picture

Once an issue is marked RTBC the last patch will be tested once daily.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 2907169_8.patch, failed testing. View results

Samvel’s picture

@mile23 ok, i only want process it after deploy new drupal core version.
And i think it's not good process to set RTBC after deploy 8.6.x without test

Anonymous’s picture

Status: Needs work » Reviewed & tested by the community
Mile23’s picture

Issue tags: -Needs change record
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/simpletest/src/AssertContentTrait.php
@@ -2,1495 +2,16 @@
+ *
+ * @deprecated in Drupal 8.5.0, to be removed before Drupal 9.0.0. Use
+ *   Drupal\KernelTests\AssertContentTrait instead.

+++ b/core/modules/simpletest/src/TestServiceProvider.php
@@ -2,54 +2,14 @@
+ * @deprecated in 8.5.0 for removal before Drupal 9.0.0. Use
+ *   Drupal\KernelTests\TestServiceProvider instead.

These should have @see's to the change record to follow our policy. We can't add @trigger_error though because we're still using Simpletest tests.

Also in TestServiceProvider (now not part of Simpletest) we still have code referring to Simpletest and its namespace. I.e:

  /**
   * Add the on demand rebuild route provider service.
   *
   * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
   */
  public static function addRouteProvider(ContainerBuilder $container) {
    foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
      // While $container->get() does a recursive resolve, getDefinition() does
      // not, so do it ourselves.
      // @todo Make the code more readable in
      //   https://www.drupal.org/node/2911498.
      for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)) {
      }
      $definition = $container->getDefinition($id);
      $definition->clearTag('needs_destruction');
      $container->setDefinition("simpletest.$original_id", $definition);
      $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
    }
  }

So we need to do something about \Drupal\simpletest\RouteProvider which has it's own @todo to move out of simpletest linking to #2672762: Move core/modules/simpletest/src/RouteProvider.php to the Drupal\Tests namespace/folder

Mile23’s picture

OK, so we have a related of #2672762: Move core/modules/simpletest/src/RouteProvider.php to the Drupal\Tests namespace/folder Should we postpone on that or make it a follow-up?

There's also a @todo for #2911498: Make TestServiceProvider more readable (cleanup) which is lower priority but still worth doing.

This patch adds @see for the change record.

Even though this patch itself isn't very disruptive and is a test change eligible for 8.5.x, we also have #2672762: Move core/modules/simpletest/src/RouteProvider.php to the Drupal\Tests namespace/folder which is more disruptive and should be 8.6.x. So the extent to which they're related means we should target this issue to 8.6.x. Deprecation messages changed.


The foreach in TestServiceProvider::addRouteProvider() comes from #2605684-26: Routing silently fails in kernel tests when there were more services being registered.
Mile23’s picture

OK, maybe #2672762: Move core/modules/simpletest/src/RouteProvider.php to the Drupal\Tests namespace/folder isn't that disruptive. Here's a patch rolling it in.

As you can see from above, the foreach is unneeded and left over from when there were multiple services being changed: #2605684-26: Routing silently fails in kernel tests

Mile23’s picture

Issue summary: View changes
Issue tags: -Needs change record updates

Updated IS and change record to include RouteProvider.

Marking #2672762: Move core/modules/simpletest/src/RouteProvider.php to the Drupal\Tests namespace/folder as a duplicate of this one.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/modules/simpletest/src/RouteProvider.php
    @@ -2,111 +2,15 @@
    diff --git a/core/modules/simpletest/src/TestServiceProvider.php b/core/modules/simpletest/src/TestServiceProvider.php
    
    diff --git a/core/modules/simpletest/src/TestServiceProvider.php b/core/modules/simpletest/src/TestServiceProvider.php
    index 0097803dee..151260c59d 100644
    
    index 0097803dee..151260c59d 100644
    --- a/core/modules/simpletest/src/TestServiceProvider.php
    
    --- a/core/modules/simpletest/src/TestServiceProvider.php
    +++ b/core/modules/simpletest/src/TestServiceProvider.php
    
    +++ b/core/modules/simpletest/src/TestServiceProvider.php
    +++ b/core/modules/simpletest/src/TestServiceProvider.php
    @@ -2,54 +2,16 @@
    
    @@ -2,54 +2,16 @@
     
     namespace Drupal\simpletest;
     
    ...
    +use Drupal\KernelTests\TestServiceProvider as CoreTestServiceProvider;
    +
    +/**
    + * Provides special routing services for tests.
    + *
    + * @deprecated in 8.6.0 for removal before Drupal 9.0.0. Use
    + *   Drupal\KernelTests\TestServiceProvider instead.
    + *
    + * @see https://www.drupal.org/node/2943146
    + */
    +class TestServiceProvider extends CoreTestServiceProvider {
     
     }
    

    I doubt we treat them as real APIs, but sure, let's not overthink this.

  2. +++ b/core/tests/Drupal/KernelTests/TestServiceProvider.php
    @@ -38,18 +41,17 @@ public function alter(ContainerBuilder $container) {
       public static function addRouteProvider(ContainerBuilder $container) {
    -    foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
    -      // While $container->get() does a recursive resolve, getDefinition() does
    -      // not, so do it ourselves.
    -      // @todo Make the code more readable in
    -      //   https://www.drupal.org/node/2911498.
    -      for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)) {
    -      }
    -      $definition = $container->getDefinition($id);
    -      $definition->clearTag('needs_destruction');
    -      $container->setDefinition("simpletest.$original_id", $definition);
    -      $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
    +    $route_provider_service_name = 'router.route_provider';
    +    // While $container->get() does a recursive resolve, getDefinition() does
    +    // not, so do it ourselves.
    +    // @todo Make the code more readable in
    +    //   https://www.drupal.org/node/2911498.
    +    for ($id = $route_provider_service_name; $container->hasAlias($id); $id = (string) $container->getAlias($id)) {
         }
    +    $definition = $container->getDefinition($id);
    +    $definition->clearTag('needs_destruction');
    +    $container->setDefinition("simpletest.$route_provider_service_name", $definition);
    +    $container->setDefinition($id, new Definition(RouteProvider::class));
    

    Thank you for making this code more readable!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0858e93 and pushed to 8.6.x. Thanks!

  • alexpott committed 0858e93 on 8.6.x
    Issue #2907169 by Mile23, Jo Fitzgerald: Break KernelTestBase dependency...

Status: Fixed » Closed (fixed)

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