Inheritance: implements PDepend\Source\Tokenizer\Tokenizer
 /**
  * This method tests that the parser does not substitute keyword tokens in
  * a class or object operator chain.
  *
  * @param string         $sourceFile Name of the text file.
  * @param array(integer) $tokenTypes List of all expected token types.
  *
  * @return void
  * @dataProvider dataProviderTokenizerKeywordSubstitutionInOperatorChain
  */
 public function testTokenizerKeywordSubstitutionInOperatorChain($sourceFile, array $tokenTypes)
 {
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile($this->createCodeResourceURI($sourceFile));
     $actual = array();
     while (is_object($token = $tokenizer->next())) {
         $actual[] = $token->type;
     }
     $this->assertEquals($tokenTypes, $actual);
 }
 /**
  * Tests that the parser detects the classname scalar.
  *
  * <code>
  * $className = stdClass::class;
  * </code>
  *
  * @return void
  */
 public function testClassNameScalarKeyword()
 {
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile($this->createCodeResourceURI('bugs/124/testClassNameScalarKeyword.php'));
     $actual = array();
     while (is_object($token = $tokenizer->next())) {
         $actual[] = $token->type;
     }
     $tokenTypes = array(Tokens::T_OPEN_TAG, Tokens::T_VARIABLE, Tokens::T_EQUAL, Tokens::T_STRING, Tokens::T_DOUBLE_COLON, Tokens::T_CLASS_FQN, Tokens::T_SEMICOLON);
     $this->assertEquals($tokenTypes, $actual);
 }
Ejemplo n.º 3
0
 /**
  * This method performs the parsing process of all source files. It expects
  * that the <b>$_builder</b> property was initialized with a concrete builder
  * implementation.
  *
  * @return void
  */
 private function performParseProcess()
 {
     // Reset list of thrown exceptions
     $this->parseExceptions = array();
     $tokenizer = new PHPTokenizerInternal();
     $this->fireStartParseProcess($this->builder);
     foreach ($this->createFileIterator() as $file) {
         $tokenizer->setSourceFile($file);
         $parser = new PHPParserGeneric($tokenizer, $this->builder, $this->cacheFactory->create());
         $parser->setMaxNestingLevel($this->configuration->parser->nesting);
         // Disable annotation parsing?
         if ($this->withoutAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $this->fireStartFileParsing($tokenizer);
         try {
             $parser->parse();
         } catch (\PDepend\Source\Parser\ParserException $e) {
             $this->parseExceptions[] = $e;
         }
         $this->fireEndFileParsing($tokenizer);
     }
     $this->fireEndParseProcess($this->builder);
 }
 /**
  * Tests the result printer with multiple entries.
  *
  * @return void
  */
 public function testResultPrinterOutputForMultipleEntries()
 {
     // Create dummy objects
     $builder = new PHPBuilder();
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile(__FILE__);
     $printer = new ResultPrinter();
     ob_start();
     for ($i = 0; $i < 73; ++$i) {
         $printer->startFileParsing($tokenizer);
     }
     $printer->endParseProcess($builder);
     $actual = ob_get_contents();
     ob_end_clean();
     $expected = "............................................................    60\n" . ".............                                                   73\n\n";
     $this->assertEquals($expected, $actual);
 }
 /**
  * Returns an array with the token types found in a file associated with
  * the currently running test.
  *
  * @return array(integer)
  */
 private function _getTokenTypesForTest()
 {
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile(self::createCodeResourceUriForTest());
     $types = array();
     while (is_object($token = $tokenizer->next())) {
         $types[] = $token->type;
     }
     return $types;
 }
 /**
  * testParserStopsProcessingWhenCacheContainsValidResult
  *
  * @return void
  */
 public function testParserStopsProcessingWhenCacheContainsValidResult()
 {
     $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder');
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile(__FILE__);
     $cache = $this->createCacheFixture();
     $cache->expects($this->once())->method('restore')->will(self::returnValue(true));
     $cache->expects($this->never())->method('store');
     $parser = new PHPParserGeneric($tokenizer, $builder, $cache);
     $parser->parse();
 }
 /**
  * Parses the given test file and then returns the builder instance.
  *
  * @param string $file Relative path to a test file for the calling test.
  * @return \PDepend\Source\Builder\Builder
  */
 protected function parseSourceAndReturnBuilder($file)
 {
     copy(self::createCodeResourceUriForTest() . '/' . $file, $this->testFile);
     $cache = new FileCacheDriver($this->cacheDir);
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile($this->testFile);
     $builder = new PHPBuilder();
     $builder->setCache($cache);
     $parser = new PHPParserGeneric($tokenizer, $builder, $cache);
     $parser->parse();
     return $builder;
 }
 /**
  * Parses the given source file or directory with the default tokenizer
  * and node builder implementations.
  *
  * @param string  $fileOrDirectory
  * @param boolean $ignoreAnnotations
  * @return \PDepend\Source\AST\ASTNamespace[]
  */
 public static function parseSource($fileOrDirectory, $ignoreAnnotations = false)
 {
     if (file_exists($fileOrDirectory) === false) {
         $fileOrDirectory = self::createCodeResourceURI($fileOrDirectory);
     }
     if (is_dir($fileOrDirectory)) {
         $it = new Iterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fileOrDirectory)), new ExcludePathFilter(array('.svn')));
     } else {
         $it = new \ArrayIterator(array($fileOrDirectory));
     }
     $files = array();
     foreach ($it as $file) {
         if (is_object($file)) {
             $files[] = realpath($file->getPathname());
         } else {
             $files[] = $file;
         }
     }
     sort($files);
     $cache = new MemoryCacheDriver();
     $builder = new PHPBuilder();
     foreach ($files as $file) {
         $tokenizer = new PHPTokenizerInternal();
         $tokenizer->setSourceFile($file);
         $parser = new PHPParserGeneric($tokenizer, $builder, $cache);
         if ($ignoreAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $parser->parse();
     }
     return $builder->getNamespaces();
 }