CredentialContextSetTest::getMetadataContextMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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()]);
0 ignored issues
show
Documentation introduced by
array($metadataContextMo...tMetadataContextMock()) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Lig...ntialContextInterface>>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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()]);
0 ignored issues
show
Documentation introduced by
$expected = array($this-...tMetadataContextMock()) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Lig...ntialContextInterface>>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
29
        $all = $context->all();
30
        $this->assertCount(2, $all);
0 ignored issues
show
Documentation introduced by
$all is of type array<integer,object<Lig...ntialContextInterface>>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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()]);
0 ignored issues
show
Documentation introduced by
array(new \stdClass()) is of type array<integer,object<std...0":"object<stdClass>"}>, but the function expects a array<integer,object<Lig...ntialContextInterface>>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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