testCalculateRecalculateAllUsersRunningBalanceWithBookedHours()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 59
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 59
rs 9.597
cc 1
eloc 41
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace JhFlexiTimeTest\Service;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use JhFlexiTime\Entity\RunningBalance;
7
use JhFlexiTime\Entity\UserSettings;
8
use JhFlexiTime\Options\ModuleOptions;
9
use JhFlexiTime\Repository\BalanceRepositoryInterface;
10
use JhFlexiTime\Repository\BookingRepository;
11
use JhFlexiTime\Repository\UserSettingsRepositoryInterface;
12
use JhFlexiTime\Service\PeriodService;
13
use JhFlexiTime\Service\RunningBalanceService;
14
use JhUser\Entity\User;
15
use JhFlexiTime\DateTime\DateTime;
16
use JhUser\Repository\UserRepositoryInterface;
17
use ZfcUser\Entity\UserInterface;
18
19
/**
20
 * Class RunningBalanceServiceTest
21
 * @package JhFlexiTimeTest\Service
22
 * @author Aydin Hassan <[email protected]>
23
 */
24
class RunningBalanceServiceTest extends \PHPUnit_Framework_TestCase
25
{
26
27
    /**
28
     * @var UserRepositoryInterface
29
     */
30
    protected $userRepository;
31
32
    /**
33
     * @var UserSettingsRepositoryInterface
34
     */
35
    protected $userSettingsRepository;
36
37
    /**
38
     * @var RunningBalanceService
39
     */
40
    protected $runningBalanceService;
41
42
    /**
43
     * @var PeriodService
44
     */
45
    protected $periodService;
46
47
    /**
48
     * @var BookingRepository
49
     */
50
    protected $bookingRepository;
51
52
    /**
53
     * @var BalanceRepositoryInterface
54
     */
55
    protected $balanceRepository;
56
57
    /**
58
     * @var DateTime
59
     */
60
    protected $date;
61
62
    /**
63
     * @var ObjectManager
64
     */
65
    protected $objectManager;
66
67
    /**
68
     * @var \Zend\EventManager\EventManagerInterface
69
     */
70
    protected $evm;
71
72
    public function setUp()
73
    {
74
        $this->userRepository           = $this->getMock('JhUser\Repository\UserRepositoryInterface');
75
        $this->userSettingsRepository   = $this->getMock('JhFlexiTime\Repository\UserSettingsRepositoryInterface');
76
        $this->balanceRepository        = $this->getMock('JhFlexiTime\Repository\BalanceRepositoryInterface');
77
        $this->periodService            = new PeriodService(new ModuleOptions());
78
        $this->bookingRepository        = $this->getMock('JhFlexiTime\Repository\BookingRepositoryInterface');
79
        $this->objectManager            = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
80
        $this->date                     = new DateTime("2 May 2014");
81
        $this->evm                      = $this->getMock('Zend\EventManager\EventManagerInterface');
82
83
        $this->runningBalanceService = new RunningBalanceService(
84
            $this->userRepository,
85
            $this->userSettingsRepository,
86
            $this->bookingRepository,
87
            $this->balanceRepository,
88
            $this->periodService,
89
            $this->objectManager,
90
            $this->date
91
        );
92
93
        $this->runningBalanceService->setEventManager($this->evm);
94
    }
95
96
    public function testCalculatePreviousMonthBalanceWithNoBookedHours()
97
    {
98
        list($user1, $userSettings1) = $this->getUser(new DateTime("10 April 2014"));
99
        list($user2, $userSettings2) = $this->getUser(new DateTime("1 January 2014"));
100
101
        $runningBalance1 = new RunningBalance;
102
        $runningBalance1->setBalance(20);
103
104
        $runningBalance2 = new RunningBalance;
105
        $runningBalance2->setBalance(-20);
106
107
        $this->userRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhUser\Repository\UserRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
            ->expects($this->once())
109
            ->method('findAll')
110
            ->with(false)
111
            ->will($this->returnValue([$user1, $user2]));
112
113
        $this->balanceRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...nceRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
            ->expects($this->exactly(2))
115
            ->method('findOneByUser')
116
            ->will($this->returnValueMap(
117
                array(
118
                    array($user1, $runningBalance1),
119
                    array($user2, $runningBalance2),
120
                )
121
            ));
122
123
        $this->userSettingsRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...ngsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
            ->expects($this->exactly(2))
125
            ->method('findOneByUser')
126
            ->will($this->returnValueMap(
127
                array(
128
                    array($user1, $userSettings1),
129
                    array($user2, $userSettings2),
130
                )
131
            ));
132
133
        $invokeCount = $this->evmExpects([new DateTime("30 April 2014 23:59:59")], $runningBalance1, false, 0);
134
        $this->evmExpects([new DateTime("30 April 2014 23:59:59")], $runningBalance2, false, $invokeCount);
135
136
        $this->objectManager->expects($this->once())->method('flush');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\Persistence\ObjectManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
137
138
        $this->runningBalanceService->indexPreviousMonthBalance();
139
        $this->assertEquals(-92.5, $runningBalance1->getBalance());
140
        $this->assertEquals(-185, $runningBalance2->getBalance());
141
    }
142
143
    public function testCalculatePreviousMonthBalanceWithBookedHours()
144
    {
145
        list($user1, $userSettings1) = $this->getUser(new DateTime("10 April 2014"));
146
        list($user2, $userSettings2) = $this->getUser(new DateTime("1 January 2014"));
147
148
        $runningBalance1 = new RunningBalance;
149
        $runningBalance1->setBalance(20);
150
151
        $runningBalance2 = new RunningBalance;
152
        $runningBalance2->setBalance(-20);
153
154
        $this->userRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhUser\Repository\UserRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
155
            ->expects($this->once())
156
            ->method('findAll')
157
            ->with(false)
158
            ->will($this->returnValue([$user1, $user2]));
159
160
        $this->balanceRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...nceRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
161
            ->expects($this->exactly(2))
162
            ->method('findOneByUser')
163
            ->will($this->returnValueMap(
164
                array(
165
                    array($user1, $runningBalance1),
166
                    array($user2, $runningBalance2),
167
                )
168
            ));
169
170
        $this->userSettingsRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...ngsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
171
            ->expects($this->exactly(2))
172
            ->method('findOneByUser')
173
            ->will($this->returnValueMap(
174
                array(
175
                    array($user1, $userSettings1),
176
                    array($user2, $userSettings2),
177
                )
178
            ));
179
180
        $user1Dates = [
181
            [new DateTime("10 April 2014 00:00:00"), new DateTime("30 April 2014 23:59:59"), 100],
182
        ];
183
184
        $user2Dates = [
185
            [new DateTime("1 April 2014 00:00:00"), new DateTime("30 April 2014 23:59:59"), 100],
186
        ];
187
188
        $invokeCount = $this->bookingRepositoryExpects($user1, $user1Dates);
189
        $invokeCount = $this->bookingRepositoryExpects($user2, $user2Dates, $invokeCount);
0 ignored issues
show
Unused Code introduced by
$invokeCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
190
191
        $invokeCount = $this->evmExpects([new DateTime("30 April 2014 23:59:59")], $runningBalance1, false, 0);
192
        $this->evmExpects([new DateTime("30 April 2014 23:59:59")], $runningBalance2, false, $invokeCount);
193
194
        $this->objectManager->expects($this->once())->method('flush');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\Persistence\ObjectManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
195
196
        $this->runningBalanceService->indexPreviousMonthBalance();
197
        $this->assertEquals(7.5, $runningBalance1->getBalance());
198
        $this->assertEquals(-85, $runningBalance2->getBalance());
199
    }
200
201
    public function testCalculateRecalculateAllUsersRunningBalance()
202
    {
203
        $user1Start = new DateTime("10 April 2014");
204
        $user2Start = new DateTime("1 January 2014");
205
        list($user1, $userSettings1) = $this->getUser($user1Start);
206
        list($user2, $userSettings2) = $this->getUser($user2Start);
207
208
        $runningBalance1 = new RunningBalance;
209
        $runningBalance2 = new RunningBalance;
210
211
        $this->userRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhUser\Repository\UserRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
212
            ->expects($this->once())
213
            ->method('findAll')
214
            ->with(false)
215
            ->will($this->returnValue([$user1, $user2]));
216
217
        $this->balanceRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...nceRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
218
            ->expects($this->exactly(2))
219
            ->method('findOneByUser')
220
            ->will($this->returnValueMap(
221
                array(
222
                    array($user1, $runningBalance1),
223
                    array($user2, $runningBalance2),
224
                )
225
            ));
226
227
        $this->userSettingsRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...ngsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
228
            ->expects($this->exactly(2))
229
            ->method('findOneByUser')
230
            ->will($this->returnValueMap(
231
                array(
232
                    array($user1, $userSettings1),
233
                    array($user2, $userSettings2),
234
                )
235
            ));
236
237
        $this->objectManager->expects($this->once())->method('flush');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\Persistence\ObjectManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
238
239
        $user1Dates = [
240
            [$user1Start, new DateTime("30 April 2014 23:59:59"), 0],
241
        ];
242
243
        $user2Dates = [
244
            [$user2Start, new DateTime('31 January 2014 23:59:59'), 0],
245
            [new DateTime('1 February 2014 00:00:00'), new DateTime('28 February 2014 23:59:59'), 0],
246
            [new DateTime('1 March 2014 00:00:00'), new DateTime('31 March 2014 23:59:59'), 0],
247
            [new DateTime('1 April 2014 00:00:00'), new DateTime('30 April 2014 23:59:59'), 0],
248
        ];
249
250
        $invokeCount = $this->bookingRepositoryExpects($user1, $user1Dates);
251
        $invokeCount = $this->bookingRepositoryExpects($user2, $user2Dates, $invokeCount);
0 ignored issues
show
Unused Code introduced by
$invokeCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
252
253
        $invokeCount = $this->evmExpects(array_column($user1Dates, 1), $runningBalance1, true, 0);
254
        $invokeCount = $this->evmExpects(array_column($user2Dates, 1), $runningBalance2, true, $invokeCount);
0 ignored issues
show
Unused Code introduced by
$invokeCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
255
256
        $this->runningBalanceService->reIndexAllUsersRunningBalance();
257
        $this->assertEquals(-112.5, $runningBalance1->getBalance());
258
        $this->assertEquals(-645, $runningBalance2->getBalance());
259
    }
260
261
    public function testCalculateRecalculateAllUsersRunningBalanceWithBookedHours()
262
    {
263
        $user1Start = new DateTime("10 April 2014");
264
        $user2Start = new DateTime("1 January 2014");
265
        list($user1, $userSettings1) = $this->getUser($user1Start);
266
        list($user2, $userSettings2) = $this->getUser($user2Start);
267
268
        $runningBalance1 = new RunningBalance;
269
        $runningBalance2 = new RunningBalance;
270
271
        $this->userRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhUser\Repository\UserRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
272
            ->expects($this->once())
273
            ->method('findAll')
274
            ->with(false)
275
            ->will($this->returnValue([$user1, $user2]));
276
277
        $this->balanceRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...nceRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
278
            ->expects($this->exactly(2))
279
            ->method('findOneByUser')
280
            ->will($this->returnValueMap(
281
                array(
282
                    array($user1, $runningBalance1),
283
                    array($user2, $runningBalance2),
284
                )
285
            ));
286
287
        $this->userSettingsRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...ngsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
288
            ->expects($this->exactly(2))
289
            ->method('findOneByUser')
290
            ->will($this->returnValueMap(
291
                array(
292
                    array($user1, $userSettings1),
293
                    array($user2, $userSettings2),
294
                )
295
            ));
296
297
        $this->objectManager->expects($this->once())->method('flush');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\Persistence\ObjectManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
298
299
        $user1Dates = [
300
            [$user1Start, new DateTime("30 April 2014 23:59:59"), 100],
301
        ];
302
303
        $user2Dates = [
304
            [$user2Start, new DateTime('31 January 2014 23:59:59'), 50],
305
            [new DateTime('1 February 2014 00:00:00'), new DateTime('28 February 2014 23:59:59'), 50],
306
            [new DateTime('1 March 2014 00:00:00'), new DateTime('31 March 2014 23:59:59'), 50],
307
            [new DateTime('1 April 2014 00:00:00'), new DateTime('30 April 2014 23:59:59'), 50],
308
        ];
309
310
        $invokeCount = $this->bookingRepositoryExpects($user1, $user1Dates);
311
        $invokeCount = $this->bookingRepositoryExpects($user2, $user2Dates, $invokeCount);
0 ignored issues
show
Unused Code introduced by
$invokeCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
312
313
        $invokeCount = $this->evmExpects(array_column($user1Dates, 1), $runningBalance1, true, 0);
314
        $invokeCount = $this->evmExpects(array_column($user2Dates, 1), $runningBalance2, true, $invokeCount);
0 ignored issues
show
Unused Code introduced by
$invokeCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
315
316
        $this->runningBalanceService->reIndexAllUsersRunningBalance();
317
        $this->assertEquals(-12.5, $runningBalance1->getBalance());
318
        $this->assertEquals(-445, $runningBalance2->getBalance());
319
    }
320
321
    /**
322
     * @param float $startBalance
323
     * @param DateTime $startDate
324
     * @param float $expectedBalance
325
     * @param float $bookedHours
326
     * @dataProvider singleUserStartDateProvider
327
     */
328
    public function testRecalculateSingleUserRunningBalanceConsidersUsersStartDate(
329
        $startBalance,
330
        DateTime $startDate,
331
        $expectedBalance,
332
        $bookedHours
333
    ) {
334
        $user = new User;
335
        $runningBalance = new RunningBalance;
336
        $userSettings = new UserSettings;
337
        $userSettings->setFlexStartDate($startDate);
338
        $userSettings->setStartingBalance($startBalance);
339
340
        $this->balanceRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...nceRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
341
            ->expects($this->once())
342
            ->method('findOneByUser')
343
            ->with($user)
344
            ->will($this->returnValue($runningBalance));
345
346
        $this->userSettingsRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...ngsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
347
            ->expects($this->once())
348
            ->method('findOneByUser')
349
            ->With($user)
350
            ->will($this->returnValue($userSettings));
351
352
        $this->objectManager->expects($this->once())->method('flush');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\Persistence\ObjectManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
353
354
        $dates = [
355
            [$startDate, new DateTime("31 March 2014 23:59:59"), $bookedHours],
356
            [new DateTime("01 April 2014 00:00:00"), new DateTime("30 April 2014 23:59:59"), $bookedHours],
357
        ];
358
359
        $this->bookingRepositoryExpects($user, $dates);
360
        $this->evmExpects(array_column($dates, 1), $runningBalance, true, 0);
361
362
        $this->runningBalanceService->reIndexIndividualUserRunningBalance($user);
363
        $this->assertEquals($expectedBalance, $runningBalance->getBalance());
364
    }
365
366
    /**
367
     * @return array
368
     */
369
    public function singleUserStartDateProvider()
370
    {
371
        return [
372
            [
373
                'startingBalance'   => 0,
374
                'startDate'         => new DateTime("12-03-2014"),
375
                'expectedBalance'   => -270,
376
                'bookedHours'       => 0
377
            ],
378
            [
379
                'startingBalance'   => 10,
380
                'startDate'         => new DateTime("12-03-2014"),
381
                'expectedBalance'   => -260,
382
                'bookedHours'       => 0
383
            ],
384
        ];
385
    }
386
387
    public function testSetUserBalance()
388
    {
389
        $user = new User;
390
        $balance = 10;
391
392
        $userSettings = new UserSettings;
393
        $this->userSettingsRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...ngsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
394
            ->expects($this->once())
395
            ->method('findOneByUser')
396
            ->with($user)
397
            ->will($this->returnValue($userSettings));
398
399
        $this->objectManager->expects($this->once())->method('flush');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\Persistence\ObjectManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
400
        $this->runningBalanceService->setUserStartingBalance($user, $balance);
401
        $this->assertEquals(10, $userSettings->getStartingBalance());
402
    }
403
404
    /**
405
     * @param DateTime $userStartDate
406
     * @return array
407
     */
408
    private function getUser(DateTime $userStartDate)
409
    {
410
        $user = new User;
411
        $userSettings = new UserSettings;
412
        $userSettings->setFlexStartDate($userStartDate);
413
        return [$user, $userSettings];
414
    }
415
416
    /**
417
     * @param array $dates
418
     * @param RunningBalance $runningBalance
419
     * @param bool $addReindexPreAndPostEvents
420
     * @param int $invocationCount
421
     * @return int
422
     */
423
    private function evmExpects(
424
        array $dates,
425
        RunningBalance $runningBalance,
426
        $addReindexPreAndPostEvents = false,
427
        $invocationCount = 0
428
    ) {
429
430
        if ($addReindexPreAndPostEvents) {
431
            $this->evm
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Zend\EventManager\EventManagerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
432
                ->expects($this->at($invocationCount++))
433
                ->method('trigger')
434
                ->with(
435
                    'reIndexUserRunningBalance.pre',
436
                    null,
437
                    ['runningBalance' => $runningBalance]
438
                );
439
        }
440
441
        foreach ($dates as $date) {
442
            $this->evm
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Zend\EventManager\EventManagerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
443
                ->expects($this->at($invocationCount++))
444
                ->method('trigger')
445
                ->with(
446
                    'addMonthBalance.pre',
447
                    null,
448
                    ['runningBalance' => $runningBalance, 'month' => $date]
449
                );
450
451
            $this->evm
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Zend\EventManager\EventManagerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
452
                ->expects($this->at($invocationCount++))
453
                ->method('trigger')
454
                ->with(
455
                    'addMonthBalance.post',
456
                    null,
457
                    ['runningBalance' => $runningBalance, 'month' => $date]
458
                );
459
        }
460
461
        if ($addReindexPreAndPostEvents) {
462
            $this->evm
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Zend\EventManager\EventManagerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
463
                ->expects($this->at($invocationCount++))
464
                ->method('trigger')
465
                ->with(
466
                    'reIndexUserRunningBalance.post',
467
                    null,
468
                    ['runningBalance' => $runningBalance]
469
                );
470
        }
471
472
        return $invocationCount;
473
    }
474
475
    /**
476
     * @param UserInterface $user
477
     * @param array $months
478
     * @param int $invocationCount
479
     * @return int
480
     */
481
    private function bookingRepositoryExpects(UserInterface $user, array $months, $invocationCount = 0)
482
    {
483
        foreach ($months as $month) {
484
            list($start, $end, $bookedHours) = $month;
485
486
            $this->bookingRepository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repository\BookingRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
487
                ->expects($this->at($invocationCount++))
488
                ->method('getTotalBookedBetweenByUser')
489
                ->with(
490
                    $user,
491
                    $this->equalTo($start),
492
                    $this->equalTo($end)
493
                )
494
                ->will($this->returnValue($bookedHours));
495
        }
496
497
        return $invocationCount;
498
    }
499
}
500