/** * @group 5384 */ public function testPropertyScannerReturnsProperValue() { $class = <<<'CLASS' <?php class Foo { protected $empty; private $string = 'string'; private $int = 123; private $array = array('test' => 2,2); private $arraynew = ['test' => 2,2]; private $notarray = "['test' => 2,2]"; private $status = false; } CLASS; $tokenScanner = new TokenArrayScanner(token_get_all($class)); $fooClass = $tokenScanner->getClass('Foo'); foreach ($fooClass->getProperties() as $property) { $value = $property->getValue(); $valueType = $property->getValueType(); switch ($property->getName()) { case "empty": $this->assertNull($value); $this->assertEquals('unknown', $valueType); break; case "string": $this->assertEquals('string', $value); $this->assertEquals('string', $valueType); break; case "int": $this->assertEquals('123', $value); $this->assertEquals('int', $valueType); break; case "array": $this->assertEquals("array('test'=>2,2)", $value); $this->assertEquals('array', $valueType); break; case "arraynew": $this->assertEquals("['test'=>2,2]", $value); $this->assertEquals('array', $valueType); break; case "notarray": $this->assertEquals('string', $valueType); break; case "status": $this->assertTrue("false" === $value); $this->assertEquals('boolean', $valueType); break; } } }
/** * @param string $file * @param null|AnnotationManager $annotationManager * @throws Exception\InvalidArgumentException */ public function __construct($file, AnnotationManager $annotationManager = null) { $this->file = $file; if (!file_exists($file)) { throw new Exception\InvalidArgumentException(sprintf('File "%s" not found', $file)); } parent::__construct(token_get_all(file_get_contents($file)), $annotationManager); }
protected function scan() { if (!$this->file) { throw new Exception\RuntimeException('File was not provided'); } $this->setTokens(token_get_all(file_get_contents($this->file))); parent::scan(); }
protected function scan() { if ($this->isScanned) { return; } $this->setTokens(token_get_all(file_get_contents($this->file))); parent::scan(); }
public function testScannerCanHandleMultipleNamespaceFile() { $tokenScanner = new TokenArrayScanner(token_get_all(file_get_contents(__DIR__ . '/../TestAsset/MultipleNamespaces.php'))); $this->assertEquals('ZendTest\\Code\\TestAsset\\Baz', $tokenScanner->getClass('ZendTest\\Code\\TestAsset\\Baz')->getName()); $this->assertEquals('Foo', $tokenScanner->getClass('Foo')->getName()); }
public function testScannerCanHandleMultipleNamespaceFile() { $tokenScanner = new TokenArrayScanner(token_get_all(file_get_contents((__DIR__ . '/../TestAsset/MultipleNamespaces.php')))); var_dump($tokenScanner->getClass('ZendTest\Code\TestAsset\Baz')); }