/** * @param string $php * Entire contents of a PHP file. * @param \Donquixote\HastyReflectionCommon\Canvas\ClassIndex\ClassIndexInterface $autoloadSource * * @return \Donquixote\HastyReflectionCommon\Reflection\File\FileReflection|null */ function phpGetReflection($php, ClassIndexInterface $autoloadSource) { $fileAst = $this->phpToAst->phpGetAst($php); if (NULL === $fileAst) { return NULL; } return $this->astToFileReflection->astGetFileReflection($fileAst, $autoloadSource); }
/** * @param \Donquixote\HastyPhpAst\PhpToAst\PhpToAstInterface $phpToAst * @param string $class * * @dataProvider providerPhpToAst */ function testPhpToAst(PhpToAstInterface $phpToAst, $class) { $reflectionClass = new \ReflectionClass($class); $file = $reflectionClass->getFileName(); $php = file_get_contents($file); $fileAst = $phpToAst->phpGetAst($php); $classNodes = $this->fileAstGetClassNodes($fileAst); $this->assertEquals(array(0), array_keys($classNodes)); $classNode = $classNodes[0]; $this->assertEquals($reflectionClass->getShortName(), $classNode->getShortName()); $this->assertEquals($reflectionClass->getDocComment(), $classNode->getDocComment()); $expectedOwnMethodNames = array(); foreach ($reflectionClass->getMethods() as $method) { if ($method->getDeclaringClass()->getName() === $reflectionClass->getName()) { $expectedOwnMethodNames[] = $method->getName(); } } $actualOwnMethodNames = array(); foreach ($classNode->getBody()->getMemberNodes() as $memberNode) { if ($memberNode instanceof AstFunctionLikeInterface) { $actualOwnMethodNames[] = $memberNode->getShortName(); } } $this->assertEquals($expectedOwnMethodNames, $actualOwnMethodNames); }
/** * @param \Donquixote\HastyPhpAst\PhpToAst\PhpToAstInterface $phpToAst * @param string $class * * @dataProvider providerPhpToAst */ function testPhpToAst(PhpToAstInterface $phpToAst, $class) { $reflectionClass = new \ReflectionClass($class); $file = $reflectionClass->getFileName(); $php = file_get_contents($file); $fileAst = $phpToAst->phpGetAst($php); static::assertNotNull($fileAst); static::assertInstanceOf(AstFileInterface::class, $fileAst); $classNodes = $this->fileAstGetClassNodes($fileAst); $this->assertEquals(array(0), array_keys($classNodes)); $classNode = $classNodes[0]; $this->assertEquals($reflectionClass->getShortName(), $classNode->getShortName()); $this->assertEquals($reflectionClass->getDocComment(), $classNode->getDocComment()); }