Completed
Push — master ( fa5688...b322d1 )
by Axel
05:31 queued 02:55
created

testCreateProductOwnerFeature()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 1
eloc 14
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
use Developtech\AgilityBundle\Utils\Slugger;
12
13
class FeatureManagerTest extends \PHPUnit_Framework_TestCase {
14
    /** @var FeatureManager **/
15
    protected $manager;
16
17
    public function setUp() {
18
        $this->manager = new FeatureManager($this->getEntityManagerMock(), new Slugger(), Feature::class);
19
    }
20
21
    public function testGetFeature() {
22
        $feature = $this->manager->getFeature(1);
23
24
        $this->assertInstanceOf(Feature::class, $feature);
25
        $this->assertEquals(1, $feature->getId());
26
        $this->assertEquals('Calendar creation', $feature->getName());
27
    }
28
29
    /**
30
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
31
     * @expectedExceptionMessage Feature not found
32
     */
33
    public function testGetFeatureWithUnexistingFeature() {
34
        $this->manager->getFeature(2);
35
    }
36
37
    public function testGetProjectFeatures() {
38
        $features = $this->manager->getProjectFeatures((new Project()));
39
40
        $this->assertCount(3, $features);
41
        $this->assertInstanceOf(Feature::class, $features[0]);
42
        $this->assertEquals(2, $features[1]->getId());
43
    }
44
45
    public function testCreateProductOwnerFeature() {
46
        $feature = $this->manager->createProductOwnerFeature(
47
            (new Project()),
48
            'Todo list',
49
            'List of all the remaining actions to perform',
50
            Feature::STATUS_READY,
51
            95
52
        );
53
        $this->assertInstanceOf(Feature::class, $feature);
54
        $this->assertInstanceOf(Project::class, $feature->getProject());
55
        $this->assertEquals('Todo list', $feature->getName());
56
        $this->assertEquals('todo-list', $feature->getSlug());
57
        $this->assertEquals('List of all the remaining actions to perform', $feature->getDescription());
58
        $this->assertEquals(Feature::STATUS_READY, $feature->getStatus());
59
        $this->assertEquals(95, $feature->getProductOwnerValue());
60
    }
61
62
    public function getEntityManagerMock() {
63
        $entityManagerMock = $this
64
            ->getMockBuilder('Doctrine\ORM\EntityManager')
65
            ->disableOriginalConstructor()
66
            ->getMock()
67
        ;
68
        $entityManagerMock
69
            ->expects($this->any())
70
            ->method('getRepository')
71
            ->willReturnCallback([$this, 'getRepositoryMock'])
72
        ;
73
        $entityManagerMock
74
            ->expects($this->any())
75
            ->method('persist')
76
            ->willReturn(true)
77
        ;
78
        $entityManagerMock
79
            ->expects($this->any())
80
            ->method('flush')
81
            ->willReturn(true)
82
        ;
83
        return $entityManagerMock;
84
    }
85
86
    public function getRepositoryMock() {
87
        $repositoryMock = $this
88
            ->getMockBuilder('Developtech\AgilityBundle\Repository\FeatureRepository')
89
            ->disableOriginalConstructor()
90
            ->setMethods([
91
                'find',
92
                'findByProject'
93
            ])
94
            ->getMock()
95
        ;
96
        $repositoryMock
97
            ->expects($this->any())
98
            ->method('find')
99
            ->willReturnCallback([$this, 'getFeatureMock'])
100
        ;
101
        $repositoryMock
102
            ->expects($this->any())
103
            ->method('findByProject')
104
            ->willReturnCallback([$this, 'getFeaturesMock'])
105
        ;
106
        return $repositoryMock;
107
    }
108
109
    public function getFeatureMock($id) {
110
        if($id === 2) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
111
            return null;
112
        }
113
        return
114
            (new Feature())
115
            ->setId(1)
116
            ->setName('Calendar creation')
117
            ->setSlug('calendar-creation')
118
            ->setDescription('Create a new calendar')
119
            ->setProject(new Project())
120
            ->setDeveloper(new User())
121
            ->setCreatedAt(new \DateTime())
122
            ->setUpdatedAt(new \DateTime())
123
        ;
124
    }
125
126
    public function getFeaturesMock() {
127
        return [
128
            (new Feature())
129
            ->setId(1)
130
            ->setName('Calendar creation')
131
            ->setSlug('calendar-creation')
132
            ->setDescription('Create a new calendar')
133
            ->setProject(new Project())
134
            ->setDeveloper(new User())
135
            ->setCreatedAt(new \DateTime())
136
            ->setUpdatedAt(new \DateTime()),
137
            (new Feature())
138
            ->setId(2)
139
            ->setName('Calendar edition')
140
            ->setSlug('calendar-edition')
141
            ->setDescription('Edit an existing calendar')
142
            ->setProject(new Project())
143
            ->setDeveloper(new User())
144
            ->setCreatedAt(new \DateTime())
145
            ->setUpdatedAt(new \DateTime()),
146
            (new Feature())
147
            ->setId(3)
148
            ->setName('Calendar removal')
149
            ->setSlug('calendar-removal')
150
            ->setDescription('Remove an existing calendar')
151
            ->setProject(new Project())
152
            ->setDeveloper(new User())
153
            ->setCreatedAt(new \DateTime())
154
            ->setUpdatedAt(new \DateTime()),
155
        ];
156
    }
157
}
158