#Mocking does not work

2 messages · Page 1 of 1 (latest)

iron vortex
#

Am I doing something wrong?

<?php

use App\Actions\SomeAction;

test('mock', function () {
    mock(SomeAction::class)
        ->shouldReceive('run')
        ->once()
        ->andReturnUndefined();

    app(SomeAction::class)->run('foo');
});
<?php

namespace App\Actions;

class SomeAction
{
    public function run(string $foo): void
    {
        throw new \RuntimeException('Unreachable error');
    }
}

The run() method should never be executed, or am I wrong?

iron vortex
#

Ah, I was calling a different mock(), from Mockery, instead of from the Laravel Pest helper.