1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Symfony-Util package. |
5
|
|
|
* |
6
|
|
|
* (c) Jean-Bernard Addor |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
use SymfonyUtil\Component\HttpFoundation\NullControllerModel; |
17
|
|
|
|
18
|
|
|
// use SymfonyUtil\Component\HttpFoundation\ResponseParameters; // used in string use ::class in php 7.1 symfony 4.0 version |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @covers \SymfonyUtil\Component\HttpFoundation\NullControllerModel |
22
|
|
|
*/ |
23
|
|
|
final class NullControllerModelTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
public function testCanBeCreated() |
26
|
|
|
{ |
27
|
|
|
$this->assertInstanceOf( |
28
|
|
|
// ::class, // 5.4 < php |
29
|
|
|
'SymfonyUtil\Component\HttpFoundation\NullControllerModel', |
30
|
|
|
new NullControllerModel() |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testCanBeCreatedWithOptionalResponse() |
35
|
|
|
{ |
36
|
|
|
$this->assertInstanceOf( |
37
|
|
|
// ::class, // 5.4 < php |
38
|
|
|
'SymfonyUtil\Component\HttpFoundation\NullControllerModel', |
39
|
|
|
new NullControllerModel(new Response()) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testRedirectResponseCanBeCreated() |
44
|
|
|
{ |
45
|
|
|
$this->assertInstanceOf( |
46
|
|
|
// ::class, // 5.4 < php |
47
|
|
|
'SymfonyUtil\Component\HttpFoundation\NullControllerModel', |
48
|
|
|
new NullControllerModel(new RedirectResponse('http://example.org/')) // Redirect example |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testRequestReturnsResponseParameters() |
53
|
|
|
{ |
54
|
|
|
$this->assertInstanceOf( |
55
|
|
|
// ::class, // 5.4 < php |
56
|
|
|
'SymfonyUtil\Component\HttpFoundation\ResponseParameters', |
57
|
|
|
(new NullControllerModel())->__invoke(new Request()) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testReturnsResponseParameters() |
62
|
|
|
{ |
63
|
|
|
$this->assertInstanceOf( |
64
|
|
|
// ::class, // 5.4 < php |
65
|
|
|
'SymfonyUtil\Component\HttpFoundation\ResponseParameters', |
66
|
|
|
(new NullControllerModel())->__invoke() |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testRequestReturnsResponseParametersWithOptionalResponse() |
71
|
|
|
{ |
72
|
|
|
$this->assertInstanceOf( |
73
|
|
|
// ::class, // 5.4 < php |
74
|
|
|
'SymfonyUtil\Component\HttpFoundation\ResponseParameters', |
75
|
|
|
(new NullControllerModel(new Response()))->__invoke(new Request()) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testReturnsResponseParametersWithOptionalResponse() |
80
|
|
|
{ |
81
|
|
|
$this->assertInstanceOf( |
82
|
|
|
// ::class, // 5.4 < php |
83
|
|
|
'SymfonyUtil\Component\HttpFoundation\ResponseParameters', |
84
|
|
|
(new NullControllerModel(new Response()))->__invoke() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testRedirectResponseReturnsUrl() |
89
|
|
|
{ |
90
|
|
|
$example = 'http://example.org/'; |
91
|
|
|
$responseParameters = (new NullControllerModel(new RedirectResponse($example)))->__invoke(); |
92
|
|
|
$this->assertInstanceOf( |
93
|
|
|
// ::class, // 5.4 < php |
94
|
|
|
'SymfonyUtil\Component\HttpFoundation\ResponseParameters', |
95
|
|
|
$responseParameters |
96
|
|
|
); |
97
|
|
|
$response = $responseParameters->getResponse(); |
98
|
|
|
$this->assertInstanceOf( |
99
|
|
|
// ::class, // 5.4 < php |
100
|
|
|
'Symfony\Component\HttpFoundation\Response', |
101
|
|
|
$response |
102
|
|
|
); |
103
|
|
|
$this->assertInstanceOf( |
104
|
|
|
// ::class, // 5.4 < php |
105
|
|
|
'Symfony\Component\HttpFoundation\RedirectResponse', |
106
|
|
|
$response |
107
|
|
|
); |
108
|
|
|
$url = $response->getTargetUrl(); |
109
|
|
|
$this->assertInternalType('string', $url); |
110
|
|
|
$this->assertSame($example, $url); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|