Problem/Motivation

The codebase contains references to the outdated namespace Drupal\*\Tests. These should be updated to Drupal\Tests\*

Steps to reproduce

See for example core/modules/node/tests/modules/node_access_test/node_access_test.module:

- * @see \Drupal\node\Tests\NodeQueryAlterTest
- * @see \Drupal\node\Tests\NodeAccessBaseTableTest

Proposed resolution

Update outdated class references from Drupal\*\Tests to Drupal\Tests\*

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

idebr created an issue. See original summary.

Lendude’s picture

Proposed automation:
In PHPStorm do a replace in file
Find with regex: \\Drupal\\(\w+)\\Tests\\
Replace with : \\Drupal\\Tests\\$1\\

Lendude’s picture

Status: Active » Needs review
Issue tags: +phpunit initiative
FileSize
60.15 KB

Lets see if this breaks anything

Tagging for the PHPUnit initiative since we should have changed it then ;)

Lendude’s picture

Lets try that again with the trailing slashes added

idebr’s picture

Status: Needs review » Needs work

The automated replacement is missing the added namespace for `Functional` / `Unit` etc, so it's unlikely this can be automated.

Lendude’s picture

Yeah good point, it does provide a handy list of what needs to be checked I guess.

Lendude’s picture

Status: Needs work » Needs review
FileSize
57.36 KB

Manually went through them and added what needed to be added. Reverted a couple that still use the old namespaces (in Views mostly), removed some things that no longer seem to exist

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Ran this locally and found these instances. Could you confirm if they are no relevant to this

Targets
    Occurrences of '\\Drupal\\.*\\Tests\\' in Directory /Users/smustgrave/Sites/Drupal-Demos/drupal-10.x/web/core
Found Occurrences in Directory /Users/smustgrave/Sites/Drupal-Demos/drupal-10.x/web/core  (23 usages found)
    Unclassified  (3 usages found)
        drupal-10.x  (3 usages found)
            web/core  (3 usages found)
                phpstan-baseline.neon  (3 usages found)
                    3159 e 'ClassWithConstants\\.SOME_KEY' \\(\\\\Drupal\\\\Tests\\\\Component\\\\Annotation\\\\Doctrine\\\\Fixtures\\\\ClassWithConstants\\:\\:SOME_KEY, \\\\Drupal\\\\Tests\\\\Component\\\\Annotation\\\\Doctrine\\\\Fixtures\\\\ClassWithConstants\\:\\:SOME_KEY\\)\\.$#"
                    3264 			message: "#^\\#lazy_builder callback '\\\\\\\\Drupal\\\\\\\\Tests\\\\\\\\Core…' at key '0' is not trusted\\.$#"
                    3274 			message: "#^\\#pre_render callback '\\\\\\\\Drupal\\\\\\\\Tests\\\\\\\\Core…' at key '0' is not trusted\\.$#"
    Usage in comments  (9 usages found)
        drupal-10.x  (9 usages found)
            web/core/modules/views/tests/modules/views_entity_test  (1 usage found)
                views_entity_test.module  (1 usage found)
                    58 // \Drupal\views\Tests\ViewResultAssertionTrait::assertIdenticalResultsetHelper()
            web/core/modules/views/tests/src/Functional/Handler  (2 usages found)
                AreaTitleWebTest.php  (2 usages found)
                    57 // \Drupal\views\Tests\ViewTestData::dataSet().
                    76 // \Drupal\views\Tests\ViewTestData::dataSet().
            web/core/modules/views/tests/src/Unit  (1 usage found)
                PluginBaseTest.php  (1 usage found)
                    17 * @var \Drupal\views\Tests\TestHelperPlugin
            web/core/modules/views/tests/src/Unit/EventSubscriber  (1 usage found)
                RouteSubscriberTest.php  (1 usage found)
                    40 * @var \Drupal\views\EventSubscriber\RouteSubscriber|\Drupal\Tests\views\Unit\EventSubscriber\TestRouteSubscriber
            web/core/tests/Drupal/KernelTests/Core/Plugin/Condition  (1 usage found)
                RequestPathTest.php  (1 usage found)
                    29 * @var \Drupal\system\Tests\Routing\MockAliasManager
            web/core/tests/Drupal/Tests/Core/Asset  (1 usage found)
                LibraryDiscoveryParserTest.php  (1 usage found)
                    30 * @var \Drupal\Core\Asset\LibraryDiscoveryParser|\Drupal\Tests\Core\Asset\TestLibraryDiscoveryParser
            web/core/tests/Drupal/Tests/Core/EventSubscriber  (1 usage found)
                CustomPageExceptionHtmlSubscriberTest.php  (1 usage found)
                    57 * @var \Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber|\Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest
            web/core/tests/Drupal/Tests/Core/Extension  (1 usage found)
                ThemeHandlerTest.php  (1 usage found)
                    39 * @var \Drupal\Core\Extension\ThemeHandler|\Drupal\Tests\Core\Extension\StubThemeHandler
    Usage in string constants  (11 usages found)
        drupal-10.x  (11 usages found)
            web/core/modules/rest/tests/src/Kernel/EntityResource  (1 usage found)
                EntityResourceRestTestCoverageTest.php  (1 usage found)
                    96 $class_alternative = str_replace("\\Drupal\\Tests\\$module_name\\Functional", '\Drupal\FunctionalTests', $class);
            web/core/tests/Drupal/Tests/Component/Assertion  (2 usages found)
                InspectorTest.php  (2 usages found)
                    235 $this->assertTrue(Inspector::assertAllObjects([new \ArrayObject(), new StringObject()], '\\Traversable', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
                    236 $this->assertFalse(Inspector::assertAllObjects([new \ArrayObject(), new StringObject(), new \stdClass()], '\\ArrayObject', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
            web/core/tests/Drupal/Tests/Component/ProxyBuilder  (1 usage found)
                ProxyBuilderTest.php  (1 usage found)
                    302 public function typehintSelf(?\Drupal\Tests\Component\ProxyBuilder\TestServiceNullableTypehintSelf $parameter): ?\Drupal\Tests\Component\ProxyBuilder\TestServiceNullableTypehintSelf
            web/core/tests/Drupal/Tests/Core/Render  (5 usages found)
                RendererCallbackTest.php  (5 usages found)
                    46 t be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was \Drupal\Tests\Core\Render\callback. See https://www.drupal.org/node/2966725',
                    50 t be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was \Drupal\Tests\Core\Render\RendererCallbackTest::renderCallback. See https://www.drupal.org/node/2966725',
                    54 t be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\Tests\Core\Render\RendererCallbackTest::renderCallback. See https://www.drupal.org/node/2966725',
                    58 t be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was \Drupal\Tests\Core\Render\callback. See https://www.drupal.org/node/2966725',
                    62 t be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\Tests\Core\Render\RendererCallbackTest. See https://www.drupal.org/node/2966725',
            web/core/tests/Drupal/Tests/Core/Test  (2 usages found)
                TestDiscoveryTest.php  (2 usages found)
                    450 $data['simpletest-webtest'] = ['\Drupal\rest\Tests\NodeTest', FALSE];
                    461 $data['core-buildtest'] = ['\Drupal\BuildTests\Framework\Tests\BuildTestTest', 'Build'];

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.