mageekguy\atoum\asserters\exception::isInstanceOf PHP Method

isInstanceOf() public method

public isInstanceOf ( $value, $failMessage = null )
    public function isInstanceOf($value, $failMessage = null)
    {
        try {
            $this->check($value, __FUNCTION__);
        } catch (\logicException $exception) {
            if (self::classExists($value) === false || strtolower(ltrim($value, '\\')) !== 'exception' && is_subclass_of($value, version_compare(PHP_VERSION, '7.0.0') >= 0 ? 'throwable' : 'exception') === false) {
                throw new exceptions\logic\invalidArgument('Argument of ' . __METHOD__ . '() must be a \\exception instance or an exception class name');
            }
        }
        return parent::isInstanceOf($value, $failMessage);
    }

Usage Example

Beispiel #1
0
 public function testIsInstanceOf()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->hasSize(rand(0, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Exception is undefined')->if($asserter->setWith(new \exception()))->then->object($asserter->isInstanceOf('\\Exception'))->isIdenticalTo($asserter)->object($asserter->isInstanceOf('Exception'))->isIdenticalTo($asserter)->object($asserter->isInstanceOf('\\exception'))->isIdenticalTo($asserter)->object($asserter->isInstanceOf('exception'))->isIdenticalTo($asserter)->exception(function () use($asserter) {
         $asserter->isInstanceOf(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic\\invalidArgument')->hasMessage('Argument of mageekguy\\atoum\\asserters\\exception::isInstanceOf() must be a \\exception instance or an exception class name')->exception(function () use($asserter) {
         $asserter->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime');
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not an instance of mageekguy\\atoum\\exceptions\\runtime'), $asserter));
 }