1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Tests for Defs.php. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Itafroma\Zork\Tests; |
9
|
|
|
|
10
|
|
|
use function Itafroma\Zork\oget; |
11
|
|
|
use function Itafroma\Zork\oput; |
12
|
|
|
|
13
|
|
|
class DefsTest extends ZorkTest |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Test Itafroma\Zork\oget() with empty property. |
17
|
|
|
* |
18
|
|
|
* @covers ::Itafroma\Zork\oget |
19
|
|
|
* @dataProvider objectPropertyProvider |
20
|
|
|
*/ |
21
|
|
|
public function testOgetEmptyProperty($struc, $property_key) |
22
|
|
|
{ |
23
|
|
|
$this->assertNull(oget($struc, $property_key)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Test Itafroma\Zork\oget() with extant property. |
28
|
|
|
* |
29
|
|
|
* @covers ::Itafroma\Zork\oget |
30
|
|
|
* @dataProvider objectPropertyProvider |
31
|
|
|
*/ |
32
|
|
|
public function testOgetExtantProperty($struc, $property_key, $property_value) |
33
|
|
|
{ |
34
|
|
|
$return = oput($struc, $property_key, $property_value); |
35
|
|
|
|
36
|
|
|
$this->assertEquals($property_value, oget($return, $property_key)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Test Itafroma\Zork\oget() with non-objects and non-rooms. |
41
|
|
|
* |
42
|
|
|
* @covers ::Itafroma\Zork\oget |
43
|
|
|
* @dataProvider strucPropertyProvider |
44
|
|
|
* @expectedException \InvalidArgumentException |
45
|
|
|
*/ |
46
|
|
|
public function testOgetOther($struc, $property_key) |
47
|
|
|
{ |
48
|
|
|
oget($struc, $property_key); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Test Itafroma\Zork\oput() with regular objects. |
53
|
|
|
* |
54
|
|
|
* @covers ::Itafroma\Zork\oput |
55
|
|
|
* @dataProvider objectPropertyProvider |
56
|
|
|
*/ |
57
|
|
|
public function testOputObject($struc, $property_key, $property_value) |
58
|
|
|
{ |
59
|
|
|
$return = oput($struc, $property_key, $property_value); |
60
|
|
|
|
61
|
|
|
$this->assertEquals($struc, $return); |
62
|
|
|
$this->assertEquals($property_value, $return->oprops[$property_key]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test Itafroma\Zork\oput() with rooms. |
67
|
|
|
* |
68
|
|
|
* @covers ::Itafroma\Zork\oput |
69
|
|
|
* @dataProvider roomPropertyProvider |
70
|
|
|
*/ |
71
|
|
|
public function testOputRoom($struc, $property_key, $property_value) |
72
|
|
|
{ |
73
|
|
|
$return = oput($struc, $property_key, $property_value); |
74
|
|
|
|
75
|
|
|
$this->assertEquals($struc, $return); |
76
|
|
|
$this->assertEquals($property_value, $return->rprops[$property_key]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Test Itafroma\Zork\oput() with non-objects and non-rooms. |
81
|
|
|
* |
82
|
|
|
* @covers ::Itafroma\Zork\oput |
83
|
|
|
* @dataProvider strucPropertyProvider |
84
|
|
|
* @expectedException \InvalidArgumentException |
85
|
|
|
*/ |
86
|
|
|
public function testOputOther($struc, $property_key, $property_value) |
87
|
|
|
{ |
88
|
|
|
oput($struc, $property_key, $property_value); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Test Itafroma\Zork\oput() with empty object properties and add = false. |
93
|
|
|
* |
94
|
|
|
* @covers ::Itafroma\Zork\oput |
95
|
|
|
* @dataProvider objectPropertyProvider |
96
|
|
|
*/ |
97
|
|
|
public function testOputNoAdd($struc, $property_key, $property_value) |
98
|
|
|
{ |
99
|
|
|
$return = oput($struc, $property_key, $property_value, false); |
100
|
|
|
|
101
|
|
|
$this->assertArrayNotHasKey($property_key, $return->oprops); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|