BetterReflection\SourceLocator\Type\PhpInternalSourceLocator::hasStub PHP Метод

hasStub() публичный Метод

Determine if a stub exists for specified class name
public hasStub ( string $className ) : boolean
$className string
Результат boolean
    public function hasStub($className)
    {
        $expectedStubName = $this->buildStubName($className);
        if (null === $expectedStubName) {
            return false;
        }
        if (!file_exists($expectedStubName) || !is_readable($expectedStubName) || !is_file($expectedStubName)) {
            return false;
        }
        return true;
    }

Usage Example

 /**
  * @dataProvider internalSymbolsProvider
  *
  * @param string $className
  * @throws \ReflectionException
  */
 public function testCanReflectInternalClasses($className)
 {
     /* @var $class */
     $phpInternalSourceLocator = new PhpInternalSourceLocator();
     $reflector = new ClassReflector($phpInternalSourceLocator);
     try {
         $class = $reflector->reflect($className);
     } catch (\ReflectionException $e) {
         if ($phpInternalSourceLocator->hasStub($className)) {
             throw $e;
         }
         $this->markTestIncomplete(sprintf('Can\'t reflect class "%s" due to an internal reflection exception: "%s". Consider adding a stub class', $className, $e->getMessage()));
     }
     $this->assertInstanceOf(ReflectionClass::class, $class);
     $this->assertSame($className, $class->getName());
     $this->assertTrue($class->isInternal());
     $this->assertFalse($class->isUserDefined());
     $internalReflection = new \ReflectionClass($className);
     $this->assertSame($internalReflection->isInterface(), $class->isInterface());
     $this->assertSame($internalReflection->isTrait(), $class->isTrait());
 }