1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Developtech\AgilityBundle\Tests\Manager; |
4
|
|
|
|
5
|
|
|
use Developtech\AgilityBundle\Manager\FeedbackManager; |
6
|
|
|
|
7
|
|
|
use Developtech\AgilityBundle\Tests\Mock\Feedback; |
8
|
|
|
use Developtech\AgilityBundle\Tests\Mock\User; |
9
|
|
|
use Developtech\AgilityBundle\Tests\Mock\Project; |
10
|
|
|
|
11
|
|
|
use Developtech\AgilityBundle\Utils\Slugger; |
12
|
|
|
|
13
|
|
|
class FeedbackManagerTest extends \PHPUnit_Framework_TestCase { |
14
|
|
|
/** @var FeedbackManager **/ |
15
|
|
|
protected $manager; |
16
|
|
|
|
17
|
|
|
public function setUp() { |
18
|
|
|
$this->manager = new FeedbackManager($this->getEntityManagerMock(), new Slugger(), Feedback::class); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testGetProjectFeedbacks() { |
22
|
|
|
$feedbacks = $this->manager->getProjectFeedbacks((new Project())); |
23
|
|
|
|
24
|
|
|
$this->assertCount(2, $feedbacks); |
25
|
|
|
$this->assertInstanceOf(Feedback::class, $feedbacks[0]); |
26
|
|
|
$this->assertEquals(2, $feedbacks[1]->getId()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetFeedback() { |
30
|
|
|
$feedback = $this->manager->getFeedback(1); |
31
|
|
|
|
32
|
|
|
$this->assertInstanceOf(Feedback::class, $feedback); |
33
|
|
|
$this->assertEquals(1, $feedback->getId()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
38
|
|
|
* @expectedExceptionMessage Feedback not found |
39
|
|
|
*/ |
40
|
|
|
public function testGetFeedbackWithUnexistingFeedback() { |
41
|
|
|
$this->manager->getFeedback(2); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testCreateFeedback() { |
45
|
|
|
$feedback = $this->manager->createFeedback( |
46
|
|
|
(new Project()), |
47
|
|
|
'There is a bug in the kitchen', |
48
|
|
|
'The fridge is hotter than my computer !', |
49
|
|
|
(new User()) |
50
|
|
|
); |
51
|
|
|
$this->assertInstanceOf(Feedback::class, $feedback); |
52
|
|
|
$this->assertInstanceOf(Project::class, $feedback->getProject()); |
53
|
|
|
$this->assertEquals('There is a bug in the kitchen', $feedback->getName()); |
54
|
|
|
$this->assertEquals('there-is-a-bug-in-the-kitchen', $feedback->getSlug()); |
55
|
|
|
$this->assertEquals('The fridge is hotter than my computer !', $feedback->getDescription()); |
56
|
|
|
$this->assertInstanceOf(User::class, $feedback->getAuthor()); |
57
|
|
|
$this->assertEquals(Feedback::STATUS_OPEN, $feedback->getStatus()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getEntityManagerMock() { |
61
|
|
|
$entityManagerMock = $this |
62
|
|
|
->getMockBuilder('Doctrine\ORM\EntityManager') |
63
|
|
|
->disableOriginalConstructor() |
64
|
|
|
->getMock() |
65
|
|
|
; |
66
|
|
|
$entityManagerMock |
67
|
|
|
->expects($this->any()) |
68
|
|
|
->method('getRepository') |
69
|
|
|
->willReturnCallback([$this, 'getRepositoryMock']) |
70
|
|
|
; |
71
|
|
|
$entityManagerMock |
72
|
|
|
->expects($this->any()) |
73
|
|
|
->method('persist') |
74
|
|
|
->willReturn(true) |
75
|
|
|
; |
76
|
|
|
$entityManagerMock |
77
|
|
|
->expects($this->any()) |
78
|
|
|
->method('flush') |
79
|
|
|
->willReturn(true) |
80
|
|
|
; |
81
|
|
|
return $entityManagerMock; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getRepositoryMock() { |
85
|
|
|
$repositoryMock = $this |
86
|
|
|
->getMockBuilder('Developtech\AgilityBundle\Repository\FeedbackRepository') |
87
|
|
|
->disableOriginalConstructor() |
88
|
|
|
->setMethods([ |
89
|
|
|
'find', |
90
|
|
|
'findByProject' |
91
|
|
|
]) |
92
|
|
|
->getMock() |
93
|
|
|
; |
94
|
|
|
$repositoryMock |
95
|
|
|
->expects($this->any()) |
96
|
|
|
->method('findByProject') |
97
|
|
|
->willReturnCallback([$this, 'getFeedbacksMock']) |
98
|
|
|
; |
99
|
|
|
$repositoryMock |
100
|
|
|
->expects($this->any()) |
101
|
|
|
->method('find') |
102
|
|
|
->willReturnCallback([$this, 'getFeedbackMock']) |
103
|
|
|
; |
104
|
|
|
return $repositoryMock; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getFeedbackMock($id) { |
108
|
|
|
if($id === 2) { |
|
|
|
|
109
|
|
|
return null; |
110
|
|
|
} |
111
|
|
|
return |
112
|
|
|
(new Feedback()) |
113
|
|
|
->setId(1) |
114
|
|
|
->setName('I can\'t see the calendar') |
115
|
|
|
->setSlug('i-can-t-see-the-calendar') |
116
|
|
|
->setDescription('Add brightness to this calendar !') |
117
|
|
|
->setProject(new Project()) |
118
|
|
|
->setAuthor(new User()) |
119
|
|
|
->setDeveloper(new User()) |
120
|
|
|
->setCreatedAt(new \DateTime()) |
121
|
|
|
->setUpdatedAt(new \DateTime()) |
122
|
|
|
; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getFeedbacksMock() { |
126
|
|
|
return [ |
127
|
|
|
(new Feedback()) |
128
|
|
|
->setId(1) |
129
|
|
|
->setName('I can\'t see the calendar') |
130
|
|
|
->setSlug('i-can-t-see-the-calendar') |
131
|
|
|
->setDescription('Add brightness to this calendar !') |
132
|
|
|
->setProject(new Project()) |
133
|
|
|
->setAuthor(new User()) |
134
|
|
|
->setDeveloper(new User()) |
135
|
|
|
->setCreatedAt(new \DateTime()) |
136
|
|
|
->setUpdatedAt(new \DateTime()), |
137
|
|
|
(new Feedback()) |
138
|
|
|
->setId(2) |
139
|
|
|
->setName('The calendar is not shiny enough') |
140
|
|
|
->setSlug('the-calendar-is-not-shiny-enough') |
141
|
|
|
->setDescription('This calendar blew my eyes away !') |
142
|
|
|
->setProject(new Project()) |
143
|
|
|
->setAuthor(new User()) |
144
|
|
|
->setDeveloper(new User()) |
145
|
|
|
->setCreatedAt(new \DateTime()) |
146
|
|
|
->setUpdatedAt(new \DateTime()), |
147
|
|
|
]; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|