1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LightSaml\Tests\Credential\Context; |
4
|
|
|
|
5
|
|
|
use LightSaml\Credential\Context\CredentialContextSet; |
6
|
|
|
use LightSaml\Credential\Context\MetadataCredentialContext; |
7
|
|
|
use LightSaml\Tests\BaseTestCase; |
8
|
|
|
|
9
|
|
|
class CredentialContextSetTest extends BaseTestCase |
10
|
|
|
{ |
11
|
|
|
public function test_metadata_context_is_null_upon_creation() |
12
|
|
|
{ |
13
|
|
|
$context = new CredentialContextSet(); |
14
|
|
|
|
15
|
|
|
$this->assertNull($context->get(MetadataCredentialContext::class)); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function test_returns_set_metadata_context() |
19
|
|
|
{ |
20
|
|
|
$context = new CredentialContextSet([$metadataContextMock = $this->getMetadataContextMock()]); |
|
|
|
|
21
|
|
|
|
22
|
|
|
$this->assertSame($metadataContextMock, $context->get(MetadataCredentialContext::class)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function test_returns_all_contexts() |
26
|
|
|
{ |
27
|
|
|
$context = new CredentialContextSet($expected = [$this->getMetadataContextMock(), $this->getMetadataContextMock()]); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$all = $context->all(); |
30
|
|
|
$this->assertCount(2, $all); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$this->assertSame($expected[0], $all[0]); |
33
|
|
|
$this->assertSame($expected[1], $all[1]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function test_throws_invalid_argument_exception_if_constructed_with_non_credential_context_array() |
37
|
|
|
{ |
38
|
|
|
$this->expectExceptionMessage("Expected CredentialContextInterface"); |
39
|
|
|
$this->expectException(\InvalidArgumentException::class); |
40
|
|
|
new CredentialContextSet([new \stdClass()]); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Credential\Context\MetadataCredentialContext |
45
|
|
|
*/ |
46
|
|
|
private function getMetadataContextMock() |
47
|
|
|
{ |
48
|
|
|
return $this->getMockBuilder(\LightSaml\Credential\Context\MetadataCredentialContext::class) |
49
|
|
|
->disableOriginalConstructor() |
50
|
|
|
->getMock(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: