1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Fenos\Notifynder\Handler; |
4
|
|
|
|
5
|
|
|
use Fenos\Notifynder\Handler\NotifynderEvent; |
6
|
|
|
use Fenos\Notifynder\NotifynderManager; |
7
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
8
|
|
|
use PhpSpec\ObjectBehavior; |
9
|
|
|
|
10
|
|
|
class DispatcherSpec extends ObjectBehavior |
11
|
|
|
{ |
12
|
|
|
public function let(Dispatcher $dispatcher) |
13
|
|
|
{ |
14
|
|
|
$this->beConstructedWith($dispatcher); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function it_is_initializable() |
18
|
|
|
{ |
19
|
|
|
$this->shouldHaveType('Fenos\Notifynder\Handler\Dispatcher'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** @test */ |
23
|
|
|
public function it_fire_a_notifynder_event(Dispatcher $dispatcher, NotifynderManager $notifynder) |
24
|
|
|
{ |
25
|
|
|
$key = 'event'; |
26
|
|
|
$category = 'hello'; |
27
|
|
|
$extraValues = []; |
28
|
|
|
$notifyEvent = 'Notifynder.'.$key; |
29
|
|
|
$notificationBuilt = [ |
30
|
|
|
0 => ['notification'], |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
$notifynderEvent = new NotifynderEvent($notifyEvent, $category, $extraValues); |
34
|
|
|
|
35
|
|
|
$dispatcher->fire($notifyEvent, [$notifynderEvent, $notifynder])->shouldBeCalled() |
36
|
|
|
->willReturn($notificationBuilt); |
37
|
|
|
|
38
|
|
|
$notifynder->send($notificationBuilt[0])->shouldBeCalled() |
39
|
|
|
->willReturn(1); |
40
|
|
|
|
41
|
|
|
$this->fire($notifynder, $key, $category, $extraValues)->shouldReturn(1); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** @test */ |
45
|
|
|
public function it_fire_a_notifynder_event_having_nothing_to_send(Dispatcher $dispatcher, NotifynderManager $notifynder) |
46
|
|
|
{ |
47
|
|
|
$key = 'event'; |
48
|
|
|
$category = 'hello'; |
49
|
|
|
$extraValues = []; |
50
|
|
|
$notifyEvent = 'Notifynder.'.$key; |
51
|
|
|
|
52
|
|
|
$notifynderEvent = new NotifynderEvent($notifyEvent, $category, $extraValues); |
53
|
|
|
|
54
|
|
|
$dispatcher->fire($notifyEvent, [$notifynderEvent, $notifynder])->shouldBeCalled() |
55
|
|
|
->willReturn(null); |
56
|
|
|
|
57
|
|
|
$this->fire($notifynder, $key, $category, $extraValues) |
58
|
|
|
->shouldReturn(null); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|