1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2017 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* @license GPL-3.0 |
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Addiks\SymfonyGenerics\Tests\Unit\Controllers; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\SymfonyGenerics\Controllers\GenericEntityRemoveController; |
15
|
|
|
use Addiks\SymfonyGenerics\Controllers\ControllerHelperInterface; |
16
|
|
|
use stdClass; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
use InvalidArgumentException; |
19
|
|
|
|
20
|
|
|
final class GenericEntityRemoveControllerTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var GenericEntityRemoveController |
25
|
|
|
*/ |
26
|
|
|
private $controller; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ControllerHelperInterface |
30
|
|
|
*/ |
31
|
|
|
private $controllerHelper; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->controllerHelper = $this->createMock(ControllerHelperInterface::class); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$this->controller = new GenericEntityRemoveController($this->controllerHelper, [ |
|
|
|
|
38
|
|
|
'entity-class' => stdClass::class |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
*/ |
45
|
|
|
public function shouldRejectMissingEntityClass() |
46
|
|
|
{ |
47
|
|
|
$this->expectException(InvalidArgumentException::class); |
48
|
|
|
|
49
|
|
|
new GenericEntityRemoveController($this->controllerHelper, []); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
*/ |
55
|
|
|
public function shouldRejectControllerCalledAgain() |
56
|
|
|
{ |
57
|
|
|
$this->expectException(InvalidArgumentException::class); |
58
|
|
|
|
59
|
|
|
$this->controller->__construct($this->controllerHelper, [ |
60
|
|
|
'entity-class' => stdClass::class |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @test |
66
|
|
|
*/ |
67
|
|
|
public function shouldThrowExceptionIfEntityNotFound() |
68
|
|
|
{ |
69
|
|
|
$this->expectException(InvalidArgumentException::class); |
70
|
|
|
|
71
|
|
|
$this->controller->removeEntity("some-id"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @test |
76
|
|
|
*/ |
77
|
|
|
public function shouldRemoveEntity() |
78
|
|
|
{ |
79
|
|
|
$entity = new stdClass(); |
80
|
|
|
|
81
|
|
|
$this->controllerHelper->expects($this->once())->method('findEntity')->with( |
|
|
|
|
82
|
|
|
$this->equalTo(stdClass::class), |
83
|
|
|
$this->equalTo('some-id') |
84
|
|
|
)->willReturn($entity); |
85
|
|
|
|
86
|
|
|
$this->controllerHelper->expects($this->once())->method('removeEntity')->with( |
|
|
|
|
87
|
|
|
$this->identicalTo($entity) |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
/** @var Response $response */ |
91
|
|
|
$response = $this->controller->removeEntity("some-id"); |
92
|
|
|
|
93
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
94
|
|
|
$this->assertEquals('Entity removed!', $response->getContent()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..