/** * @param ReflectionClass $class * * @return self */ public static function fromReflectionClass(ReflectionClass $class) { $type = 'class'; if ($class->isTrait()) { $type = 'trait'; } return new self(sprintf('Provided node "%s" is not interface, but "%s"', $class->getName(), $type)); }
/** * {@inheritDoc} */ public function getName() { return $this->betterReflectionClass->getName(); }
/** * @param ReflectionClass $class * * @return bool */ protected function isInterface(ReflectionClass $class) { return $class->isInterface() || substr($class->getName(), -strlen('Interface')) === 'Interface'; }
public function name() : string { return $this->reflectionClass->getName(); }
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())); } }
function it_might_be_invokable(ReflectionClass $reflectionClass, ReflectionMethod $method, AnnotationScanner $annotations, TypeFactory $typeFactory, Type $type, Annotations $methodAnnotations) { $reflectionClass->getName()->willReturn('MyClass'); $method->getName()->willReturn('__invoke'); $method->getReturnType()->willReturn(null); $method->getDocBlockReturnTypes()->willReturn([]); $method->getParameters()->willReturn([]); $method->getDocComment()->willReturn(''); $reflectionClass->getMethods()->willReturn([$method]); $annotations->scanForAnnotations(Argument::any(), Argument::any(), $this->imports)->willReturn($methodAnnotations); $typeFactory->create(Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn($type); $this->isInvokable()->shouldBe(true); $reflectionClass->getMethods()->willReturn([]); $this->isInvokable()->shouldBe(false); }