You are here

protected function DrupalComponentTest::assertNoCoreUsage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 69
Contains \Drupal\Tests\Component\DrupalComponentTest.

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}");
}