.cursor/skills/laravel-actions/references/testing-fakes.md
Use this reference when isolating action orchestration in tests.
AsFake helpers (mock, partialMock, spy, shouldRun, shouldNotRun, allowToRun).isFake, clearFake).mock()partialMock()spy()shouldRun()shouldNotRun()allowToRun()isFake()clearFake()handle(...) directly for business rules.AsFake trait)mockSwaps the action with a full mock.
FetchContactsFromGoogle::mock()
->shouldReceive('handle')
->with(42)
->andReturn(['Loris', 'Will', 'Barney']);
partialMockSwaps the action with a partial mock.
FetchContactsFromGoogle::partialMock()
->shouldReceive('fetch')
->with('some_google_identifier')
->andReturn(['Loris', 'Will', 'Barney']);
spySwaps the action with a spy.
$spy = FetchContactsFromGoogle::spy()
->allows('handle')
->andReturn(['Loris', 'Will', 'Barney']);
// ...
$spy->shouldHaveReceived('handle')->with(42);
shouldRunHelper adding expectation on handle.
FetchContactsFromGoogle::shouldRun();
// Equivalent to:
FetchContactsFromGoogle::mock()->shouldReceive('handle');
shouldNotRunHelper adding negative expectation on handle.
FetchContactsFromGoogle::shouldNotRun();
// Equivalent to:
FetchContactsFromGoogle::mock()->shouldNotReceive('handle');
allowToRunHelper allowing handle on a spy.
$spy = FetchContactsFromGoogle::allowToRun()
->andReturn(['Loris', 'Will', 'Barney']);
// ...
$spy->shouldHaveReceived('handle')->with(42);
isFakeReturns whether the action has been swapped with a fake.
FetchContactsFromGoogle::isFake(); // false
FetchContactsFromGoogle::mock();
FetchContactsFromGoogle::isFake(); // true
clearFakeClears the fake instance, if any.
FetchContactsFromGoogle::mock();
FetchContactsFromGoogle::isFake(); // true
FetchContactsFromGoogle::clearFake();
FetchContactsFromGoogle::isFake(); // false
it('runs sync contacts for premium teams', function () {
SyncGoogleContacts::shouldRun()->once()->with(42)->andReturnTrue();
ImportTeamContacts::run(42, isPremium: true);
});
it('does not run sync when integration is disabled', function () {
SyncGoogleContacts::shouldNotRun();
ImportTeamContacts::run(42, integrationEnabled: false);
});
shouldRun() / shouldNotRun() where clearer.