This repository was archived by the owner on Jul 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAbstractObjectMapInterfaceTest.php
More file actions
224 lines (164 loc) · 5.29 KB
/
Copy pathAbstractObjectMapInterfaceTest.php
File metadata and controls
224 lines (164 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php declare(strict_types=1);
/*
* This file is part of the pinepain/php-object-maps PHP library.
*
* Copyright (c) 2016-2017 Bogdan Padalko <pinepain@gmail.com>
*
* Licensed under the MIT license: http://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code or visit http://opensource.org/licenses/MIT
*/
namespace Pinepain\ObjectMaps\Tests;
use PHPUnit\Framework\TestCase;
use Pinepain\ObjectMaps\ObjectBiMapInterface;
use Pinepain\ObjectMaps\ObjectMapInterface;
use stdClass;
abstract class AbstractObjectMapInterfaceTest extends TestCase
{
/**
* @param int $behavior
*
* @return ObjectMapInterface | ObjectBiMapInterface
*/
abstract public function buildMap(int $behavior = ObjectMapInterface::DEFAULT);
public function testMap()
{
$map = $this->buildMap();
$key = new stdClass();
$value = new stdClass();
$this->assertSame(0, $map->count());
$map->put($key, $value);
$this->assertSame(1, $map->count());
$value = null;
$this->assertSame(1, $map->count());
$key = null;
$this->assertSame(1, $map->count());
}
public function testWeakKeyMap()
{
$map = $this->buildMap(ObjectMapInterface::WEAK_KEY);
$key = new stdClass();
$value = new stdClass();
$this->assertSame(0, $map->count());
$map->put($key, $value);
$this->assertSame(1, $map->count());
$this->assertSame($value, $map->get($key));
$value = null;
$this->assertSame(1, $map->count());
$key = null;
$this->assertSame(0, $map->count());
}
public function testWeakValueMap()
{
$map = $this->buildMap(ObjectMapInterface::WEAK_VALUE);
$key = new stdClass();
$value = new stdClass();
$this->assertSame(0, $map->count());
$map->put($key, $value);
$this->assertSame(1, $map->count());
$this->assertSame($value, $map->get($key));
$key = null;
$this->assertSame(1, $map->count());
$value = null;
$this->assertSame(0, $map->count());
}
public function testWeakKeyValueMap()
{
$map = $this->buildMap(ObjectMapInterface::WEAK_KEY_VALUE);
$key = new stdClass();
$value = new stdClass();
$this->assertSame(0, $map->count());
$map->put($key, $value);
$this->assertSame(1, $map->count());
$key = null;
$this->assertSame(0, $map->count());
$key = new stdClass();
$value = new stdClass();
$this->assertSame(0, $map->count());
$map->put($key, $value);
$this->assertSame(1, $map->count());
$value = null;
$this->assertSame(0, $map->count());
}
public function testPutAndGet()
{
$map = $this->buildMap();
$key = new stdClass();
$value = new stdClass();
$map->put($key, $value);
$this->assertSame($value, $map->get($key));
}
/**
* @expectedException \Pinepain\ObjectMaps\Exceptions\OverflowException
* @expectedExceptionMessage Value with such key already exists
*/
public function testPutExistentKeyFails()
{
$map = $this->buildMap();
$key = new stdClass();
$value = new stdClass();
$map->put($key, $value);
$map->put($key, $value);
}
/**
* @expectedException \Pinepain\ObjectMaps\Exceptions\OutOfBoundsException
* @expectedExceptionMessage Value with such key not found
*/
public function testGetNonexistentKeyFails()
{
$map = $this->buildMap();
$map->get(new stdClass());
}
public function testHasNonexistentKey()
{
$map = $this->buildMap();
$this->assertFalse($map->has(new stdClass()));
}
public function testHasExistentKey()
{
$map = $this->buildMap();
$key = new stdClass();
$map->put($key, new stdClass());
$this->assertTrue($map->has($key));
}
/**
* @expectedException \Pinepain\ObjectMaps\Exceptions\OutOfBoundsException
* @expectedExceptionMessage Value with such key not found
*/
public function testRemoveNonexistentKeyFails()
{
$map = $this->buildMap();
$map->remove(new stdClass());
}
public function testRemove()
{
$map = $this->buildMap();
$key = new stdClass();
$map->put($key, new stdClass());
$this->assertTrue($map->has($key));
$map->remove($key);
$this->assertFalse($map->has($key));
}
public function testCount()
{
$map = $this->buildMap();
$this->assertSame(0, $map->count());
$key = new stdClass();
$map->put($key, new stdClass());
$this->assertSame(1, $map->count());
$map->remove($key);
$this->assertSame(0, $map->count());
}
public function testClear()
{
$map = $this->buildMap();
$this->assertSame(0, $map->count());
$map->put(new stdClass(), new stdClass());
$this->assertSame(1, $map->count());
$map->put(new stdClass(), new stdClass());
$this->assertSame(2, $map->count());
$map->clear();
$this->assertSame(0, $map->count());
}
}