|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Tests for abstract collections. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Itafroma\Zork\Tests; |
|
9
|
|
|
|
|
10
|
|
|
use Itafroma\Zork\State\AbstractCollection; |
|
11
|
|
|
|
|
12
|
|
|
class AbstractCollectionTest extends ZorkTest |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Tests Itafroma\Zork\AbstractCollection::create(). |
|
16
|
|
|
* |
|
17
|
|
|
* @covers Itafroma\Zork\State\AbstractCollection::create |
|
18
|
|
|
* @dataProvider abstractCollectionPropertyProvider |
|
19
|
|
|
*/ |
|
20
|
|
|
public function testCreateAtom($abstract_collection, $property_name) |
|
21
|
|
|
{ |
|
22
|
|
|
$return = $abstract_collection->create($property_name); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertEquals($return, $this->getPrivateProperty($abstract_collection, 'atoms')[$property_name]); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Tests Itafroma\Zork\State\AbstractCollection::get() when atom exists. |
|
29
|
|
|
* |
|
30
|
|
|
* @covers Itafroma\Zork\State\AbstractCollection::get |
|
31
|
|
|
* @dataProvider abstractCollectionPropertyProvider |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testGetAtomExists($abstract_collection, $property_name, $property_value) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->setPrivateProperty($abstract_collection, 'atoms', [$property_name => $property_value]); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertEquals($property_value, $abstract_collection->get($property_name)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Tests Itafroma\Zork\State\AbstractCollection::get() when atom exists. |
|
42
|
|
|
* |
|
43
|
|
|
* @covers Itafroma\Zork\State\AbstractCollection::get |
|
44
|
|
|
* @dataProvider abstractCollectionPropertyProvider |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testGetAtomDoesNotExist($abstract_collection, $property_name) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->assertFalse($abstract_collection->get($property_name)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Tests Itafroma\Zork\State\AbstractCollection::set(). |
|
53
|
|
|
* |
|
54
|
|
|
* @covers Itafroma\Zork\State\AbstractCollection::set |
|
55
|
|
|
* @dataProvider abstractCollectionPropertyProvider |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testSet($abstract_collection, $property_name, $property_value) |
|
58
|
|
|
{ |
|
59
|
|
|
$return = $abstract_collection->set($property_name, $property_value); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEquals($property_value, $return); |
|
62
|
|
|
$this->assertEquals($property_value, $abstract_collection->get($property_name)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Tests Itafroma\Zork\State\AbstractCollection::exists() when the atom exists. |
|
67
|
|
|
* |
|
68
|
|
|
* @covers Itafroma\Zork\State\AbstractCollection::exists |
|
69
|
|
|
* @dataProvider abstractCollectionPropertyProvider |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testExistsAtomExists($abstract_collection, $property_name, $property_value) |
|
72
|
|
|
{ |
|
73
|
|
|
$abstract_collection->set($property_name, $property_value); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertTrue($abstract_collection->exists($property_name)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Tests Itafroma\Zork\State\AbstractCollection::exists() when the atom does not exist. |
|
80
|
|
|
* |
|
81
|
|
|
* @covers Itafroma\Zork\State\AbstractCollection::exists |
|
82
|
|
|
* @dataProvider abstractCollectionPropertyProvider |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testExistsAtomDoesNotExist($abstract_collection, $property_name) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->assertFalse($abstract_collection->exists($property_name)); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Provides an abstract collection mock with test properties. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function abstractCollectionPropertyProvider() |
|
93
|
|
|
{ |
|
94
|
|
|
$properties = $this->propertyProvider(); |
|
95
|
|
|
|
|
96
|
|
|
foreach ($properties as &$property) { |
|
97
|
|
|
$stub = $this->getMockForAbstractClass(AbstractCollection::class); |
|
98
|
|
|
array_unshift($property, $stub); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $properties; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|