|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Emarref\Jwt\Token; |
|
4
|
|
|
|
|
5
|
|
|
class PropertyListTest extends \PHPUnit_Framework_TestCase |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
9
|
|
|
*/ |
|
10
|
|
|
private $properties; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var PropertyListStub |
|
14
|
|
|
*/ |
|
15
|
|
|
private $propertyList; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->properties = $this->getMockBuilder('\ArrayObject')->getMock(); |
|
20
|
|
|
|
|
21
|
|
|
$this->propertyList = new PropertyListStub($this->properties); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testSetProperty() |
|
25
|
|
|
{ |
|
26
|
|
|
$property = new PropertyStub(); |
|
27
|
|
|
|
|
28
|
|
|
$this->properties->expects($this->once()) |
|
29
|
|
|
->method('offsetSet') |
|
30
|
|
|
->with($property->getName(), $property); |
|
31
|
|
|
|
|
32
|
|
|
$this->propertyList->setProperty($property); |
|
33
|
|
|
|
|
34
|
|
|
return $property; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testJsonSerialize() |
|
38
|
|
|
{ |
|
39
|
|
|
$expectedJson = '{"one":"11","two":"2"}'; |
|
40
|
|
|
|
|
41
|
|
|
$properties = new \ArrayIterator([ |
|
42
|
|
|
new PropertyStub('one', '1'), |
|
43
|
|
|
new PropertyStub('one', '11'), // Latter takes precedence |
|
44
|
|
|
new PropertyStub('two', '2'), |
|
45
|
|
|
new PropertyStub('three', ''), // Blank value ignored |
|
46
|
|
|
new PropertyStub('', '4'), // Blank name ignored |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
$this->properties->expects($this->once()) |
|
50
|
|
|
->method('getIterator') |
|
51
|
|
|
->will($this->returnValue($properties)); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertSame($expectedJson, $this->propertyList->jsonSerialize()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testGetIterator() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->assertSame($this->properties, $this->propertyList->getIterator()); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|