Completed
Push — master ( d5bbb9...ab4758 )
by Milos
04:50 queued 02:32
created

Tests/RelyingParty/RelyingPartyCollectionTest.php (11 issues)

call_checks.maybe_mismatching_type_passed_with_def

Bug Minor

Upgrade to new PHP Analysis Engine

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\RelyingParty;
4
5
use AerialShip\SamlSPBundle\RelyingParty\RelyingPartyCollection;
6
7
class RelyingPartyCollectionTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @test
11
     */
12
    public function shouldImplementsRelyingPartyInterface()
13
    {
14
        $rc = new \ReflectionClass('AerialShip\SamlSPBundle\RelyingParty\RelyingPartyCollection');
15
        $this->assertTrue($rc->implementsInterface('AerialShip\SamlSPBundle\RelyingParty\RelyingPartyInterface'));
16
    }
17
18
    /**
19
     * @test
20
     */
21
    public function couldBeConstructedWithoutAnyArguments()
22
    {
23
        new RelyingPartyCollection();
24
    }
25
26
27
    /**
28
     * @test
29
     */
30
    public function shouldAllowPrependRelyingParty()
31
    {
32
        $collection = new RelyingPartyCollection;
33
        $collection->prepend($this->createRelyingPartyMock());
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function shouldAllowAppendRelyingParty()
40
    {
41
        $collection = new RelyingPartyCollection;
42
        $collection->append($this->createRelyingPartyMock());
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function shouldNotSupportIfCollectionEmpty()
49
    {
50
        $collection = new RelyingPartyCollection;
51
        $this->assertFalse($collection->supports($this->createRequestMock()));
52
    }
53
54
55
    /**
56
     * @test
57
     */
58
    public function shouldNotSupportIfAnyRelyingPartyInCollectionNotSupport()
59
    {
60
        $relyingPartyOneMock = $this->createRelyingPartyMock();
61
        $relyingPartyOneMock
62
                ->expects($this->once())
63
                ->method('supports')
64
                ->will($this->returnValue(false))
65
        ;
66
67
        $relyingPartyTwoMock = $this->createRelyingPartyMock();
68
        $relyingPartyTwoMock
69
                ->expects($this->once())
70
                ->method('supports')
71
                ->will($this->returnValue(false))
72
        ;
73
74
        $collection = new RelyingPartyCollection;
75
76
        $collection->append($relyingPartyOneMock);
0 ignored issues
show
It seems like $relyingPartyOneMock defined by $this->createRelyingPartyMock() on line 60 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
77
        $collection->prepend($relyingPartyTwoMock);
0 ignored issues
show
It seems like $relyingPartyTwoMock defined by $this->createRelyingPartyMock() on line 67 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...tyCollection::prepend() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
78
79
        $this->assertFalse($collection->supports($this->createRequestMock()));
80
    }
81
82
    /**
83
     * @test
84
     */
85
    public function shouldSupportIfRelyingPartyInCollectionSupport()
86
    {
87
        $relyingPartyOneMock = $this->createRelyingPartyMock();
88
        $relyingPartyOneMock
89
                ->expects($this->once())
90
                ->method('supports')
91
                ->will($this->returnValue(false))
92
        ;
93
94
        $relyingPartyTwoMock = $this->createRelyingPartyMock();
95
        $relyingPartyTwoMock
96
                ->expects($this->once())
97
                ->method('supports')
98
                ->will($this->returnValue(true))
99
        ;
100
101
        $collection = new RelyingPartyCollection;
102
103
        $collection->append($relyingPartyOneMock);
0 ignored issues
show
It seems like $relyingPartyOneMock defined by $this->createRelyingPartyMock() on line 87 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
104
        $collection->append($relyingPartyTwoMock);
0 ignored issues
show
It seems like $relyingPartyTwoMock defined by $this->createRelyingPartyMock() on line 94 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
105
106
        $this->assertTrue($collection->supports($this->createRequestMock()));
107
    }
108
109
110
    /**
111
     * @test
112
     */
113
    public function shouldStopOnFirstSupportedRelyingPartyWhileCheckingWhetherCollectionSupportOrNot()
114
    {
115
        $relyingPartyOneMock = $this->createRelyingPartyMock();
116
        $relyingPartyOneMock
117
                ->expects($this->once())
118
                ->method('supports')
119
                ->will($this->returnValue(true))
120
        ;
121
122
        $relyingPartyTwoMock = $this->createRelyingPartyMock();
123
        $relyingPartyTwoMock
124
                ->expects($this->never())
125
                ->method('supports')
126
        ;
127
128
        $collection = new RelyingPartyCollection;
129
130
        $collection->append($relyingPartyOneMock);
0 ignored issues
show
It seems like $relyingPartyOneMock defined by $this->createRelyingPartyMock() on line 115 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
131
        $collection->append($relyingPartyTwoMock);
0 ignored issues
show
It seems like $relyingPartyTwoMock defined by $this->createRelyingPartyMock() on line 122 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
132
133
        $this->assertTrue($collection->supports($this->createRequestMock()));
134
    }
135
136
    /**
137
     * @test
138
     *
139
     * @expectedException \InvalidArgumentException
140
     * @expectedExceptionMessage The relying party does not support the request
141
     */
142
    public function throwIfTryManageEmptyCollection()
143
    {
144
        $collection = new RelyingPartyCollection;
145
        $this->assertFalse($collection->supports($this->createRequestMock()));
146
        $collection->manage($this->createRequestMock());
147
    }
148
149
    /**
150
     * @test
151
     *
152
     * @expectedException InvalidArgumentException
153
     * @expectedExceptionMessage The relying party does not support the request
154
     */
155
    public function throwIfTryManageRequestNotSupportedByAnyRelyingPartyInCollection()
156
    {
157
        $relyingPartyOneMock = $this->createRelyingPartyMock();
158
        $relyingPartyOneMock
159
                ->expects($this->atLeastOnce())
160
                ->method('supports')
161
                ->will($this->returnValue(false))
162
        ;
163
164
        $relyingPartyTwoMock = $this->createRelyingPartyMock();
165
        $relyingPartyTwoMock
166
                ->expects($this->atLeastOnce())
167
                ->method('supports')
168
                ->will($this->returnValue(false))
169
        ;
170
171
        $collection = new RelyingPartyCollection;
172
173
        $collection->append($relyingPartyOneMock);
0 ignored issues
show
It seems like $relyingPartyOneMock defined by $this->createRelyingPartyMock() on line 157 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
174
        $collection->append($relyingPartyTwoMock);
0 ignored issues
show
It seems like $relyingPartyTwoMock defined by $this->createRelyingPartyMock() on line 164 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
175
176
        $this->assertFalse($collection->supports($this->createRequestMock()));
177
178
        $collection->manage($this->createRequestMock());
179
    }
180
181
182
    /**
183
     * @test
184
     */
185
    public function shouldProxyManagingToRelyingPartyWhichSupportRequest()
186
    {
187
        $expectedRequest = $this->createRequestMock();
188
189
        $relyingPartyOneMock = $this->createRelyingPartyMock();
190
        $relyingPartyOneMock
191
                ->expects($this->any())
192
                ->method('supports')
193
                ->will($this->returnValue(true))
194
        ;
195
        $relyingPartyOneMock
196
                ->expects($this->once())
197
                ->method('manage')
198
                ->with($expectedRequest)
199
        ;
200
201
        $collection = new RelyingPartyCollection;
202
203
        $collection->append($relyingPartyOneMock);
0 ignored issues
show
It seems like $relyingPartyOneMock defined by $this->createRelyingPartyMock() on line 189 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
204
205
        $collection->manage($expectedRequest);
0 ignored issues
show
It seems like $expectedRequest defined by $this->createRequestMock() on line 187 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::manage() does only seem to accept object<Symfony\Component\HttpFoundation\Request>, 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...
206
    }
207
208
209
    /**
210
     * @test
211
     */
212
    public function shouldReturnResultOfRelyingPartyWhichSupportRequestOnManaging()
213
    {
214
        $expectedResult = 'the_relying_party_result';
215
216
        $relyingPartyOneMock = $this->createRelyingPartyMock();
217
        $relyingPartyOneMock
218
                ->expects($this->any())
219
                ->method('supports')
220
                ->will($this->returnValue(true))
221
        ;
222
        $relyingPartyOneMock
223
                ->expects($this->once())
224
                ->method('manage')
225
                ->will($this->returnValue($expectedResult))
226
        ;
227
228
        $collection = new RelyingPartyCollection;
229
230
        $collection->append($relyingPartyOneMock);
0 ignored issues
show
It seems like $relyingPartyOneMock defined by $this->createRelyingPartyMock() on line 216 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, AerialShip\SamlSPBundle\...rtyCollection::append() does only seem to accept object<AerialShip\SamlSP...\RelyingPartyInterface>, 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...
231
232
        $this->assertSame($expectedResult, $collection->manage($this->createRequestMock()));
233
    }
234
235
    /**
236
     * @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\HttpFoundation\Request
237
     */
238
    public function createRequestMock()
239
    {
240
        return $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
241
    }
242
243
    /**
244
     * @return \PHPUnit_Framework_MockObject_MockObject|\AerialShip\SamlSPBundle\RelyingParty\RelyingPartyInterface
245
     */
246
    public function createRelyingPartyMock()
247
    {
248
        return $this->getMock('AerialShip\SamlSPBundle\RelyingParty\RelyingPartyInterface');
249
    }
250
}
251