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); }
/** * {@inheritDoc} */ public function getMethod($name) { return new ReflectionMethod($this->betterReflectionClass->getMethod($name)); }
private function assertSameClassAttributes(\ReflectionClass $original, ReflectionClass $stubbed) { $this->assertSame($original->getName(), $stubbed->getName()); $internalParent = $original->getParentClass(); $betterParent = $stubbed->getParentClass(); $internalParentName = $internalParent ? $internalParent->getName() : null; $betterParentName = $betterParent ? $betterParent->getName() : null; $this->assertSame($internalParentName, $betterParentName); $originalMethods = $original->getMethods(); $originalMethodNames = array_map(function (\ReflectionMethod $method) { return $method->getName(); }, $originalMethods); $stubbedMethodNames = array_map(function (ReflectionMethod $method) { return $method->getName(); }, $stubbed->getMethods()); sort($originalMethodNames); sort($stubbedMethodNames); $this->assertSame($originalMethodNames, $stubbedMethodNames); $this->assertEquals($original->getConstants(), $stubbed->getConstants()); foreach ($originalMethods as $method) { $this->assertSameMethodAttributes($method, $stubbed->getMethod($method->getName())); } }