1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Repository; |
4
|
|
|
|
5
|
|
|
use JhFlexiTime\Repository\BalanceRepository; |
6
|
|
|
use JhFlexiTime\Entity\RunningBalance; |
7
|
|
|
use JhUser\Entity\User; |
8
|
|
|
use JhFlexiTimeTest\Util\ServiceManagerFactory; |
9
|
|
|
use JhFlexiTimeTest\Fixture\SingleRunningBalance; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class BalanceRepositoryTest |
13
|
|
|
* @package JhFlexiTimeTest\Repository |
14
|
|
|
* @author Aydin Hassan <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class BalanceRepositoryTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
protected $objectManager; |
20
|
|
|
protected $objectRepository; |
21
|
|
|
protected $balanceRepository; |
22
|
|
|
protected $repository; |
23
|
|
|
protected $fixtureExecutor; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->objectRepository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository'); |
28
|
|
|
$this->objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); |
29
|
|
|
|
30
|
|
|
$sm = ServiceManagerFactory::getServiceManager(); |
31
|
|
|
$this->repository = $sm->get('JhFlexiTime\Repository\BalanceRepository'); |
32
|
|
|
$this->fixtureExecutor = $sm->get('Doctrine\Common\DataFixtures\Executor\AbstractExecutor'); |
33
|
|
|
$this->assertInstanceOf('JhFlexiTime\Repository\BalanceRepository', $this->repository); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Test get running balance function |
38
|
|
|
*/ |
39
|
|
|
public function testGetRunningBalance() |
40
|
|
|
{ |
41
|
|
|
$this->balanceRepository = new BalanceRepository( |
42
|
|
|
$this->objectRepository, |
43
|
|
|
$this->objectManager |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$userMock = $this->getMock('ZfcUser\Entity\UserInterface'); |
47
|
|
|
$runningBalance = new RunningBalance(); |
48
|
|
|
|
49
|
|
|
$this->objectRepository->expects($this->once()) |
50
|
|
|
->method('findOneBy') |
51
|
|
|
->with(['user' => $userMock]) |
52
|
|
|
->will($this->returnValue($runningBalance)); |
53
|
|
|
|
54
|
|
|
$ret = $this->balanceRepository->findOneByUser($userMock); |
55
|
|
|
$this->assertSame($runningBalance, $ret); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testFindOneByReturnsNullIfNotExists() |
59
|
|
|
{ |
60
|
|
|
$this->assertNull($this->repository->findOneBy(["user" => 1])); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testFindOneByReturnsBalanceIfExists() |
64
|
|
|
{ |
65
|
|
|
$balance = new SingleRunningBalance(); |
66
|
|
|
$this->fixtureExecutor->execute([$balance]); |
67
|
|
|
$result = $this->repository->findOneBy(["user" => $balance->getBalance()->getUser()->getId()]); |
68
|
|
|
$this->assertInstanceOf('JhFlexiTime\Entity\RunningBalance', $result); |
69
|
|
|
$this->assertSame($balance->getBalance()->getUser()->getEmail(), $result->getUser()->getEmail()); |
70
|
|
|
$this->assertSame($balance->getBalance()->getBalance(), $result->getBalance()); |
71
|
|
|
$this->assertSame($balance->getBalance()->getId(), $result->getId()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|