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

Tests/RelyingParty/RelyingPartyCollectionTest.php (6 issues)

a method exists on all of the called types.

Bug Major

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
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AerialShip\SamlSPBundle\...y\RelyingPartyInterface.

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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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);
77
        $collection->prepend($relyingPartyTwoMock);
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
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AerialShip\SamlSPBundle\...y\RelyingPartyInterface.

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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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);
104
        $collection->append($relyingPartyTwoMock);
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
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AerialShip\SamlSPBundle\...y\RelyingPartyInterface.

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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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);
131
        $collection->append($relyingPartyTwoMock);
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
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AerialShip\SamlSPBundle\...y\RelyingPartyInterface.

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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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);
174
        $collection->append($relyingPartyTwoMock);
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
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AerialShip\SamlSPBundle\...y\RelyingPartyInterface.

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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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);
204
205
        $collection->manage($expectedRequest);
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
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AerialShip\SamlSPBundle\...y\RelyingPartyInterface.

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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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);
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