1 | <?php |
||
17 | class TimeCalculatorServiceTest extends \PHPUnit_Framework_TestCase |
||
18 | { |
||
19 | /** |
||
20 | * @var \JhFlexiTime\Service\TimeCalculatorService |
||
21 | */ |
||
22 | protected $timeCalculatorService; |
||
23 | |||
24 | /** |
||
25 | * @var float |
||
26 | */ |
||
27 | protected $hoursInDay = 7.5; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $lunchDuration = 1; |
||
33 | |||
34 | /** |
||
35 | * @var \JhFlexiTime\Options\ModuleOptions |
||
36 | */ |
||
37 | protected $options; |
||
38 | |||
39 | /** |
||
40 | * @var \DateTime $date |
||
41 | */ |
||
42 | protected $date; |
||
43 | |||
44 | /** |
||
45 | * @var \JhFlexiTime\Repository\BookingRepositoryInterface |
||
46 | */ |
||
47 | protected $bookingRepository; |
||
48 | |||
49 | /** |
||
50 | * @var \JhFlexiTime\Service\BalanceServiceInterface |
||
51 | */ |
||
52 | protected $balanceService; |
||
53 | |||
54 | protected $balanceRepository; |
||
55 | |||
56 | /** |
||
57 | * @var \JhFlexiTime\Service\PeriodService |
||
58 | */ |
||
59 | protected $periodService; |
||
60 | |||
61 | /** |
||
62 | * Create Service |
||
63 | */ |
||
64 | public function setUp() |
||
77 | |||
78 | /** |
||
79 | * @return TimeCalculatorService |
||
80 | */ |
||
81 | public function getService(DateTime $today = null) |
||
93 | |||
94 | /** |
||
95 | * @param float $initialBalance |
||
96 | * @param float $expectedBalance |
||
97 | * @param float $monthToDateTotalHours |
||
98 | * @param float $bookedToDate |
||
99 | * |
||
100 | * @dataProvider runningBalanceProvider |
||
101 | */ |
||
102 | // public function testGetRunningBalance($initialBalance, $expectedBalance, $bookedToDate) |
||
103 | // { |
||
104 | // |
||
105 | // $mockUser = $this->getMock('ZfcUser\Entity\UserInterface'); |
||
106 | // $runningBalance = new RunningBalance(); |
||
107 | // $runningBalance->setBalance($initialBalance); |
||
108 | // |
||
109 | // $this->balanceRepository->expects($this->once()) |
||
110 | // ->method('findOneByUser') |
||
111 | // ->with($mockUser) |
||
112 | // ->will($this->returnValue($runningBalance)); |
||
113 | // |
||
114 | // $this->bookingRepository->expects($this->once()) |
||
115 | // ->method('getMonthBookedToDateTotalByUser') |
||
116 | // ->with($mockUser, $this->date) |
||
117 | // ->will($this->returnValue($bookedToDate)); |
||
118 | // |
||
119 | // $balance = $this->getService()->getRunningBalance($mockUser); |
||
120 | // $this->assertEquals($expectedBalance, $balance); |
||
121 | // } |
||
122 | |||
123 | /** |
||
124 | * @return array |
||
125 | */ |
||
126 | // public function runningBalanceProvider() |
||
127 | // { |
||
128 | // /** |
||
129 | // * Initial Balance | Expected Balance | Month Booked |
||
130 | // */ |
||
131 | // return [ |
||
132 | // [0, -5, 10], |
||
133 | // [0, 0, 15], |
||
134 | // [5, 0, 10], |
||
135 | // [5, 5, 15], |
||
136 | // [-5, 0, 15], |
||
137 | // [-5, -5, 15], |
||
138 | // [-5, -10, 10], |
||
139 | // [-50, -50, 150], |
||
140 | // [-50, -100, 100], |
||
141 | // [50, 100, 200], |
||
142 | // [0, -1.75, 18.25], |
||
143 | // [-10.5, 0, 30.5], |
||
144 | // |
||
145 | // ]; |
||
146 | // } |
||
147 | |||
148 | // public function testGetBalanceForwardReturnsZeroIfNoRowPresent() |
||
149 | // { |
||
150 | // $user = new User; |
||
151 | // |
||
152 | // $this->balanceRepository |
||
153 | // ->expects($this->once()) |
||
154 | // ->method('findOneByUser') |
||
155 | // ->with($user) |
||
156 | // ->will($this->returnValue(null)); |
||
157 | // |
||
158 | // $this->assertEquals(0, $this->getService()->getBalanceForward($user)); |
||
159 | // } |
||
160 | |||
161 | // public function testGetBalanceForwardReturnsRunningBalance() |
||
162 | // { |
||
163 | // $balance = 25; |
||
164 | // $user = new User; |
||
165 | // $runningBalance = new RunningBalance(); |
||
166 | // $runningBalance->setBalance($balance); |
||
167 | // |
||
168 | // $this->balanceRepository |
||
169 | // ->expects($this->once()) |
||
170 | // ->method('findOneByUser') |
||
171 | // ->with($user) |
||
172 | // ->will($this->returnValue($runningBalance)); |
||
173 | // |
||
174 | // $this->assertEquals($balance, $this->getService()->getBalanceForward($user)); |
||
175 | // } |
||
176 | |||
177 | // public function testGetMonthBalanceWithPreviousMonthReturnsFullMonthBalance() |
||
178 | // { |
||
179 | // $user = new User; |
||
180 | // $this->date = new DateTime("15 May 2014"); |
||
181 | // $date = new DateTime("4 April 2014"); |
||
182 | // $startDate = new DateTime('4 March 2014'); |
||
183 | // |
||
184 | // $this->bookingRepository |
||
185 | // ->expects($this->once()) |
||
186 | // ->method('getMonthBookedTotalByUser') |
||
187 | // ->with($user, $date) |
||
188 | // ->will($this->returnValue(40)); |
||
189 | // |
||
190 | // $this->assertEquals(-125.0, $this->getService()->getMonthBalance($user, $startDate, $date)); |
||
191 | // } |
||
192 | // |
||
193 | // public function testGetMonthBalanceWithSameMonthReturnsToDateBalance() |
||
194 | // { |
||
195 | // $user = new User; |
||
196 | // $this->date = new DateTime("15 May 2014"); |
||
197 | // $date = new DateTime("4 May 2014"); |
||
198 | // $startDate = new DateTime('4 April 2014'); |
||
199 | // |
||
200 | // $this->bookingRepository |
||
201 | // ->expects($this->once()) |
||
202 | // ->method('getMonthBookedToDateTotalByUser') |
||
203 | // ->with($user, $this->date) |
||
204 | // ->will($this->returnValue(40)); |
||
205 | // |
||
206 | // $this->assertEquals(-42.5, $this->getService()->getMonthBalance($user, $startDate, $date)); |
||
207 | // } |
||
208 | // |
||
209 | // public function testGetMonthBalanceWithFutureMonthDateReturnsZero() |
||
210 | // { |
||
211 | // $user = new User; |
||
212 | // $this->date = new DateTime("15 May 2014"); |
||
213 | // $date = new DateTime("16 June 2014"); |
||
214 | // $startDate = new DateTime('4 March 2014'); |
||
215 | // |
||
216 | // $this->assertEquals(0, $this->getService()->getMonthBalance($user, $startDate, $date)); |
||
217 | // } |
||
218 | |||
219 | // public function testGetMonthTotalWorkedHoursForPreviousMonth() |
||
220 | // { |
||
221 | // $user = new User; |
||
222 | // $this->date = new DateTime("15 May 2014"); |
||
223 | // $date = new DateTime("4 April 2014"); |
||
224 | // $startDate = new DateTime('4 March 2014'); |
||
225 | // |
||
226 | // $this->bookingRepository |
||
227 | // ->expects($this->once()) |
||
228 | // ->method('getMonthBookedTotalByUser') |
||
229 | // ->with($user, $date) |
||
230 | // ->will($this->returnValue(40)); |
||
231 | // |
||
232 | // $this->assertEquals(40, $this->getService()->getMonthTotalWorked($user, $startDate, $date)); |
||
233 | // } |
||
234 | // |
||
235 | // public function testGetMonthTotalWorkedHoursForCurrentMonth() |
||
236 | // { |
||
237 | // $user = new User; |
||
238 | // $this->date = new DateTime("15 May 2014"); |
||
239 | // $date = new DateTime("15 May 2014"); |
||
240 | // $startDate = new DateTime('4 March 2014'); |
||
241 | // |
||
242 | // $this->bookingRepository |
||
243 | // ->expects($this->once()) |
||
244 | // ->method('getMonthBookedToDateTotalByUser') |
||
245 | // ->with($user, $date) |
||
246 | // ->will($this->returnValue(40)); |
||
247 | // |
||
248 | // $this->assertEquals(40, $this->getService()->getMonthTotalWorked($user, $startDate, $date)); |
||
249 | // } |
||
250 | |||
251 | public function testGetWeekTotals() |
||
273 | |||
274 | public function testGetTotalsForCurrentMonthWhereStartDateWasInAPreviousMonth() |
||
305 | |||
306 | public function testGetTotalsForCurrentMonthWhereStartDateWasInAPreviousMonthWithRunningBalance() |
||
345 | |||
346 | |||
347 | |||
348 | |||
349 | public function testGetTotalsForCurrentMonthWhereStartDateWasInThisMonth() |
||
380 | |||
381 | public function testGetTotalsForAPreviousMonthWhereStartDateWasInAPreviousMonthToThat() |
||
412 | |||
413 | public function testGetTotalsForAPreviousMonthWhereStartDateWasInThatMonth() |
||
444 | |||
445 | public function testGetTotalsBalanceIsZeroIfInFutureMonth() |
||
465 | |||
466 | public function testGetTotalsBalanceIsZeroIfInFutureMonthWithRunningBalanceAddedOn() |
||
495 | } |
||
496 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.