/** * Tests that the parser ignores backtick expressions. * * http://bugs.xplib.de/index.php?do=details&task_id=15&project=3 * * @return void */ public function testParserBacktickExpressionBug15() { $sourceFile = dirname(__FILE__) . '/_code/bugs/15.php'; $tokenizer = new PHP_Depend_Tokenizer_Internal($sourceFile); $builder = new PHP_Depend_Builder_Default(); $parser = new PHP_Depend_Parser($tokenizer, $builder); $parser->parse(); $package = $builder->getPackages()->current(); $classes = $package->getClasses(); $this->assertEquals(1, $classes->count()); $methods = $classes->current()->getMethods(); $this->assertEquals(1, $methods->count()); }
/** * 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; }
/** * 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(); }
/** * Creates a clean builder test instance. * * @return PHP_Depend_Builder_Default */ protected function createBuilder() { $builder = new PHP_Depend_Builder_Default(); $builder->setCache($this->getMock('PHP_Depend_Util_Cache_Driver')); return $builder; }
/** * 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(); }
/** * Tests that the builder throws the expected exception when some one tries * to build a new node, when the internal state flag is frozen. * * @return void * @covers PHP_Depend_Builder_Default * @group pdepend * @group pdepend::builder * @group unittest */ public function testBuildFunctionThrowsExpectedExceptionWhenStateIsFrozen() { $builder = new PHP_Depend_Builder_Default(); $builder->buildFunction('func'); // Freeze object $builder->getInterface('Inter'); $this->setExpectedException('BadMethodCallException', 'Cannot create new nodes, when internal state is frozen.'); $builder->buildFunction('prop'); }
/** * 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(); }