public function testTraitTester() { $trait = 'SR\\Util\\Test\\Fixture\\FixtureTrait'; static::assertTrue(ClassInfo::assertTrait($trait)); static::assertTrue(ClassInfo::isTrait($trait)); static::assertFalse(ClassInfo::isTrait(__CLASS__)); $this->expectException('\\InvalidArgumentException'); ClassInfo::assertTrait(__CLASS__); }
/** * @param string $class * @param string $method * @param null|object $bindTo * @param null|ResolverInterface $resolver */ public function __construct($class, $method, $bindTo = null, ResolverInterface $resolver = null) { try { parent::__construct(new \ReflectionMethod($class, $method), $bindTo, $resolver); if (ClassInfo::isTrait($class)) { $this->declaringClass = new TraitInspector($class); } if (!ClassInfo::isTrait($class) && ClassInfo::isClass($class)) { $this->declaringClass = new ClassInspector($class); } } catch (\Exception $exception) { throw $this->getConstructorException(['class name string', $class], ['method name string', $method]); } }
/** * Try to determine the type of passed item and proxies the call to the respective specific this[*] methods. * * @param object|string $what A class name, object instance, interface name, or trait name * @param object|null $bind Alternate $this binding for internal resolver instance * * @throws RuntimeException If passed value is not an instance, class, interface or trait * * @return ClassInspector|ObjectInspector|InterfaceInspector|TraitInspector */ public static function using($what, $bind = null) { if (ClassInfo::isInstance($what)) { return self::useInstance($what, $bind); } if (ClassInfo::isClass($what)) { return self::useClass($what, $bind); } if (ClassInfo::isInterface($what)) { return self::useInterface($what, $bind); } if (ClassInfo::isTrait($what)) { return self::useTrait($what); } throw RuntimeException::create('Invalid inspector argument provided (got %s)', var_export($what, true)); }