BalanceRepositoryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 58
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testGetRunningBalance() 0 18 1
A testFindOneByReturnsNullIfNotExists() 0 4 1
A testFindOneByReturnsBalanceIfExists() 0 10 1
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