1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) 2017 Michael Giesler |
3
|
|
|
* |
4
|
|
|
* This file is part of Dembelo. |
5
|
|
|
* |
6
|
|
|
* Dembelo is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* Dembelo is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Affero General Public License 3 for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Affero General Public License 3 |
17
|
|
|
* along with Dembelo. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace AdminBundle\Tests\Controller; |
21
|
|
|
|
22
|
|
|
use AdminBundle\Controller\LicenseeController; |
23
|
|
|
use DembeloMain\Document\Licensee; |
24
|
|
|
use DembeloMain\Model\Repository\Doctrine\ODM\LicenseeRepository; |
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
26
|
|
|
use Symfony\Component\HttpFoundation\Response; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class LicenseeControllerTest |
30
|
|
|
*/ |
31
|
|
|
class LicenseeControllerTest extends WebTestCase |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var LicenseeController |
35
|
|
|
*/ |
36
|
|
|
private $controller; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|LicenseeRepository |
40
|
|
|
*/ |
41
|
|
|
private $licenseeRepositoryMock; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
protected function setUp(): void |
47
|
|
|
{ |
48
|
|
|
$this->licenseeRepositoryMock = $this->createLicenseeRepositoryMock(); |
49
|
|
|
|
50
|
|
|
$this->controller = new LicenseeController($this->licenseeRepositoryMock); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* tests licenseeAction with no licensees |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function testLicenseeActionWithNoLicensees(): void |
58
|
|
|
{ |
59
|
|
|
$this->licenseeRepositoryMock->expects($this->once()) |
|
|
|
|
60
|
|
|
->method('findAll') |
61
|
|
|
->willReturn([]); |
62
|
|
|
|
63
|
|
|
/* @var $response \Symfony\Component\HttpFoundation\Response */ |
64
|
|
|
$response = $this->controller->licenseesAction(); |
65
|
|
|
$this->assertInstanceOf(Response::class, $response); |
66
|
|
|
$this->assertJsonStringEqualsJsonString('[]', $response->getContent()); |
67
|
|
|
$this->assertEquals('200', $response->getStatusCode()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* tests licenseeAction() with one licensee |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
public function testLicenseeActionWithOneLicensee(): void |
75
|
|
|
{ |
76
|
|
|
$licensee = new Licensee(); |
77
|
|
|
$licensee->setName('someName'); |
78
|
|
|
$licensee->setId('someId'); |
79
|
|
|
|
80
|
|
|
$this->licenseeRepositoryMock->expects($this->once()) |
|
|
|
|
81
|
|
|
->method('findAll') |
82
|
|
|
->willReturn([$licensee]); |
83
|
|
|
|
84
|
|
|
/* @var $response \Symfony\Component\HttpFoundation\Response */ |
85
|
|
|
$response = $this->controller->licenseesAction(); |
86
|
|
|
$this->assertInstanceOf(Response::class, $response); |
87
|
|
|
$this->assertJsonStringEqualsJsonString('[{"id":"someId","name":"someName"}]', $response->getContent()); |
88
|
|
|
$this->assertEquals('200', $response->getStatusCode()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|LicenseeRepository |
93
|
|
|
*/ |
94
|
|
|
private function createLicenseeRepositoryMock(): LicenseeRepository |
95
|
|
|
{ |
96
|
|
|
$repository = $this->getMockBuilder(LicenseeRepository::class) |
97
|
|
|
->disableOriginalConstructor() |
98
|
|
|
->setMethods(['findAll', 'save', 'find', 'findBy', 'findOneBy', 'getClassName', 'findOneByName']) |
99
|
|
|
->getMock(); |
100
|
|
|
|
101
|
|
|
return $repository; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.