Skip to content

Commit 857fea4

Browse files
committed
drop user spaces method
1 parent 923f502 commit 857fea4

File tree

2 files changed

+26
-37
lines changed

2 files changed

+26
-37
lines changed

src/Mapper.php

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public function createSpace(string $space, array $options = []): Space
4444
return $this->getSpace($space);
4545
}
4646

47+
public function dropUserSpaces(): static
48+
{
49+
foreach ($this->find('_vspace') as $space) {
50+
$id = $this->arrays ? $space['id'] : $space->id;
51+
if ($id >= 512) {
52+
$this->getSpace($id)->drop();
53+
}
54+
}
55+
return $this;
56+
}
57+
4758
public function evaluate(string $query, array $params = [], bool $createFunction = false)
4859
{
4960
if (!count($params)) {

tests/MapperTest.php

+15-37
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,40 @@
1717
class MapperTest extends TestCase
1818
{
1919
private Middleware $middleware;
20-
public function createMapper(): Mapper
21-
{
20+
21+
public function createMapper(
22+
bool $arrays = false,
23+
bool $dropUserSpaces = true,
24+
): Mapper {
2225
$host = getenv('TARANTOOL_HOST');
2326
$port = getenv('TARANTOOL_PORT') ?: 3301;
2427
$this->middleware = new Middleware();
2528
$client = Client::fromDsn("tcp://$host:$port")->withMiddleware($this->middleware);
2629

27-
$mapper = new Mapper($client);
28-
$mapper->spy = true;
30+
$mapper = new Mapper($client, arrays: $arrays, spy: true);
31+
if ($dropUserSpaces) {
32+
$mapper->dropUserSpaces();
33+
}
34+
2935
return $mapper;
3036
}
3137

3238
public function testCache()
3339
{
34-
$mapper = $this->createMapper();
40+
$mapper = $this->createMapper(dropUserSpaces: false);
3541
$cache = new ArrayAdapter();
3642
$mapper->cache = $cache;
3743
$this->assertCount(0, $cache->getvalues());
44+
$mapper->dropUserSpaces();
3845
$mapper->find('_vspace');
3946

4047
$this->assertNotCount(0, $cache->getvalues());
4148

4249
$freshCounter = count($this->middleware->data);
4350

44-
$mapper = $this->createMapper();
51+
$mapper = $this->createMapper(dropUserSpaces: false);
4552
$mapper->cache = $cache;
53+
$mapper->dropUserSpaces();
4654
$mapper->find('_vspace');
4755

4856
// 4 requests:
@@ -54,11 +62,6 @@ public function testCache()
5462
public function testDifferentIndexPartConfiguration()
5563
{
5664
$mapper = $this->createMapper();
57-
foreach ($mapper->find('_vspace') as $space) {
58-
if ($space->id >= 512) {
59-
$mapper->getSpace($space->id)->drop();
60-
}
61-
}
6265

6366
$tester = $mapper->createSpace('tester');
6467
$tester->addProperty('id', 'unsigned');
@@ -96,11 +99,6 @@ public function testDifferentIndexPartConfiguration()
9699
public function testCreateRow()
97100
{
98101
$mapper = $this->createMapper();
99-
foreach ($mapper->find('_vspace') as $space) {
100-
if ($space->id >= 512) {
101-
$mapper->getSpace($space->id)->drop();
102-
}
103-
}
104102

105103
// No 'id' field, sequence isn't created
106104
$tester = $mapper->createSpace('tester');
@@ -154,16 +152,7 @@ public function testCreateRow()
154152

155153
public function testIndexCasting()
156154
{
157-
$mapper = $this->createMapper();
158-
159-
$mapper->arrays = true;
160-
161-
foreach ($mapper->find('_vspace') as $space) {
162-
if ($space['id'] >= 512) {
163-
$mapper->getSpace($space['id'])->drop();
164-
}
165-
}
166-
155+
$mapper = $this->createMapper(arrays: true);
167156
$tester = $mapper->createSpace('tester');
168157

169158
$tester->addProperty('id', 'unsigned');
@@ -187,12 +176,6 @@ public function testIndexCasting()
187176
public function testFindOrCreateRow()
188177
{
189178
$mapper = $this->createMapper();
190-
foreach ($mapper->find('_vspace') as $space) {
191-
if ($space->id >= 512) {
192-
$mapper->getSpace($space->id)->drop();
193-
}
194-
}
195-
196179
$tester = $mapper->createSpace('tester');
197180

198181
//id is not first field, sequence isn't created
@@ -268,11 +251,6 @@ public function testSpaces()
268251
echo PHP_EOL;
269252
$mapper = $this->createMapper();
270253

271-
foreach ($mapper->find('_vspace') as $space) {
272-
if ($space->id >= 512) {
273-
$mapper->getSpace($space->id)->drop();
274-
}
275-
}
276254

277255
$userTypes = [
278256
'constructor' => TypedConstructor::class,

0 commit comments

Comments
 (0)