/**
  * 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
  * @covers stdClass
  * @group pdepend
  * @group pdepend::bugs
  * @group regressiontest
  * @dataProvider dataProviderTokenizerKeywordSubstitutionInOperatorChain
  */
 public function testTokenizerKeywordSubstitutionInOperatorChain($sourceFile, array $tokenTypes)
 {
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($this->createCodeResourceURI($sourceFile));
     foreach ($tokenTypes as $tokenType) {
         $this->assertSame($tokenType, $tokenizer->next()->type);
     }
 }
 /**
  * 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 PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($this->createCodeResourceURI($sourceFile));
     $actual = array();
     while (is_object($token = $tokenizer->next())) {
         $actual[] = $token->type;
     }
     self::assertEquals($tokenTypes, $actual);
 }
Example #3
0
 /**
  * testParserHandlesMaxNestingLevel
  * 
  * @return void
  * @covers PHP_Depend_Parser
  * @group pdepend
  * @group pdepend::parser
  * @group unittest
  */
 public function testParserHandlesMaxNestingLevel()
 {
     if (version_compare(phpversion(), '5.2.10') < 0) {
         $this->markTestSkipped();
     }
     ini_set('xdebug.max_nesting_level', '100');
     $builder = new PHP_Depend_Builder_Default();
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile(self::createCodeResourceURI('parser/' . __FUNCTION__ . '.php'));
     $parser = new PHP_Depend_Parser($tokenizer, $builder);
     $parser->setMaxNestingLevel(512);
     $parser->parse();
 }
Example #4
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 PHP_Depend_Tokenizer_Internal();
     $this->fireStartParseProcess($this->builder);
     foreach ($this->createFileIterator() as $file) {
         $tokenizer->setSourceFile($file);
         $parser = new PHP_Depend_Parser_VersionAllParser($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 (PHP_Depend_Parser_Exception $e) {
             $this->parseExceptions[] = $e;
         }
         $this->fireEndFileParsing($tokenizer);
     }
     $this->fireEndParseProcess($this->builder);
 }
Example #5
0
 /**
  * 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 PHP_Depend_Builder_Default
  */
 protected function parseSourceAndReturnBuilder($file)
 {
     copy(self::createCodeResourceUriForTest() . '/' . $file, $this->testFile);
     $cache = new PHP_Depend_Util_Cache_Driver_File($this->cacheDir);
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($this->testFile);
     $builder = new PHP_Depend_Builder_Default();
     $builder->setCache($cache);
     $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $builder, $cache);
     $parser->parse();
     return $builder;
 }
Example #6
0
 /**
  * Tests the result printer with multiple entries.
  *
  * @return void
  */
 public function testResultPrinterOutputForMultipleEntries()
 {
     // Create dummy objects
     $builder = new PHP_Depend_Builder_Default();
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile(__FILE__);
     $printer = new PHP_Depend_TextUI_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);
 }
Example #7
0
 /**
  * Parses the given source file or directory with the default tokenizer
  * and node builder implementations.
  *
  * @param string  $fileOrDirectory   A source file or a source directory.
  * @param boolean $ignoreAnnotations The parser should ignore annotations.
  *
  * @return PHP_Depend_Code_NodeIterator
  */
 public static function parseSource($fileOrDirectory, $ignoreAnnotations = false)
 {
     include_once 'PHP/Depend/Parser.php';
     include_once 'PHP/Depend/Builder/Default.php';
     include_once 'PHP/Depend/Code/Filter/Collection.php';
     include_once 'PHP/Depend/Tokenizer/Internal.php';
     include_once 'PHP/Depend/Input/ExcludePathFilter.php';
     include_once 'PHP/Depend/Input/Iterator.php';
     if (file_exists($fileOrDirectory) === false) {
         $fileOrDirectory = self::createCodeResourceURI($fileOrDirectory);
     }
     if (is_dir($fileOrDirectory)) {
         $it = new PHP_Depend_Input_Iterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fileOrDirectory)), new PHP_Depend_Input_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);
     $builder = new PHP_Depend_Builder_Default();
     foreach ($files as $file) {
         $tokenizer = new PHP_Depend_Tokenizer_Internal();
         $tokenizer->setSourceFile($file);
         $parser = new PHP_Depend_Parser($tokenizer, $builder);
         if ($ignoreAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $parser->parse();
     }
     return $builder->getPackages();
 }
Example #8
0
 /**
  * testReturnsExpectedTokensForBacktickExpressionWithEmbeddedString
  *
  * @return void
  * @covers PHP_Depend_Tokenizer_Internal
  * @group pdepend
  * @group pdepend::tokenizer
  * @group unittest
  */
 public function testReturnsExpectedTokensForBacktickExpressionWithEmbeddedString()
 {
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile(self::createCodeResourceURI('tokenizer/' . __FUNCTION__ . '.php'));
     $actual = array();
     while (is_object($token = $tokenizer->next())) {
         $actual[] = array($token->type);
     }
     $expected = array(array(PHP_Depend_ConstantsI::T_OPEN_TAG), array(PHP_Depend_ConstantsI::T_BACKTICK), array(PHP_Depend_ConstantsI::T_ENCAPSED_AND_WHITESPACE), array(PHP_Depend_ConstantsI::T_VARIABLE), array(PHP_Depend_ConstantsI::T_DOUBLE_QUOTE), array(PHP_Depend_ConstantsI::T_BACKTICK), array(PHP_Depend_ConstantsI::T_SEMICOLON));
     $this->assertEquals($expected, $actual);
 }
Example #9
0
 /**
  * Parses the source of the given file and returns the first package found
  * in that file.
  *
  * @param string $sourceFile Name of the test source file.
  *
  * @return PHP_Depend_Code_Package
  */
 private function parseSource($sourceFile)
 {
     if (file_exists($sourceFile) === false) {
         throw new ErrorException('Cannot locate source file: ' . $sourceFile);
     }
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($sourceFile);
     $builder = new PHP_Depend_Builder_Default();
     $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $builder, new PHP_Depend_Util_Cache_Driver_Memory());
     $parser->parse();
     return $builder->getPackages()->current();
 }
Example #10
0
 /**
  * testParserStopsProcessingWhenCacheContainsValidResult
  *
  * @return void
  * @covers PHP_Depend_Parser
  * @group pdepend
  * @group pdepend::parser
  * @group unittest
  */
 public function testParserStopsProcessingWhenCacheContainsValidResult()
 {
     $builder = $this->getMock('PHP_Depend_BuilderI');
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile(__FILE__);
     $cache = $this->getMock('PHP_Depend_Util_Cache_Driver');
     $cache->expects($this->once())->method('restore')->will(self::returnValue(true));
     $cache->expects($this->never())->method('store');
     $parser = new PHP_Depend_Parser_VersionAllParser($tokenizer, $builder, $cache);
     $parser->parse();
 }
Example #11
0
 /**
  * Parses the source of the given file and returns the first package found
  * in that file.
  *
  * @param string $sourceFile Name of the test source file.
  *
  * @return PHP_Depend_Code_Package
  */
 private function _parseSource($sourceFile)
 {
     if (file_exists($sourceFile) === false) {
         throw new ErrorException('Cannot locate source file: ' . $sourceFile);
     }
     include_once 'PHP/Depend/Parser.php';
     include_once 'PHP/Depend/Builder/Default.php';
     include_once 'PHP/Depend/Tokenizer/Internal.php';
     $tokenizer = new PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile($sourceFile);
     $builder = new PHP_Depend_Builder_Default();
     $parser = new PHP_Depend_Parser($tokenizer, $builder);
     $parser->parse();
     return $builder->getPackages()->current();
 }
Example #12
0
 /**
  * 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 PHP_Depend_Tokenizer_Internal();
     $tokenizer->setSourceFile(self::createCodeResourceUriForTest());
     $types = array();
     while (is_object($token = $tokenizer->next())) {
         $types[] = $token->type;
     }
     return $types;
 }