1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Developtech\AgilityBundle\Tests\Manager; |
4
|
|
|
|
5
|
|
|
use Developtech\AgilityBundle\Manager\ProjectManager; |
6
|
|
|
|
7
|
|
|
use Developtech\AgilityBundle\Tests\Mock\Project; |
8
|
|
|
use Developtech\AgilityBundle\Tests\Mock\User; |
9
|
|
|
|
10
|
|
|
use Developtech\AgilityBundle\Utils\Slugger; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
13
|
|
|
|
14
|
|
|
class ProjectManagerTest extends \PHPUnit_Framework_TestCase { |
15
|
|
|
/** @var ProjectManager **/ |
16
|
|
|
protected $manager; |
17
|
|
|
|
18
|
|
|
public function setUp() { |
19
|
|
|
$this->manager = new ProjectManager($this->getEntityManagerMock(), new Slugger(), Project::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testGetProjects() { |
23
|
|
|
$projects = $this->manager->getProjects(); |
24
|
|
|
|
25
|
|
|
$this->assertCount(3, $projects); |
26
|
|
|
$this->assertInstanceOf(Project::class, $projects[0]); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetProject() { |
30
|
|
|
$project = $this->manager->getProject('great-project'); |
31
|
|
|
|
32
|
|
|
$this->assertInstanceOf(Project::class, $project); |
33
|
|
|
$this->assertEquals(3, $project->getId()); |
34
|
|
|
$this->assertEquals('Great project', $project->getName()); |
35
|
|
|
$this->assertEquals('great-project', $project->getSlug()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testCreateProject() { |
39
|
|
|
$project = $this->manager->createProject('Great project', new User()); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(Project::class, $project); |
42
|
|
|
$this->assertEquals('Great project', $project->getName()); |
43
|
|
|
$this->assertEquals('great-project', $project->getSlug()); |
44
|
|
|
$this->assertInstanceOf(User::class, $project->getProductOwner()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testEditProject() { |
48
|
|
|
$project = $this->manager->editProject(3, 'Updated project', 'open', 10); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf(Project::class, $project); |
51
|
|
|
$this->assertEquals(3, $project->getId()); |
52
|
|
|
$this->assertEquals('Updated project', $project->getName()); |
53
|
|
|
$this->assertEquals('updated-project', $project->getSlug()); |
54
|
|
|
$this->assertEquals('open', $project->getBetaTestStatus()); |
55
|
|
|
$this->assertEquals(10, $project->getNbBetaTesters()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
60
|
|
|
* @expectedExceptionMessage Project not found |
61
|
|
|
*/ |
62
|
|
|
public function testEditProjectWithUnexistingProject() { |
63
|
|
|
$this->manager->editProject(2, 'Unknown project', 'closed', 0); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getEntityManagerMock() { |
67
|
|
|
$entityManagerMock = $this |
68
|
|
|
->getMockBuilder('Doctrine\ORM\EntityManager') |
69
|
|
|
->disableOriginalConstructor() |
70
|
|
|
->getMock() |
71
|
|
|
; |
72
|
|
|
$entityManagerMock |
73
|
|
|
->expects($this->any()) |
74
|
|
|
->method('getRepository') |
75
|
|
|
->willReturnCallback([$this, 'getRepositoryMock']) |
76
|
|
|
; |
77
|
|
|
$entityManagerMock |
78
|
|
|
->expects($this->any()) |
79
|
|
|
->method('persist') |
80
|
|
|
->willReturn(true) |
81
|
|
|
; |
82
|
|
|
$entityManagerMock |
83
|
|
|
->expects($this->any()) |
84
|
|
|
->method('flush') |
85
|
|
|
->willReturn(true) |
86
|
|
|
; |
87
|
|
|
return $entityManagerMock; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getRepositoryMock() { |
91
|
|
|
$repositoryMock = $this |
92
|
|
|
->getMockBuilder('Developtech\AgilityBundle\Repository\ProjectRepository') |
93
|
|
|
->disableOriginalConstructor() |
94
|
|
|
->setMethods([ |
95
|
|
|
'find', |
96
|
|
|
'findOneBySlug', |
97
|
|
|
'findAll' |
98
|
|
|
]) |
99
|
|
|
->getMock() |
100
|
|
|
; |
101
|
|
|
$repositoryMock |
102
|
|
|
->expects($this->any()) |
103
|
|
|
->method('find') |
104
|
|
|
->willReturnCallback([$this, 'getProjectMock']) |
105
|
|
|
; |
106
|
|
|
$repositoryMock |
107
|
|
|
->expects($this->any()) |
108
|
|
|
->method('findOneBySlug') |
109
|
|
|
->willReturnCallback([$this, 'getProjectMock']) |
110
|
|
|
; |
111
|
|
|
$repositoryMock |
112
|
|
|
->expects($this->any()) |
113
|
|
|
->method('findAll') |
114
|
|
|
->willReturnCallback([$this, 'getProjectsMock']) |
115
|
|
|
; |
116
|
|
|
return $repositoryMock; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param mixed $id |
121
|
|
|
* @return Project|null |
122
|
|
|
*/ |
123
|
|
|
public function getProjectMock($id) { |
124
|
|
|
if($id === 2) { |
|
|
|
|
125
|
|
|
return null; |
126
|
|
|
} |
127
|
|
|
return |
128
|
|
|
(new Project()) |
129
|
|
|
->setId(3) |
130
|
|
|
->setName('Great project') |
131
|
|
|
->setSlug('great-project') |
132
|
|
|
->setCreatedAt(new \DateTime()) |
133
|
|
|
->setNbBetaTesters(12) |
134
|
|
|
->setBetaTestStatus('open') |
135
|
|
|
->setProductOwner(new \StdClass) |
136
|
|
|
; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getProjectsMock() { |
140
|
|
|
return [ |
141
|
|
|
(new Project()) |
142
|
|
|
->setName('Great Project') |
143
|
|
|
->setSlug('great-project') |
144
|
|
|
->setCreatedAt(new \DateTime()) |
145
|
|
|
->setNbBetaTesters(12) |
146
|
|
|
->setBetaTestStatus('open'), |
147
|
|
|
(new Project()) |
148
|
|
|
->setName('Bloody Project') |
149
|
|
|
->setSlug('bloody-project') |
150
|
|
|
->setCreatedAt(new \DateTime()) |
151
|
|
|
->setNbBetaTesters(17) |
152
|
|
|
->setBetaTestStatus('closed'), |
153
|
|
|
(new Project()) |
154
|
|
|
->setName('Messy Project') |
155
|
|
|
->setSlug('messy-project') |
156
|
|
|
->setCreatedAt(new \DateTime()) |
157
|
|
|
->setNbBetaTesters(24) |
158
|
|
|
->setBetaTestStatus('closed'), |
159
|
|
|
]; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|