function DrupalComponentTest::assertNoCoreUsage

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/DrupalComponentTest.php \Drupal\Tests\Component\DrupalComponentTest::assertNoCoreUsage()
  2. 10 core/tests/Drupal/Tests/Component/DrupalComponentTest.php \Drupal\Tests\Component\DrupalComponentTest::assertNoCoreUsage()
  3. 11.x core/tests/Drupal/Tests/Component/DrupalComponentTest.php \Drupal\Tests\Component\DrupalComponentTest::assertNoCoreUsage()

Asserts that the given class is not using any class from Core namespace.

@internal

Parameters

string $class_path: The full path to the class that should be checked.

3 calls to DrupalComponentTest::assertNoCoreUsage()
DrupalComponentTest::testAssertNoCoreUsage in core/tests/Drupal/Tests/Component/DrupalComponentTest.php
@covers \Drupal\Tests\Component\DrupalComponentTest::assertNoCoreUsage @dataProvider providerAssertNoCoreUsage
DrupalComponentTest::testNoCoreInComponent in core/tests/Drupal/Tests/Component/DrupalComponentTest.php
Tests that classes in Component do not use any Core class.
DrupalComponentTest::testNoCoreInComponentTests in core/tests/Drupal/Tests/Component/DrupalComponentTest.php
Tests that classes in Component Tests do not use any Core class.

File

core/tests/Drupal/Tests/Component/DrupalComponentTest.php, line 96

Class

DrupalComponentTest
General tests for \Drupal\Component that can't go anywhere else.

Namespace

Drupal\Tests\Component

Code

protected function assertNoCoreUsage(string $class_path) : void {
    $contents = file_get_contents($class_path);
    preg_match_all('/^.*Drupal\\\\Core.*$/m', $contents, $matches);
    $matches = array_filter($matches[0], function ($line) {
        // Filter references that don't really matter.
        return preg_match('/@see|E_USER_DEPRECATED|expectDeprecation/', $line) === 0;
    });
    $this->assertEmpty($matches, "Checking for illegal reference to 'Drupal\\Core' namespace in {$class_path}");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.