function DocParserIgnoredClassesTest::testIgnoredAnnotationSkippedBeforeReflection

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

Ensure annotations can be ignored when namespaces are present.

Drupal's DocParser should never use class_exists() on an ignored annotation, including cases where namespaces are set.

File

core/tests/Drupal/Tests/Component/Annotation/DocParserIgnoredClassesTest.php, line 21

Class

DocParserIgnoredClassesTest
@coversDefaultClass \Drupal\Component\Annotation\Doctrine\DocParser

Namespace

Drupal\Tests\Component\Annotation

Code

public function testIgnoredAnnotationSkippedBeforeReflection() {
    $annotation = 'neverReflectThis';
    $parser = new DocParser();
    $parser->setIgnoredAnnotationNames([
        $annotation => TRUE,
    ]);
    $parser->addNamespace('\\Arbitrary\\Namespace');
    // Register our class loader which will fail if the parser tries to
    // autoload disallowed annotations.
    $autoloader = function ($class_name) use ($annotation) {
        $name_array = explode('\\', $class_name);
        $name = array_pop($name_array);
        if ($name == $annotation) {
            $this->fail('Attempted to autoload an ignored annotation: ' . $name);
        }
    };
    spl_autoload_register($autoloader, TRUE, TRUE);
    // Perform the parse.
    $this->assertEmpty($parser->parse('@neverReflectThis'));
    // Clean up after ourselves.
    spl_autoload_unregister($autoloader);
}

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