Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Finds whether a variable is an object
<?php is_object(mixed $value): bool
<?php     public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation|PendingArchExpectation

    {

        if (! self::hasMethod($method)) {

            if (! is_object($this->value) && method_exists(PendingArchExpectation::class, $method)) {

                $pendingArchExpectation = new PendingArchExpectation($this, []);



                return $pendingArchExpectation->$method(...$parameters); // @phpstan-ignore-line
<?php                 return $pendingArchExpectation->$method(...$parameters); // @phpstan-ignore-line

            }



            if (! is_object($this->value)) {

                throw new BadMethodCallException(sprintf(

                    'Method "%s" does not exist in %s.',

                    $method,
<?php         $reflectionClosure = new \ReflectionFunction($closure);

        $expectation = $reflectionClosure->getClosureThis();



        assert(is_object($expectation));



        ExpectationPipeline::for($closure)

            ->send(...$parameters)
<?php     public function __get(string $name)

    {

        if (! self::hasMethod($name)) {

            if (! is_object($this->value) && method_exists(PendingArchExpectation::class, $name)) {


                return $this->{$name}();

            }
<?php     public function __call(string $name, array $arguments): Expectation

    {

        try {

            if (! is_object($this->original->value) && method_exists(PendingArchExpectation::class, $name)) {

                throw InvalidExpectation::fromMethods(['not', $name]);

            }
<?php     public function __get(string $name): Expectation

    {

        try {

            if (! is_object($this->original->value) && method_exists(PendingArchExpectation::class, $name)) {

                throw InvalidExpectation::fromMethods(['not', $name]);

            }
<?php             return $this->toHaveCount($number, $message);

        }



        if (is_object($this->value)) {

            $array = method_exists($this->value, 'toArray') ? $this->value->toArray() : (array) $this->value;



            Assert::assertCount($number, $array, $message);
<?php     public function toHaveKey(string|int $key, mixed $value = new Any(), string $message = ''): self

    {

        if (is_object($this->value) && method_exists($this->value, 'toArray')) {

            $array = $this->value->toArray();

        } else {

            $array = (array) $this->value;
<?php     public function toMatchArray(iterable $array, string $message = ''): self

    {

        if (is_object($this->value) && method_exists($this->value, 'toArray')) {

            $valueAsArray = $this->value->toArray();

        } else {

            $valueAsArray = (array) $this->value;
<?php     public function toMatchObject(iterable $object, string $message = ''): self

    {

        foreach ((array) $object as $property => $value) {

            if (! is_object($this->value) && ! is_string($this->value)) {

                InvalidExpectationValue::expected('object|string');

            }
<?php         $string = match (true) {

            is_string($this->value) => $this->value,

            is_object($this->value) && method_exists($this->value, 'toSnapshot') => $this->value->toSnapshot(),

            is_object($this->value) && method_exists($this->value, '__toString') => $this->value->__toString(),

            is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(),

            $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line
<?php         $string = match (true) {

            is_string($this->value) => $this->value,

            is_object($this->value) && method_exists($this->value, 'toSnapshot') => $this->value->toSnapshot(),

            is_object($this->value) && method_exists($this->value, '__toString') => $this->value->__toString(),

            is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(),

            $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line

            is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),
<?php             is_string($this->value) => $this->value,

            is_object($this->value) && method_exists($this->value, 'toSnapshot') => $this->value->toSnapshot(),

            is_object($this->value) && method_exists($this->value, '__toString') => $this->value->__toString(),

            is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(),

            $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line

            is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),
<?php             is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof JsonSerializable => json_encode($this->value->jsonSerialize(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            is_object($this->value) && method_exists($this->value, 'toArray') => json_encode($this->value->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            default => InvalidExpectationValue::expected('array|object|string'),

        };
<?php     public static function boundWhen(Closure $condition, Closure $next): Closure

    {

        return function () use ($condition, $next): void {

            if (! is_object($this)) { // @phpstan-ignore-line

                throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.');

            }