1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Service; |
4
|
|
|
|
5
|
|
|
use JhFlexiTime\DateTime\DateTime; |
6
|
|
|
use JhFlexiTime\Options\NotificationOptions; |
7
|
|
|
use JhFlexiTime\Service\MissingBookingReminderService; |
8
|
|
|
use JhUser\Entity\User; |
9
|
|
|
use PHPUnit_Framework_TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class MissingBookingReminderServiceTest |
13
|
|
|
* @package JhFlexiTimeTest\Service |
14
|
|
|
* @author Aydin Hassan <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class MissingBookingReminderServiceTest extends PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
protected $notificationService; |
19
|
|
|
protected $userRepository; |
20
|
|
|
protected $userSettingsRepository; |
21
|
|
|
protected $bookingRepository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var NotificationOptions |
25
|
|
|
*/ |
26
|
|
|
protected $options; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var MissingBookingReminderService |
30
|
|
|
*/ |
31
|
|
|
protected $service; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->notificationService = $this->getMock('JhHubBase\Notification\NotificationService'); |
36
|
|
|
$this->userRepository = $this->getMock('JhUser\Repository\UserRepositoryInterface'); |
37
|
|
|
$this->userSettingsRepository = $this->getMock('JhFlexiTime\Repository\UserSettingsRepositoryInterface'); |
38
|
|
|
$this->bookingRepository = $this->getMock('JhFlexiTime\Repository\BookingRepositoryInterface'); |
39
|
|
|
$this->options = new NotificationOptions; |
40
|
|
|
$this->service = new MissingBookingReminderService( |
41
|
|
|
$this->notificationService, |
42
|
|
|
$this->userRepository, |
43
|
|
|
$this->userSettingsRepository, |
44
|
|
|
$this->bookingRepository, |
45
|
|
|
$this->options |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testFindAndNotifyMissingBookings() |
50
|
|
|
{ |
51
|
|
|
$user = new User; |
52
|
|
|
|
53
|
|
|
$this->userRepository |
54
|
|
|
->expects($this->once()) |
55
|
|
|
->method('findAll') |
56
|
|
|
->will($this->returnValue([$user])); |
57
|
|
|
|
58
|
|
|
$this->options->setRemindStart('11 November 2014'); |
59
|
|
|
$this->options->setRemindDays('2 days'); |
60
|
|
|
|
61
|
|
|
$this->bookingRepository |
62
|
|
|
->expects($this->at(0)) |
63
|
|
|
->method('findOneBy') |
64
|
|
|
->with(['user' => $user, 'date' => new DateTime('10 November 2014 00:00:00')]) |
65
|
|
|
->will($this->returnValue(null)); |
66
|
|
|
|
67
|
|
|
$this->bookingRepository |
68
|
|
|
->expects($this->at(1)) |
69
|
|
|
->method('findOneBy') |
70
|
|
|
->with(['user' => $user, 'date' => new DateTime('11 November 2014 00:00:00')]) |
71
|
|
|
->will($this->returnValue(null)); |
72
|
|
|
|
73
|
|
|
$this->notificationService |
74
|
|
|
->expects($this->once()) |
75
|
|
|
->method('notify') |
76
|
|
|
->with($this->isInstanceOf('JhFlexiTime\Notification\MissingBookingsNotification', $user)); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->service->findAndNotifyMissingBookings(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.