1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
declare(strict_types = 1); |
20
|
|
|
|
21
|
|
|
namespace PSR7SessionsTest\Storageless\Session; |
22
|
|
|
|
23
|
|
|
use PHPUnit_Framework_TestCase; |
24
|
|
|
use PSR7Sessions\Storageless\Helper\ArrayAccessor; |
25
|
|
|
use PSR7Sessions\Storageless\Session\SessionInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @covers \PSR7Sessions\Storageless\Helper\ArrayAccessor |
29
|
|
|
*/ |
30
|
|
|
final class ArrayAccessorTest extends PHPUnit_Framework_TestCase |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var SessionInterface|\PHPUnit_Framework_MockObject_MockObject |
34
|
|
|
*/ |
35
|
|
|
private $wrappedSession; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ArrayAccessor |
39
|
|
|
*/ |
40
|
|
|
private $arrayAccess; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
protected function setUp() |
46
|
|
|
{ |
47
|
|
|
$this->wrappedSession = $this->createMock(SessionInterface::class); |
48
|
|
|
$this->arrayAccess = new ArrayAccessor($this->wrappedSession); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testOffsetExists() |
52
|
|
|
{ |
53
|
|
|
$this->wrappedSession->expects(self::exactly(2))->method('has')->willReturnMap( |
|
|
|
|
54
|
|
|
[ |
55
|
|
|
['foo', false], |
56
|
|
|
['bar', true], |
57
|
|
|
] |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
self::assertFalse($this->arrayAccess->offsetExists('foo')); |
61
|
|
|
self::assertTrue($this->arrayAccess->offsetExists('bar')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
*/ |
67
|
|
|
public function testOffsetUnset() |
68
|
|
|
{ |
69
|
|
|
$this->wrappedSession->expects(self::exactly(2))->method('remove')->with(self::logicalOr('foo', 'bar')); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->arrayAccess->offsetUnset('foo'); |
72
|
|
|
$this->arrayAccess->offsetUnset('bar'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testOffsetGet() |
76
|
|
|
{ |
77
|
|
|
$this->wrappedSession->expects(self::exactly(3))->method('get')->willReturnMap( |
|
|
|
|
78
|
|
|
[ |
79
|
|
|
['foo', null, 'bar'], |
80
|
|
|
['baz', null, 'tab'], |
81
|
|
|
['baz', 'default', 'taz'], |
82
|
|
|
] |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
self::assertSame('bar', $this->arrayAccess->offsetGet('foo')); |
86
|
|
|
self::assertSame('tab', $this->arrayAccess->offsetGet('baz')); |
87
|
|
|
self::assertSame('taz', $this->arrayAccess->offsetGet('baz', 'default')); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testOffsetSet() |
91
|
|
|
{ |
92
|
|
|
$this->wrappedSession->expects(self::exactly(2))->method('set')->with( |
|
|
|
|
93
|
|
|
self::logicalOr('foo', 'baz'), |
94
|
|
|
self::logicalOr('bar', 'tab') |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$this->arrayAccess->offsetSet('foo', 'bar'); |
98
|
|
|
$this->arrayAccess->offsetSet('baz', 'tab'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testGetSessionInterface() |
102
|
|
|
{ |
103
|
|
|
self::assertEquals($this->wrappedSession, $this->arrayAccess->getSession()); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: