DocParser example

class DCOM58Test extends TestCase
{
    protected function setUp(): void
    {
        // Some class named Entity in the global namespace.         include __DIR__ .'/DCOM58Entity.php';
    }

    public function testIssueGlobalNamespace()
    {
        $docblock   = "@Entity";
        $parser     = new DocParser();
        $parser->setImports(array(
            "__NAMESPACE__" =>"Drupal\Tests\Component\Annotation\Doctrine\Ticket\Doctrine\ORM\Mapping"
        ));

        $annots     = $parser->parse($docblock);

        $this->assertCount(1, $annots);
        $this->assertInstanceOf("Drupal\Tests\Component\Annotation\Doctrine\Ticket\Doctrine\ORM\Mapping\Entity", $annots[0]);
    }

    public function testIssueNamespaces()
    {
 {
            throw AnnotationException::optimizerPlusSaveComments();
        }

        if (extension_loaded('Zend OPcache') && ini_get('opcache.save_comments') === 0) {
            throw AnnotationException::optimizerPlusSaveComments();
        }

        // Make sure that the IgnoreAnnotation annotation is loaded         class_exists(IgnoreAnnotation::class);

        $this->parser = $parser ?: new DocParser();

        $this->preParser = new DocParser();

        $this->preParser->setImports(self::$globalImports);
        $this->preParser->setIgnoreNotImportedAnnotations(true);
        $this->preParser->setIgnoredAnnotationNames(self::$globalIgnoredNames);

        $this->phpParser = new PhpParser();
    }

    /** * {@inheritDoc} */

class DocParserIgnoredClassesTest extends TestCase {

  /** * 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. */
  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 D$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);
      }
    };

class SimpleAnnotationReader implements Reader
{
    /** @var DocParser */
    private $parser;

    /** * Initializes a new SimpleAnnotationReader. */
    public function __construct()
    {
        $this->parser = new DocParser();
        $this->parser->setIgnoreNotImportedAnnotations(true);
    }

    /** * Adds a namespace in which we will look for annotations. * * @param string $namespace * * @return void */
    public function addNamespace($namespace)
    {
$result = $parser->parse($docblock);

        $this->assertInstanceOf("Drupal\Tests\Component\Annotation\Doctrine\Name", $result[0]);
    }

    /** * @group DDC-77 */
    public function testAnnotationWithoutClassIsIgnoredWithoutWarning()
    {
        $parser = new DocParser();
        $parser->setIgnoreNotImportedAnnotations(true);
        $result = $parser->parse("@param");

        $this->assertCount(0, $result);
    }

    /** * @group DCOM-168 */
    public function testNotAnAnnotationClassIsIgnoredWithoutWarning()
    {
        

    private $parser;

    /** * Constructor. * * Initializes a new SimpleAnnotationReader. */
    public function __construct()
    {
        $this->parser = new DocParser();
        $this->parser->setIgnoreNotImportedAnnotations(true);
        $this->parser->setIgnoredAnnotationNames($this->ignoredAnnotations);
    }

    /** * Adds a namespace in which we will look for annotations. * * @param string $namespace * * @return void */
    
Home | Imprint | This part of the site doesn't use cookies.