CappedCreditServiceTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testCreate() 0 13 1
A testSave() 0 18 1
A testClearCappedCreditEntries() 0 11 1
1
<?php
2
3
namespace JhFlexiTimeTest\Service;
4
5
use JhFlexiTime\DateTime\DateTime;
6
use JhFlexiTime\Entity\CappedCredit;
7
use JhFlexiTime\Service\CappedCreditService;
8
use JhUser\Entity\User;
9
use PHPUnit_Framework_TestCase;
10
11
/**
12
 * Class CappedCreditServiceTest
13
 * @package JhFlexiTimeTest\Service
14
 * @author  Aydin Hassan <[email protected]>
15
 */
16
class CappedCreditServiceTest extends PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var CappedCreditService
20
     */
21
    protected $service;
22
23
    /**
24
     * @var \JhFlexiTime\Repository\CappedCreditRepositoryInterface
25
     */
26
    protected $repository;
27
28
    /**
29
     * @var
30
     */
31
    protected $objectManager;
32
33
    public function setUp()
34
    {
35
        $this->repository       = $this->getMock('JhFlexiTime\Repository\CappedCreditRepositoryInterface');
36
        $this->objectManager    = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
37
        $this->service          = new CappedCreditService($this->repository, $this->objectManager);
38
    }
39
40
    public function testCreate()
41
    {
42
        $this->objectManager
43
            ->expects($this->once())
44
            ->method('persist')
45
            ->with($this->isInstanceOf('\JhFlexiTime\Entity\CappedCredit'));
46
47
        $this->objectManager
48
            ->expects($this->once())
49
            ->method('flush');
50
51
        $this->service->create(new User, 100, new DateTime('10 October 2014'));
52
    }
53
54
    public function testSave()
55
    {
56
        $this->objectManager
57
            ->expects($this->once())
58
            ->method('persist')
59
            ->with($this->isInstanceOf('\JhFlexiTime\Entity\CappedCredit'));
60
61
        $this->objectManager
62
            ->expects($this->once())
63
            ->method('flush');
64
65
        $capped = new CappedCredit;
66
        $capped->setDate(new DateTime('10 October 2014'));
67
        $capped->setUser(new User);
68
        $capped->setCappedCredit(100);
69
70
        $this->service->save($capped);
71
    }
72
73
    public function testClearCappedCreditEntries()
74
    {
75
        $user = new User;
76
77
        $this->repository
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JhFlexiTime\Repos...ditRepositoryInterface>.

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...
78
            ->expects($this->once())
79
            ->method('deleteAllByUser')
80
            ->with($user);
81
82
        $this->service->clearCappedCreditEntries($user);
83
    }
84
}
85