These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace AerialShip\SamlSPBundle\Tests\Config; |
||
4 | |||
5 | use AerialShip\LightSaml\Model\Metadata\EntityDescriptor; |
||
6 | use AerialShip\SamlSPBundle\Config\EntityDescriptorProviderInterface; |
||
7 | use AerialShip\SamlSPBundle\Config\ServiceInfo; |
||
8 | use AerialShip\SamlSPBundle\Config\ServiceInfoCollection; |
||
9 | |||
10 | class ServiceInfoCollectionTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @test |
||
14 | */ |
||
15 | public function couldBeConstructed() |
||
16 | { |
||
17 | new ServiceInfoCollection(); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * @test |
||
22 | */ |
||
23 | public function shouldReturnNullForNonExistingService() |
||
24 | { |
||
25 | $col = new ServiceInfoCollection(); |
||
26 | $this->assertNull($col->get('something')); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @test |
||
31 | */ |
||
32 | public function shouldReturnServiceInfoByIdpIDWhenGetIsCalled() |
||
33 | { |
||
34 | $col = new ServiceInfoCollection(); |
||
35 | |||
36 | $expectedServiceInfo_1 = $this->createServiceInfoStub( |
||
37 | $expectedProviderID_1 = 'main', |
||
38 | $expectedIdpID_1 = 'idp1', |
||
39 | null, |
||
40 | null, |
||
41 | null, |
||
42 | null |
||
43 | ); |
||
44 | $expectedServiceInfo_2 = $this->createServiceInfoStub( |
||
45 | $expectedProviderID_2 = 'main', |
||
46 | $expectedIdpID_2 = 'idp2', |
||
47 | null, |
||
48 | null, |
||
49 | null, |
||
50 | null |
||
51 | ); |
||
52 | |||
53 | $col->add($expectedServiceInfo_1); |
||
0 ignored issues
–
show
|
|||
54 | $col->add($expectedServiceInfo_2); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_2 defined by $this->createServiceInfo...null, null, null, null) on line 44 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
55 | |||
56 | $this->assertEquals($expectedServiceInfo_1, $col->get($expectedIdpID_1)); |
||
57 | $this->assertEquals($expectedServiceInfo_2, $col->get($expectedIdpID_2)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @test |
||
62 | */ |
||
63 | public function shouldReturnAllThatAreAddedWhenAllIsCalled() |
||
64 | { |
||
65 | $col = new ServiceInfoCollection(); |
||
66 | |||
67 | $expectedServiceInfo_1 = $this->createServiceInfoStub( |
||
68 | $expectedProviderID_1 = 'main', |
||
69 | $expectedIdpID_1 = 'idp1', |
||
70 | null, |
||
71 | null, |
||
72 | null, |
||
73 | null |
||
74 | ); |
||
75 | $expectedServiceInfo_2 = $this->createServiceInfoStub( |
||
76 | $expectedProviderID_2 = 'main', |
||
77 | $expectedIdpID_2 = 'idp2', |
||
78 | null, |
||
79 | null, |
||
80 | null, |
||
81 | null |
||
82 | ); |
||
83 | |||
84 | $col->add($expectedServiceInfo_1); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_1 defined by $this->createServiceInfo...null, null, null, null) on line 67 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
85 | $col->add($expectedServiceInfo_2); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_2 defined by $this->createServiceInfo...null, null, null, null) on line 75 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
86 | |||
87 | $all = $col->all(); |
||
88 | |||
89 | $this->assertInternalType('array', $all); |
||
90 | $this->assertCount(2, $all); |
||
91 | $this->assertEquals($expectedServiceInfo_1, $all[$expectedIdpID_1]); |
||
92 | $this->assertEquals($expectedServiceInfo_2, $all[$expectedIdpID_2]); |
||
93 | } |
||
94 | |||
95 | |||
96 | /** |
||
97 | * @test |
||
98 | */ |
||
99 | public function shouldReturnEmptyArrayWhenAllCalledAndNoneAdded() |
||
100 | { |
||
101 | $col = new ServiceInfoCollection(); |
||
102 | |||
103 | $all = $col->all(); |
||
104 | |||
105 | $this->assertInternalType('array', $all); |
||
106 | $this->assertCount(0, $all); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @test |
||
111 | */ |
||
112 | public function shouldReturnServiceInfoWhenFindByAsIsCalledWithNullAndThereIsOnlyOne() |
||
113 | { |
||
114 | $col = new ServiceInfoCollection(); |
||
115 | |||
116 | $expectedServiceInfo = $this->createServiceInfoStub( |
||
117 | $expectedProviderID = 'main', |
||
118 | $expectedIdpID = 'idp', |
||
119 | null, |
||
120 | null, |
||
121 | null, |
||
122 | null |
||
123 | ); |
||
124 | |||
125 | $col->add($expectedServiceInfo); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo defined by $this->createServiceInfo...null, null, null, null) on line 116 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
126 | |||
127 | $this->assertEquals($expectedServiceInfo, $col->findByAS(null)); |
||
128 | } |
||
129 | |||
130 | |||
131 | /** |
||
132 | * @test |
||
133 | */ |
||
134 | public function shouldReturnNullWhenFindByAsIsCalledWithNullAndThereIsMoreThenOne() |
||
135 | { |
||
136 | $col = new ServiceInfoCollection(); |
||
137 | |||
138 | $expectedServiceInfo_1 = $this->createServiceInfoStub( |
||
139 | $expectedProviderID_1 = 'main', |
||
140 | $expectedIdpID_1 = 'idp1', |
||
141 | null, |
||
142 | null, |
||
143 | null, |
||
144 | null |
||
145 | ); |
||
146 | $expectedServiceInfo_2 = $this->createServiceInfoStub( |
||
147 | $expectedProviderID_2 = 'main', |
||
148 | $expectedIdpID_2 = 'idp2', |
||
149 | null, |
||
150 | null, |
||
151 | null, |
||
152 | null |
||
153 | ); |
||
154 | |||
155 | $col->add($expectedServiceInfo_1); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_1 defined by $this->createServiceInfo...null, null, null, null) on line 138 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
156 | $col->add($expectedServiceInfo_2); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_2 defined by $this->createServiceInfo...null, null, null, null) on line 146 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
157 | |||
158 | $this->assertNull($col->findByAS(null)); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @test |
||
163 | */ |
||
164 | public function shouldReturnServiceInfoWhenFindByAsIsCalledWithIdpIDAndThereIsMoreThenOne() |
||
165 | { |
||
166 | $col = new ServiceInfoCollection(); |
||
167 | |||
168 | $expectedServiceInfo_1 = $this->createServiceInfoStub( |
||
169 | $expectedProviderID_1 = 'main', |
||
170 | $expectedIdpID_1 = 'idp1', |
||
171 | null, |
||
172 | null, |
||
173 | null, |
||
174 | null |
||
175 | ); |
||
176 | $expectedServiceInfo_2 = $this->createServiceInfoStub( |
||
177 | $expectedProviderID_2 = 'main', |
||
178 | $expectedIdpID_2 = 'idp2', |
||
179 | null, |
||
180 | null, |
||
181 | null, |
||
182 | null |
||
183 | ); |
||
184 | |||
185 | $col->add($expectedServiceInfo_1); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_1 defined by $this->createServiceInfo...null, null, null, null) on line 168 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
186 | $col->add($expectedServiceInfo_2); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_2 defined by $this->createServiceInfo...null, null, null, null) on line 176 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
187 | |||
188 | $this->assertEquals($expectedServiceInfo_1, $col->findByAS($expectedIdpID_1)); |
||
189 | $this->assertEquals($expectedServiceInfo_2, $col->findByAS($expectedIdpID_2)); |
||
190 | } |
||
191 | |||
192 | |||
193 | /** |
||
194 | * @test |
||
195 | */ |
||
196 | public function shouldReturnServiceInfoWhenFindByIDPEntityIDIsCalledWithEntityID() |
||
197 | { |
||
198 | $expectedProviderID = 'main'; |
||
199 | |||
200 | $col = new ServiceInfoCollection(); |
||
201 | |||
202 | $ed_1 = $this->createEntityDescriptorStub($expectedEntityID_1 = 'entity_1'); |
||
203 | $expectedIdpProvider_1 = $this->createEntityDescriptorProviderStub($ed_1); |
||
204 | $expectedServiceInfo_1 = $this->createServiceInfoStub( |
||
205 | $expectedProviderID, |
||
206 | $expectedIdpID_1 = 'idp_1', |
||
207 | $expectedSpProvider = null, |
||
208 | $expectedIdpProvider_1, |
||
209 | null, |
||
210 | null |
||
211 | ); |
||
212 | |||
213 | $ed_2 = $this->createEntityDescriptorStub($expectedEntityID_2 = 'entity_2'); |
||
214 | $expectedIdpProvider_2 = $this->createEntityDescriptorProviderStub($ed_2); |
||
215 | $expectedServiceInfo_2 = $this->createServiceInfoStub( |
||
216 | $expectedProviderID, |
||
217 | $expectedIdpID_2 = 'idp_2', |
||
218 | $expectedSpProvider = null, |
||
219 | $expectedIdpProvider_2, |
||
220 | null, |
||
221 | null |
||
222 | ); |
||
223 | |||
224 | $col->add($expectedServiceInfo_1); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_1 defined by $this->createServiceInfo...Provider_1, null, null) on line 204 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
225 | $col->add($expectedServiceInfo_2); |
||
0 ignored issues
–
show
It seems like
$expectedServiceInfo_2 defined by $this->createServiceInfo...Provider_2, null, null) on line 215 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, AerialShip\SamlSPBundle\...ceInfoCollection::add() does only seem to accept object<AerialShip\SamlSP...dle\Config\ServiceInfo> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
226 | |||
227 | $this->assertEquals($expectedServiceInfo_1, $col->findByIDPEntityID($expectedEntityID_1)); |
||
228 | $this->assertEquals($expectedServiceInfo_2, $col->findByIDPEntityID($expectedEntityID_2)); |
||
229 | $this->assertNull($col->findByIDPEntityID('foo')); |
||
230 | } |
||
231 | |||
232 | |||
233 | /** |
||
234 | * @test |
||
235 | */ |
||
236 | public function shouldReturnNullWhenFindByIDPEntityIDIsCalledWithUnknownEntityID() |
||
237 | { |
||
238 | $col = new ServiceInfoCollection(); |
||
239 | |||
240 | $this->assertNull($col->findByIDPEntityID('foo')); |
||
241 | } |
||
242 | |||
243 | |||
244 | |||
245 | |||
246 | |||
247 | /** |
||
248 | * @return \PHPUnit_Framework_MockObject_MockObject|ServiceInfo |
||
249 | */ |
||
250 | protected function createServiceInfoMock() |
||
251 | { |
||
252 | return $this->getMock('AerialShip\SamlSPBundle\Config\ServiceInfo', array(), array(), '', false, false); |
||
253 | } |
||
254 | |||
255 | |||
256 | /** |
||
257 | * @param $providerID |
||
258 | * @param $idpID |
||
259 | * @param $spProvider |
||
260 | * @param $idpProvider |
||
261 | * @param $spMetaProvider |
||
262 | * @param $signingProvider |
||
263 | * @return ServiceInfo|\PHPUnit_Framework_MockObject_MockObject |
||
264 | */ |
||
265 | protected function createServiceInfoStub($providerID, $idpID, $spProvider, $idpProvider, $spMetaProvider, $signingProvider) |
||
266 | { |
||
267 | $result = $this->createServiceInfoMock(); |
||
268 | $result->expects($this->any())->method('getProviderID')->will($this->returnValue($providerID)); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in AerialShip\SamlSPBundle\Config\ServiceInfo .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
269 | $result->expects($this->any())->method('getAuthenticationService')->will($this->returnValue($idpID)); |
||
270 | $result->expects($this->any())->method('getSpProvider')->will($this->returnValue($spProvider)); |
||
271 | $result->expects($this->any())->method('getIdpProvider')->will($this->returnValue($idpProvider)); |
||
272 | $result->expects($this->any())->method('getSpMetaProvider')->will($this->returnValue($spMetaProvider)); |
||
273 | $result->expects($this->any())->method('getSpSigningProvider')->will($this->returnValue($signingProvider)); |
||
274 | return $result; |
||
275 | } |
||
276 | |||
277 | |||
278 | /** |
||
279 | * @return \PHPUnit_Framework_MockObject_MockObject|EntityDescriptorProviderInterface |
||
280 | */ |
||
281 | protected function createEntityDescriptorProviderMock() |
||
282 | { |
||
283 | return $this->getMock('AerialShip\SamlSPBundle\Config\EntityDescriptorProviderInterface'); |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * @param $ed |
||
288 | * @return EntityDescriptorProviderInterface|\PHPUnit_Framework_MockObject_MockObject |
||
289 | */ |
||
290 | protected function createEntityDescriptorProviderStub($ed) |
||
291 | { |
||
292 | $result = $this->createEntityDescriptorProviderMock(); |
||
293 | $result->expects($this->any())->method('getEntityDescriptor')->will($this->returnValue($ed)); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in AerialShip\SamlSPBundle\...riptorProviderInterface .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
294 | return $result; |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * @return \PHPUnit_Framework_MockObject_MockObject|EntityDescriptor |
||
299 | */ |
||
300 | protected function createEntityDescriptorMock() |
||
301 | { |
||
302 | return $this->getMock('AerialShip\LightSaml\Model\Metadata\EntityDescriptor'); |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * @param $entityID |
||
307 | * @return EntityDescriptor|\PHPUnit_Framework_MockObject_MockObject |
||
308 | */ |
||
309 | protected function createEntityDescriptorStub($entityID) |
||
310 | { |
||
311 | $result = $this->createEntityDescriptorMock(); |
||
312 | $result->expects($this->any())->method('getEntityID')->will($this->returnValue($entityID)); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in AerialShip\LightSaml\Mod...tadata\EntityDescriptor .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
313 | return $result; |
||
314 | } |
||
315 | } |
||
316 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.