1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Base test class. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Itafroma\Zork\Tests; |
8
|
|
|
|
9
|
|
|
use Itafroma\Zork\ServiceContainer; |
10
|
|
|
use Itafroma\Zork\Struc\Object; |
11
|
|
|
use Itafroma\Zork\Struc\Room; |
12
|
|
|
use \PHPUnit_Framework_TestCase; |
13
|
|
|
use \ReflectionObject; |
14
|
|
|
|
15
|
|
|
abstract class ZorkTest extends PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
protected $container; |
18
|
|
|
|
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->container = ServiceContainer::getContainer(true); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Gets the value of a private property. |
26
|
|
|
*/ |
27
|
|
|
public function getPrivateProperty($object, $property) |
28
|
|
|
{ |
29
|
|
|
$reflected_object = new ReflectionObject($object); |
30
|
|
|
$reflected_property = $reflected_object->getProperty($property); |
31
|
|
|
$reflected_property->setAccessible(true); |
32
|
|
|
|
33
|
|
|
return $reflected_property->getValue($object); |
34
|
|
|
} |
35
|
|
|
/** |
36
|
|
|
* Sets the value of a private property. |
37
|
|
|
*/ |
38
|
|
|
public function setPrivateProperty($object, $property, $value) |
39
|
|
|
{ |
40
|
|
|
$reflected_object = new ReflectionObject($object); |
41
|
|
|
$reflected_property = $reflected_object->getProperty($property); |
42
|
|
|
$reflected_property->setAccessible(true); |
43
|
|
|
$reflected_property->setValue($object, $value); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Key-value properties used for testing functions modifying global state. |
48
|
|
|
*/ |
49
|
|
|
public function propertyProvider() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
|
|
['ZorkTest-property', 'value1', 'value2'], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Provides a room struc and a mock property. |
58
|
|
|
*/ |
59
|
|
|
public function roomPropertyProvider() |
60
|
|
|
{ |
61
|
|
|
$properties = $this->propertyProvider(); |
62
|
|
|
|
63
|
|
|
foreach ($properties as &$property) { |
64
|
|
|
array_unshift($property, new Room()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $properties; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Provides an object struc and a mock property. |
72
|
|
|
*/ |
73
|
|
|
public function objectPropertyProvider() |
74
|
|
|
{ |
75
|
|
|
$properties = $this->propertyProvider(); |
76
|
|
|
|
77
|
|
|
foreach ($properties as &$property) { |
78
|
|
|
array_unshift($property, new Object()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $properties; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Provides a generic struc and a mock property. |
86
|
|
|
*/ |
87
|
|
|
public function strucPropertyProvider() |
88
|
|
|
{ |
89
|
|
|
$properties = $this->propertyProvider(); |
90
|
|
|
|
91
|
|
|
foreach ($properties as &$property) { |
92
|
|
|
array_unshift($property, $this->getMockBuilder('Itafroma\Zork\Struc\StrucInterface')->getMock()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $properties; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|