Completed
Pull Request — develop (#28)
by Axel
03:58
created

FeedbackManagerTest::testGetFeedback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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
class FeedbackManagerTest extends \PHPUnit_Framework_TestCase {
12
    /** @var FeedbackManager **/
13
    protected $manager;
14
15
    public function setUp() {
16
        $this->manager = new FeedbackManager($this->getEntityManagerMock(), Feature::class);
17
    }
18
19
    public function testGetProjectFeedbacks() {
20
        $feedbacks = $this->manager->getProjectFeedbacks((new Project()));
21
22
        $this->assertCount(2, $feedbacks);
23
        $this->assertInstanceOf(Feedback::class, $feedbacks[0]);
24
        $this->assertEquals(2, $feedbacks[1]->getId());
25
    }
26
27
    public function testGetFeedback() {
28
        $feedback = $this->manager->getFeedback(1);
29
30
        $this->assertInstanceOf(Feedback::class, $feedback);
31
        $this->assertEquals(1, $feedback->getId());
32
    }
33
34
    /**
35
     * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
36
     * @expectedExceptionMessage Feedback not found
37
     */
38
    public function testGetFeedbackWithUnexistingFeedback() {
39
        $this->manager->getFeedback(2);
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\FeedbackRepository')
59
            ->disableOriginalConstructor()
60
            ->setMethods([
61
                'find',
62
                'findByProject'
63
            ])
64
            ->getMock()
65
        ;
66
        $repositoryMock
67
            ->expects($this->any())
68
            ->method('findByProject')
69
            ->willReturnCallback([$this, 'getFeedbacksMock'])
70
        ;
71
        $repositoryMock
72
            ->expects($this->any())
73
            ->method('find')
74
            ->willReturnCallback([$this, 'getFeedbackMock'])
75
        ;
76
        return $repositoryMock;
77
    }
78
79
    public function getFeedbackMock($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 Feedback())
85
            ->setId(1)
86
            ->setName('I can\'t see the calendar')
87
            ->setSlug('i-can-t-see-the-calendar')
88
            ->setDescription('Add brightness to this calendar !')
89
            ->setProject(new Project())
90
            ->setAuthor(new User())
91
            ->setDeveloper(new User())
92
            ->setCreatedAt(new \DateTime())
93
            ->setUpdatedAt(new \DateTime())
94
        ;
95
    }
96
97
    public function getFeedbacksMock() {
98
        return [
99
            (new Feedback())
100
            ->setId(1)
101
            ->setName('I can\'t see the calendar')
102
            ->setSlug('i-can-t-see-the-calendar')
103
            ->setDescription('Add brightness to this calendar !')
104
            ->setProject(new Project())
105
            ->setAuthor(new User())
106
            ->setDeveloper(new User())
107
            ->setCreatedAt(new \DateTime())
108
            ->setUpdatedAt(new \DateTime()),
109
            (new Feedback())
110
            ->setId(2)
111
            ->setName('The calendar is not shiny enough')
112
            ->setSlug('the-calendar-is-not-shiny-enough')
113
            ->setDescription('This calendar blew my eyes away !')
114
            ->setProject(new Project())
115
            ->setAuthor(new User())
116
            ->setDeveloper(new User())
117
            ->setCreatedAt(new \DateTime())
118
            ->setUpdatedAt(new \DateTime()),
119
        ];
120
    }
121
}
122