MissedBookingEmailNotificationHandlerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 105
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testShouldHandle() 0 11 1
B testHandle() 0 33 1
B testHandleWithRandomGiphyImage() 0 45 1
1
<?php
2
3
namespace JhFlexiTime\NotificationHandler;
4
5
use JhFlexiTime\Notification\MissingBookingsNotification;
6
use JhHubBase\Module;
7
use JhHubBase\Notification\Notification;
8
use JhHubBase\Options\ModuleOptions;
9
use JhUser\Entity\User;
10
use PHPUnit_Framework_TestCase;
11
12
class MissedBookingEmailNotificationHandlerTest extends PHPUnit_Framework_TestCase
13
{
14
    protected $handler;
15
    protected $mailService;
16
    protected $giphy;
17
18
    public function setUp()
19
    {
20
        $this->mailService = $this->getMock('\AcMailer\Service\MailServiceInterface');
21
        $this->giphy = $this->getMock('rfreebern\Giphy');
22
        $this->handler = new MissedBookingEmailNotificationHandler($this->mailService, new ModuleOptions, $this->giphy);
23
    }
24
25
    public function testShouldHandle()
26
    {
27
        $notification = new MissingBookingsNotification([], []);
28
        $this->assertTrue($this->handler->shouldHandle($notification));
29
30
        $notification = new Notification('missing-bookings', []);
31
        $this->assertFalse($this->handler->shouldHandle($notification));
32
33
        $notification = new Notification('different-notification', []);
34
        $this->assertFalse($this->handler->shouldHandle($notification));
35
    }
36
37
    public function testHandle()
38
    {
39
        $user = new User;
40
        $user->setEmail('[email protected]');
41
        $notification = new MissingBookingsNotification([], []);
42
43
        $this->mailService
44
            ->expects($this->once())
45
            ->method('setSubject')
46
            ->with('Missing Bookings');
47
48
        $message = $this->getMock('Zend\Mail\Message');
49
        $this->mailService
50
            ->expects($this->any())
51
            ->method('getMessage')
52
            ->will($this->returnValue($message));
53
54
        $message
55
            ->expects($this->once())
56
            ->method('setTo')
57
            ->with(['[email protected]']);
58
59
        $this->mailService
60
            ->expects($this->once())
61
            ->method('setTemplate')
62
            ->with($this->isInstanceOf('Zend\View\Model\ViewModel'));
63
64
        $this->mailService
65
            ->expects($this->once())
66
            ->method('send');
67
68
        $this->handler->handle($notification, $user);
69
    }
70
71
    public function testHandleWithRandomGiphyImage()
72
    {
73
        $user = new User;
74
        $user->setEmail('[email protected]');
75
        $notification = new MissingBookingsNotification([], []);
76
77
        $this->mailService
78
            ->expects($this->once())
79
            ->method('setSubject')
80
            ->with('Missing Bookings');
81
82
        $message = $this->getMock('Zend\Mail\Message');
83
        $this->mailService
84
            ->expects($this->any())
85
            ->method('getMessage')
86
            ->will($this->returnValue($message));
87
88
        $message
89
            ->expects($this->once())
90
            ->method('setTo')
91
            ->with(['[email protected]']);
92
93
        $this->mailService
94
            ->expects($this->once())
95
            ->method('setTemplate')
96
            ->with($this->isInstanceOf('Zend\View\Model\ViewModel'));
97
98
        $this->mailService
99
            ->expects($this->once())
100
            ->method('send');
101
102
        $giphyData = (object) [
103
            'data' => (object) [
104
                'image_original_url' => 'some/url',
105
            ],
106
        ];
107
108
        $this->giphy
109
            ->expects($this->once())
110
            ->method('random')
111
            ->with('fail')
112
            ->will($this->returnValue($giphyData));
113
114
        $this->handler->handle($notification, $user);
115
    }
116
}
117