CappedCreditRepositoryTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 78
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testFindAllByUser() 0 16 2
A tesGetTotalCappedCreditByUser() 0 9 1
A testDeleteAllByUser() 0 14 1
A testDeleteAll() 0 14 1
1
<?php
2
3
namespace JhFlexiTimeTest\Repository;
4
5
use JhFlexiTimeTest\Fixture\MultiUserCreditCaps;
6
use JhUser\Entity\User;
7
use JhFlexiTimeTest\Util\ServiceManagerFactory;
8
9
/**
10
 * Class CappedCreditRepositoryTest
11
 * @package JhFlexiTimeTest\Repository
12
 * @author Aydin Hassan <[email protected]>
13
 */
14
class CappedCreditRepositoryTest 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\CappedCreditRepository');
31
        $this->fixtureExecutor  = $this->sl->get('Doctrine\Common\DataFixtures\Executor\AbstractExecutor');
32
        $this->assertInstanceOf('JhFlexiTime\Repository\CappedCreditRepository', $this->repository);
33
    }
34
35
    public function testFindAllByUser()
36
    {
37
        $user = new User;
38
        $user->setEmail('[email protected]')->setPassword("password");
39
        $fixture = new MultiUserCreditCaps($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->getCappedCredit(), 10);
49
        }
50
    }
51
52
    public function tesGetTotalCappedCreditByUser()
53
    {
54
        $user = new User;
55
        $user->setEmail('[email protected]')->setPassword("password");
56
        $fixture = new MultiUserCreditCaps($user);
57
        $this->fixtureExecutor->execute([$fixture]);
58
59
        $this->assertEquals(100, $this->repository->getTotalCappedCreditByUser($user));
60
    }
61
62
    public function testDeleteAllByUser()
63
    {
64
        $user = new User;
65
        $user->setEmail('[email protected]')->setPassword("password");
66
        $fixture = new MultiUserCreditCaps($user);
67
        $this->fixtureExecutor->execute([$fixture]);
68
69
        $this->repository->deleteAllByUser($user);
70
71
        $this->assertEquals(0, $this->repository->getTotalCappedCreditByUser($user));
72
        $this->assertCount(0, $this->repository->findAllByUser($user));
73
        $this->assertEquals(100, $this->repository->getTotalCappedCreditByUser($fixture->getUser2()));
74
        $this->assertCount(10, $this->repository->findAllByUser($fixture->getUser2()));
75
    }
76
77
    public function testDeleteAll()
78
    {
79
        $user = new User;
80
        $user->setEmail('[email protected]')->setPassword("password");
81
        $fixture = new MultiUserCreditCaps($user);
82
        $this->fixtureExecutor->execute([$fixture]);
83
84
        $this->repository->deleteAll();
85
86
        $this->assertEquals(0, $this->repository->getTotalCappedCreditByUser($user));
87
        $this->assertCount(0, $this->repository->findAllByUser($user));
88
        $this->assertEquals(0, $this->repository->getTotalCappedCreditByUser($fixture->getUser2()));
89
        $this->assertCount(0, $this->repository->findAllByUser($fixture->getUser2()));
90
    }
91
}
92