function DrupalComponentTest::assertNoCoreUsage

Same name in other branches
  1. 9 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.

Parameters

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

3 calls to DrupalComponentTest::assertNoCoreUsage()
DrupalComponentTest::testAssertNoCoreUseage in core/tests/Drupal/Tests/Component/DrupalComponentTest.php
@covers \Drupal\Tests\Component\DrupalComponentTest::assertNoCoreUsage @dataProvider providerAssertNoCoreUseage
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 93

Class

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

Namespace

Drupal\Tests\Component

Code

protected function assertNoCoreUsage($class_path) {
    $contents = file_get_contents($class_path);
    preg_match_all('/^.*Drupal\\\\Core.*$/m', $contents, $matches);
    $matches = array_filter($matches[0], function ($line) {
        // Filter references to @see as they don't really matter.
        return strpos($line, '@see') === FALSE;
    });
    $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.