public function testInvokableLoadsSource()
 {
     $sourceCode = '<?php echo "Hello world!";';
     $locator = new StringSourceLocator($sourceCode);
     $locatedSource = $locator->__invoke(new Identifier('does not matter what the class name is', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)));
     $this->assertSame($sourceCode, $locatedSource->getSource());
     $this->assertNull($locatedSource->getFileName());
 }
예제 #2
0
 public function testFetchingFqsenThrowsExceptionWithNonObjectName()
 {
     $sourceLocator = new StringSourceLocator('<?php class Foo {}');
     $reflector = new ClassReflector($sourceLocator);
     $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));
     $locatedSource = $sourceLocator->__invoke($identifier);
     $node = new Class_('Foo');
     $reflection = ReflectionClass::createFromNode($reflector, $node, $locatedSource);
     $reflectionClassReflection = new \ReflectionClass(ReflectionClass::class);
     $reflectionClassMethodReflection = $reflectionClassReflection->getMethod('getFqsenFromNamedNode');
     $reflectionClassMethodReflection->setAccessible(true);
     $nameNode = new Name(['int']);
     $this->setExpectedException(\Exception::class, 'Unable to determine FQSEN for named node');
     $reflectionClassMethodReflection->invoke($reflection, $nameNode);
 }