How mock model method in laravel

  laravel, mockery, php, phpunit

I have model method

public static function getDetails(
        array $fields,
        array $where_condition
    ) {
        return Event::select($fields)

I am calling this method like this

$logo = Event::getDetails(
[‘id’ => $id] )->logo;

so what I tried to mock method in below way but not working

$mock = $this->mock(Event::class, function (MockInterface $mock) {
    $collection = new IlluminateDatabaseEloquentCollection(
            new Event( array( "logo" => 'test.jpg' ) ),
    $mock->shouldReceive('getDetails')->once()->with(['logo', [ 'id'=> '123']])->andReturns('test.jpg');

It is returning null instead of image. It should not go into getDetails method but it is going there

Can anyone help?

Source: Laravel

Leave a Reply