pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.49k stars 343 forks source link

[Bug]: toHaveMethod expectation does not work correctly #1043

Closed marepilc closed 9 months ago

marepilc commented 9 months ago

What Happened

The test

it('has isAdmin method', function () {
    $user = User::factory()->admin()->make();
    expect($user)->toHaveMethod('isAdmin');
});

returns AssertionError: AssertionError: assert(is_string($expectation->value) || is_array($expectation->value))

When changed to expect($user)->toHaveMethods(['isAdmin']); the test passes.

How to Reproduce

Add $table->boolean('is_admin')->default(false); to the default users table and isAdmin method to the User model

public function isAdmin()
    {
        return $this->is_admin;
    }

Sample Repository

No response

Pest Version

2.28.1

PHP Version

8.2.7

Operation System

Windows

Notes

No response

nunomaduro commented 9 months ago

expect(User::class)->toHaveMethod(...);