Completed
Push — master ( 9abbc7...a687e5 )
by Fabrizio
03:03
created

DispatcherSpec::it_fire_a_notifynder_event()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 13
nc 1
nop 2
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