public function testFromNonObject() { $exception = NotAnObject::fromNonObject(123); $this->assertInstanceOf(NotAnObject::class, $exception); $this->assertSame('Provided "integer" is not an object', $exception->getMessage()); }
/** * Checks whether the given object is an instance. * * @link http://php.net/manual/en/reflectionclass.isinstance.php * * @param object $object * * @return bool * * @throws NotAnObject */ public function isInstance($object) { if (!is_object($object)) { throw NotAnObject::fromNonObject($object); } $className = $this->getName(); // note: since $object was loaded, we can safely assume that $className is available in the current // php script execution context return $object instanceof $className; }