Skip to content

Commit 2723e06

Browse files
committed
Merge branch '5.7-selective-event-fakes' of https://github.com/tomlankhorst/docs into tomlankhorst-5.7-selective-event-fakes
2 parents c71cfbd + 3abd628 commit 2723e06

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

mocking.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Bus Fake](#bus-fake)
55
- [Event Fake](#event-fake)
66
- [Scoped Event Fakes](#scoped-event-fakes)
7+
- [Selective Event Fakes](#selective-event-fakes)
78
- [Mail Fake](#mail-fake)
89
- [Notification Fake](#notification-fake)
910
- [Queue Fake](#queue-fake)
@@ -126,6 +127,28 @@ If you only want to fake event listeners for a portion of your test, you may use
126127
}
127128
}
128129

130+
<a name="selective-event-fakes"></a>
131+
### Selective Event Fakes
132+
133+
If you only want to fake event listeners for a specific set of events, you may pass them to the `fake` or `fakeFor` method:
134+
135+
/**
136+
* Test order process.
137+
*/
138+
public function testOrderProcess()
139+
{
140+
Event::fake([
141+
OrderCreated::class,
142+
]);
143+
144+
$order = factory(Order::class)->create();
145+
146+
Event::assertDispatched(OrderCreated::class);
147+
148+
// Other events are dispatched as normal...
149+
$order->update([...]);
150+
}
151+
129152
<a name="mail-fake"></a>
130153
## Mail Fake
131154

0 commit comments

Comments
 (0)