method_exists

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Checks if the class method exists
<?php method_exists(object|string $object_or_class, string $method): 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     private function getExpectationClosure(string $name): Closure

    {

        if (method_exists(Mixins\Expectation::class, $name)) {


            return Closure::fromCallable([new Mixins\Expectation($this->value), $name]);

        }
<?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 static function hasMethod(string $name): bool

    {

        return method_exists(self::class, $name)

            || method_exists(Mixins\Expectation::class, $name)

            || self::hasExtend($name);

    }
<?php     public static function hasMethod(string $name): bool

    {

        return method_exists(self::class, $name)

            || method_exists(Mixins\Expectation::class, $name)

            || self::hasExtend($name);

    }
<?php     private function expectationHasMethod(string $name): bool

    {

        if (method_exists($this->original, $name)) {

            return true;

        }

        if ($this->original::hasMethod($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         }



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

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



            Assert::assertCount($number, $array, $message);
<?php         $this->toBeObject();




        Assert::assertTrue(method_exists($this->value, $name), $message);



        return $this;

    }
<?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         $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),