1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maketok\DataMigration; |
4
|
|
|
|
5
|
|
|
class ArrayMapTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var ArrayMap |
9
|
|
|
*/ |
10
|
|
|
private $map; |
11
|
|
|
|
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
$this->map = new ArrayMap(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testGet() |
18
|
|
|
{ |
19
|
|
|
$this->map->somevar = 1; |
20
|
|
|
|
21
|
|
|
$this->assertSame(1, $this->map->somevar); |
|
|
|
|
22
|
|
|
$this->assertSame(1, $this->map['somevar']); |
23
|
|
|
$this->assertNull($this->map['someothervar']); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testHas() |
27
|
|
|
{ |
28
|
|
|
$this->map->somevar = 1; |
29
|
|
|
|
30
|
|
|
$this->assertTrue(isset($this->map['somevar'])); |
31
|
|
|
$this->assertTrue($this->map->offsetExists('somevar')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testUnset() |
35
|
|
|
{ |
36
|
|
|
$this->map->somevar = 1; |
37
|
|
|
unset($this->map['somevar']); |
38
|
|
|
|
39
|
|
|
// should not produce error |
40
|
|
|
unset($this->map->someothervar); |
41
|
|
|
|
42
|
|
|
$this->assertFalse(isset($this->map['somevar'])); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testFill() |
46
|
|
|
{ |
47
|
|
|
$this->map->setState([ |
48
|
|
|
'somevar' => 2 |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
$this->assertEquals(2, $this->map->somevar); |
|
|
|
|
52
|
|
|
$this->assertEquals([ |
53
|
|
|
'somevar' => 2 |
54
|
|
|
], $this->map->dumpState()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testIncr() |
58
|
|
|
{ |
59
|
|
|
$this->map->somevar = 1; |
60
|
|
|
$this->map->incr('somevar', 50); |
61
|
|
|
$this->map->incr('someothervar', 50, 50); |
62
|
|
|
|
63
|
|
|
$this->assertSame(2, $this->map->somevar); |
|
|
|
|
64
|
|
|
$this->assertSame(50, $this->map->someothervar); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testFrozenIncr() |
68
|
|
|
{ |
69
|
|
|
$this->map->somevar = 1; |
70
|
|
|
$this->map->frozenIncr('somevar', 1, 1); // +1 |
71
|
|
|
$this->map->frozenIncr('somevar', 1, 1); // +1 |
72
|
|
|
$this->map->frozenIncr('somevar', 1, 1); // +1 |
73
|
|
|
$this->map->freeze(); |
74
|
|
|
$this->map->frozenIncr('somevar', 1, 1); // do nothing |
75
|
|
|
$this->map->frozenIncr('somevar', 1, 1); // do nothing |
76
|
|
|
$this->map->unFreeze(); |
77
|
|
|
$this->map->frozenIncr('somevar', 1, 5); // +5 |
78
|
|
|
$this->map->frozenIncr('somevar', 1, 5); // +5 |
79
|
|
|
|
80
|
|
|
$this->assertSame(14, $this->map->somevar); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testIterate() |
84
|
|
|
{ |
85
|
|
|
$this->map->setState([ |
86
|
|
|
'somevar' => 2, |
87
|
|
|
'someothervar' => 2, |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
$i = 0; |
91
|
|
|
foreach ($this->map as $key => $val) { |
92
|
|
|
$i++; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$this->assertEquals(2, $i); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testWithClear() |
99
|
|
|
{ |
100
|
|
|
$this->map->setState([ |
101
|
|
|
'somevar' => 2, |
102
|
|
|
'someothervar' => 2, |
103
|
|
|
]); |
104
|
|
|
$this->map->clear(); |
105
|
|
|
|
106
|
|
|
$this->assertFalse(isset($this->map['somevar'])); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.