17
17
class MapperTest extends TestCase
18
18
{
19
19
private Middleware $ middleware ;
20
- public function createMapper (): Mapper
21
- {
20
+
21
+ public function createMapper (
22
+ bool $ arrays = false ,
23
+ bool $ dropUserSpaces = true ,
24
+ ): Mapper {
22
25
$ host = getenv ('TARANTOOL_HOST ' );
23
26
$ port = getenv ('TARANTOOL_PORT ' ) ?: 3301 ;
24
27
$ this ->middleware = new Middleware ();
25
28
$ client = Client::fromDsn ("tcp:// $ host: $ port " )->withMiddleware ($ this ->middleware );
26
29
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
+
29
35
return $ mapper ;
30
36
}
31
37
32
38
public function testCache ()
33
39
{
34
- $ mapper = $ this ->createMapper ();
40
+ $ mapper = $ this ->createMapper (dropUserSpaces: false );
35
41
$ cache = new ArrayAdapter ();
36
42
$ mapper ->cache = $ cache ;
37
43
$ this ->assertCount (0 , $ cache ->getvalues ());
44
+ $ mapper ->dropUserSpaces ();
38
45
$ mapper ->find ('_vspace ' );
39
46
40
47
$ this ->assertNotCount (0 , $ cache ->getvalues ());
41
48
42
49
$ freshCounter = count ($ this ->middleware ->data );
43
50
44
- $ mapper = $ this ->createMapper ();
51
+ $ mapper = $ this ->createMapper (dropUserSpaces: false );
45
52
$ mapper ->cache = $ cache ;
53
+ $ mapper ->dropUserSpaces ();
46
54
$ mapper ->find ('_vspace ' );
47
55
48
56
// 4 requests:
@@ -54,11 +62,6 @@ public function testCache()
54
62
public function testDifferentIndexPartConfiguration ()
55
63
{
56
64
$ mapper = $ this ->createMapper ();
57
- foreach ($ mapper ->find ('_vspace ' ) as $ space ) {
58
- if ($ space ->id >= 512 ) {
59
- $ mapper ->getSpace ($ space ->id )->drop ();
60
- }
61
- }
62
65
63
66
$ tester = $ mapper ->createSpace ('tester ' );
64
67
$ tester ->addProperty ('id ' , 'unsigned ' );
@@ -96,11 +99,6 @@ public function testDifferentIndexPartConfiguration()
96
99
public function testCreateRow ()
97
100
{
98
101
$ mapper = $ this ->createMapper ();
99
- foreach ($ mapper ->find ('_vspace ' ) as $ space ) {
100
- if ($ space ->id >= 512 ) {
101
- $ mapper ->getSpace ($ space ->id )->drop ();
102
- }
103
- }
104
102
105
103
// No 'id' field, sequence isn't created
106
104
$ tester = $ mapper ->createSpace ('tester ' );
@@ -154,16 +152,7 @@ public function testCreateRow()
154
152
155
153
public function testIndexCasting ()
156
154
{
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 );
167
156
$ tester = $ mapper ->createSpace ('tester ' );
168
157
169
158
$ tester ->addProperty ('id ' , 'unsigned ' );
@@ -187,12 +176,6 @@ public function testIndexCasting()
187
176
public function testFindOrCreateRow ()
188
177
{
189
178
$ mapper = $ this ->createMapper ();
190
- foreach ($ mapper ->find ('_vspace ' ) as $ space ) {
191
- if ($ space ->id >= 512 ) {
192
- $ mapper ->getSpace ($ space ->id )->drop ();
193
- }
194
- }
195
-
196
179
$ tester = $ mapper ->createSpace ('tester ' );
197
180
198
181
//id is not first field, sequence isn't created
@@ -268,11 +251,6 @@ public function testSpaces()
268
251
echo PHP_EOL ;
269
252
$ mapper = $ this ->createMapper ();
270
253
271
- foreach ($ mapper ->find ('_vspace ' ) as $ space ) {
272
- if ($ space ->id >= 512 ) {
273
- $ mapper ->getSpace ($ space ->id )->drop ();
274
- }
275
- }
276
254
277
255
$ userTypes = [
278
256
'constructor ' => TypedConstructor::class,
0 commit comments