Completed
Push — master ( cd6d5c...fa5688 )
by Axel
05:46 queued 03:12
created

testGetFeatureWithUnexistingFeature()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Developtech\AgilityBundle\Tests\Manager;
4
5
use Developtech\AgilityBundle\Manager\FeatureManager;
6
7
use Developtech\AgilityBundle\Tests\Mock\Feature;
8
use Developtech\AgilityBundle\Tests\Mock\User;
9
use Developtech\AgilityBundle\Tests\Mock\Project;
10
11
class FeatureManagerTest extends \PHPUnit_Framework_TestCase {
12
    protected $manager;
13
14
    public function setUp() {
15
        $this->manager = new FeatureManager($this->getEntityManagerMock(), Feature::class);
16
    }
17
18
    public function testGetFeature() {
19
        $feature = $this->manager->getFeature(1);
20
21
        $this->assertInstanceOf(Feature::class, $feature);
22
        $this->assertEquals(1, $feature->getId());
23
        $this->assertEquals('Calendar creation', $feature->getName());
24
    }
25
26
    /**
27
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
28
     * @expectedExceptionMessage Feature not found
29
     */
30
    public function testGetFeatureWithUnexistingFeature() {
31
        $this->manager->getFeature(2);
32
    }
33
34
    public function testGetProjectFeatures() {
35
        $features = $this->manager->getProjectFeatures((new Project()));
36
37
        $this->assertCount(3, $features);
38
        $this->assertInstanceOf(Feature::class, $features[0]);
39
        $this->assertEquals(2, $features[1]->getId());
40
    }
41
42
    public function getEntityManagerMock() {
43
        $entityManagerMock = $this
44
            ->getMockBuilder('Doctrine\ORM\EntityManager')
45
            ->disableOriginalConstructor()
46
            ->getMock()
47
        ;
48
        $entityManagerMock
49
            ->expects($this->any())
50
            ->method('getRepository')
51
            ->willReturnCallback([$this, 'getRepositoryMock'])
52
        ;
53
        return $entityManagerMock;
54
    }
55
56
    public function getRepositoryMock() {
57
        $repositoryMock = $this
58
            ->getMockBuilder('Developtech\AgilityBundle\Repository\FeatureRepository')
59
            ->disableOriginalConstructor()
60
            ->setMethods([
61
                'find',
62
                'findByProject'
63
            ])
64
            ->getMock()
65
        ;
66
        $repositoryMock
67
            ->expects($this->any())
68
            ->method('find')
69
            ->willReturnCallback([$this, 'getFeatureMock'])
70
        ;
71
        $repositoryMock
72
            ->expects($this->any())
73
            ->method('findByProject')
74
            ->willReturnCallback([$this, 'getFeaturesMock'])
75
        ;
76
        return $repositoryMock;
77
    }
78
79
    public function getFeatureMock($id) {
80
        if($id === 2) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
81
            return null;
82
        }
83
        return
84
            (new Feature())
85
            ->setId(1)
86
            ->setName('Calendar creation')
87
            ->setSlug('calendar-creation')
88
            ->setDescription('Create a new calendar')
89
            ->setProject(new Project())
90
            ->setDeveloper(new User())
91
            ->setCreatedAt(new \DateTime())
92
            ->setUpdatedAt(new \DateTime())
93
        ;
94
    }
95
96
    public function getFeaturesMock() {
97
        return [
98
            (new Feature())
99
            ->setId(1)
100
            ->setName('Calendar creation')
101
            ->setSlug('calendar-creation')
102
            ->setDescription('Create a new calendar')
103
            ->setProject(new Project())
104
            ->setDeveloper(new User())
105
            ->setCreatedAt(new \DateTime())
106
            ->setUpdatedAt(new \DateTime()),
107
            (new Feature())
108
            ->setId(2)
109
            ->setName('Calendar edition')
110
            ->setSlug('calendar-edition')
111
            ->setDescription('Edit an existing calendar')
112
            ->setProject(new Project())
113
            ->setDeveloper(new User())
114
            ->setCreatedAt(new \DateTime())
115
            ->setUpdatedAt(new \DateTime()),
116
            (new Feature())
117
            ->setId(3)
118
            ->setName('Calendar removal')
119
            ->setSlug('calendar-removal')
120
            ->setDescription('Remove an existing calendar')
121
            ->setProject(new Project())
122
            ->setDeveloper(new User())
123
            ->setCreatedAt(new \DateTime())
124
            ->setUpdatedAt(new \DateTime()),
125
        ];
126
    }
127
}
128