1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Repository; |
4
|
|
|
|
5
|
|
|
use JhFlexiTimeTest\Fixture\MultiUserBookedCredit; |
6
|
|
|
use JhUser\Entity\User; |
7
|
|
|
use JhFlexiTimeTest\Util\ServiceManagerFactory; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class BookedCreditRepositoryTest |
11
|
|
|
* @package JhFlexiTimeTest\Repository |
12
|
|
|
* @author Aydin Hassan <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class BookedCreditRepositoryTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
protected $objectManager; |
18
|
|
|
protected $objectRepository; |
19
|
|
|
protected $balanceRepository; |
20
|
|
|
protected $repository; |
21
|
|
|
protected $fixtureExecutor; |
22
|
|
|
protected $sl; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->objectRepository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository'); |
27
|
|
|
$this->objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); |
28
|
|
|
|
29
|
|
|
$this->sl = ServiceManagerFactory::getServiceManager(); |
30
|
|
|
$this->repository = $this->sl->get('JhFlexiTime\Repository\BookedCreditRepository'); |
31
|
|
|
$this->fixtureExecutor = $this->sl->get('Doctrine\Common\DataFixtures\Executor\AbstractExecutor'); |
32
|
|
|
$this->assertInstanceOf('JhFlexiTime\Repository\BookedCreditRepository', $this->repository); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testFindAllByUser() |
36
|
|
|
{ |
37
|
|
|
$user = new User; |
38
|
|
|
$user->setEmail('[email protected]')->setPassword("password"); |
39
|
|
|
$fixture = new MultiUserBookedCredit($user); |
40
|
|
|
$this->fixtureExecutor->execute([$fixture]); |
41
|
|
|
|
42
|
|
|
$records = $this->repository->findAllByUser($user); |
43
|
|
|
$this->assertSame(count($fixture->getUserRecords()), count($records)); |
44
|
|
|
|
45
|
|
|
foreach ($records as $record) { |
46
|
|
|
$this->assertEquals($record->getUser()->getId(), $user->getId()); |
47
|
|
|
$this->assertEquals($record->getUser()->getEmail(), $user->getEmail()); |
48
|
|
|
$this->assertEquals($record->getAmount(), 10); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testFindAllByUserPaginated() |
53
|
|
|
{ |
54
|
|
|
$user = new User; |
55
|
|
|
$user->setEmail('[email protected]')->setPassword("password"); |
56
|
|
|
$fixture = new MultiUserBookedCredit($user); |
57
|
|
|
$this->fixtureExecutor->execute([$fixture]); |
58
|
|
|
|
59
|
|
|
$records = $this->repository->findAllByUser($user, true); |
60
|
|
|
$this->assertSame($records->count(), count($records)); |
61
|
|
|
|
62
|
|
|
$this->assertInstanceOf('Zend\Paginator\Paginator', $records); |
63
|
|
|
foreach ($records as $record) { |
64
|
|
|
$this->assertEquals($record->getUser()->getId(), $user->getId()); |
65
|
|
|
$this->assertEquals($record->getUser()->getEmail(), $user->getEmail()); |
66
|
|
|
$this->assertEquals($record->getAmount(), 10); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|