Browse Source

Remove reflection

Maurits van der Schee 7 years ago
parent
commit
ee1e2e3383

+ 4
- 8
tests/Config.php.dist View File

@@ -9,30 +9,26 @@ class Config
9 9
      * @var array
10 10
      */
11 11
     public static $config = array(
12
-        array(
13
-            'dbengine' => 'MySQL',              // 'MySQL', 'SQLServer', 'PostgreSQL' or 'SQLite'
12
+        'MySQL' => array(
14 13
             'hostname' => '{{test_hostname}}',  // 'localhost' for MySQL, '(Local)' for SQLServer, empty for SQLite
15 14
             'username' => '{{test_username}}',  // May be empty on SQLServer or SQLite
16 15
             'password' => '{{test_password}}',  // May be empty on SQLServer or SQLite
17 16
             'database' => '{{test_database}}',  // NB: Use an empty database, data will be LOST!
18 17
         ),
19 18
         /* Uncomment and update for any databases you want to use.
20
-        array(
21
-            'dbengine' => 'PostgreSQL',
19
+        'PostgreSQL' => array(
22 20
             'hostname' => '{{test_hostname}}',
23 21
             'username' => '{{test_username}}',
24 22
             'password' => '{{test_password}}',
25 23
             'database' => '{{test_database}}',
26 24
         ),
27
-        array(
28
-            'dbengine' => 'SQLite',
25
+        'SQLite' => array(
29 26
             'hostname' => '{{test_hostname}}',
30 27
             'username' => '{{test_username}}',
31 28
             'password' => '{{test_password}}',
32 29
             'database' => '{{test_database}}',
33 30
         ),
34
-        array(
35
-            'dbengine' => 'SQLServer',
31
+        'SQLServer' => array(
36 32
             'hostname' => '{{test_hostname}}',
37 33
             'username' => '{{test_username}}',
38 34
             'password' => '{{test_password}}',

+ 3
- 11
tests/Config.php.travis View File

@@ -9,27 +9,19 @@ class Config
9 9
      * @var array
10 10
      */
11 11
     public static $config = array(
12
-        /* MySQL is disabled because v5.7 is required for all tests to pass,
13
-            and Travis only has up to MySQL 5.6 installed by default. This
14
-            will be runnable once we have a test suite that adapts to the
15
-            available MySQL version. See: https://github.com/mevdschee/php-crud-api/issues/194
16
-        array(
17
-            'dbengine' => 'MySQL',
12
+        'MySQL' => array(
18 13
             'hostname' => 'localhost',
19 14
             'username' => 'root',
20 15
             'password' => 'travis',
21 16
             'database' => 'testing',
22 17
         ),
23
-        */
24
-        array(
25
-            'dbengine' => 'PostgreSQL',
18
+        'PostgreSQL' => array(
26 19
             'hostname' => 'localhost',
27 20
             'username' => 'postgres',
28 21
             'password' => '',
29 22
             'database' => 'testing',
30 23
         ),
31
-        array(
32
-            'dbengine' => 'SQLite',
24
+        'SQLite' => array(
33 25
             'hostname' => '',
34 26
             'username' => '',
35 27
             'password' => '',

+ 2
- 0
tests/MysqlTest.php View File

@@ -4,6 +4,8 @@ require_once(__DIR__ . '/Tests.php');
4 4
 
5 5
 class MysqlTest extends Tests
6 6
 {
7
+    const NAME = 'MySQL';
8
+
7 9
     /**
8 10
      * Connects to the Database
9 11
      *

+ 2
- 0
tests/PostgresqlTest.php View File

@@ -4,6 +4,8 @@ require_once(__DIR__ . '/Tests.php');
4 4
 
5 5
 class PostgresqlTest extends Tests
6 6
 {
7
+    const NAME = 'PostgreSQL';
8
+
7 9
     /**
8 10
      * Connects to the Database
9 11
      *

+ 2
- 0
tests/SqlServerTest.php View File

@@ -4,6 +4,8 @@ require_once(__DIR__ . '/Tests.php');
4 4
 
5 5
 class SqlServerTest extends Tests
6 6
 {
7
+    const NAME = 'SQLServer';
8
+
7 9
     /**
8 10
      * Connects to the Database
9 11
      *

+ 2
- 0
tests/SqliteTest.php View File

@@ -4,6 +4,8 @@ require_once(__DIR__ . '/Tests.php');
4 4
 
5 5
 class SqliteTest extends Tests
6 6
 {
7
+    const NAME = 'SQLite';
8
+
7 9
     /**
8 10
      * Connects to the Database
9 11
      *

+ 8
- 15
tests/TestBase.php View File

@@ -4,23 +4,12 @@ require_once(__DIR__ . '/Config.php');
4 4
 
5 5
 abstract class TestBase extends PHPUnit_Framework_TestCase
6 6
 {
7
-    protected function getConfig()
8
-    {
9
-        $dbengine = strtolower(substr(get_called_class(),0,-4));
10
-        foreach (Config::$config as $database) {
11
-            if (strtolower($database['dbengine']) == $dbengine) {
12
-                if ($database['database']!='{{test_database}}') {
13
-                    return $database;
14
-                }
15
-            }
16
-        }
17
-        self::markTestSkipped("Configuration for '{$dbengine}' in 'Config.php' not found.");
18
-        return false;
19
-    }
20
-
21 7
     public static function setUpBeforeClass()
22 8
     {
23
-        $config = self::getConfig();
9
+        if (!Config::$config || !isset(Config::$config[static::NAME])) {
10
+            self::markTestSkipped("Configuration in 'Config.php' not found.");
11
+        }
12
+        $config = Config::$config[static::NAME];
24 13
         $db = static::connect($config);
25 14
         static::checkVersion($db);
26 15
         $capabilities = static::getCapabilities($db);
@@ -37,6 +26,10 @@ abstract class TestBase extends PHPUnit_Framework_TestCase
37 26
     const GIS = 1;
38 27
     const JSON = 2;
39 28
 
29
+    public abstract function connect($db);
30
+
31
+    public abstract function disconnect($db);
32
+
40 33
     public abstract function checkVersion($db);
41 34
 
42 35
     public abstract function getCapabilities($db);

+ 82
- 81
tests/Tests.php View File

@@ -22,10 +22,11 @@ class API
22 22
      */
23 23
     protected $api;
24 24
 
25
-    public function __construct($test, $config)
25
+    public function __construct($test)
26 26
     {
27 27
         $this->test = $test;
28
-        $this->config = $config;
28
+        $this->config = $test::$config;
29
+        $this->config['dbengine'] = $test::NAME;
29 30
     }
30 31
 
31 32
     private function action($method,$url,$data='')
@@ -117,56 +118,56 @@ abstract class Tests extends TestBase
117 118
 {
118 119
     public function testListPosts()
119 120
     {
120
-        $test = new API($this, static::$config);
121
+        $test = new API($this);
121 122
         $test->get('/posts');
122 123
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"It works!"]]}}');
123 124
     }
124 125
 
125 126
     public function testListPostColumns()
126 127
     {
127
-        $test = new API($this, static::$config);
128
+        $test = new API($this);
128 129
         $test->get('/posts?columns=id,content');
129 130
         $test->expect('{"posts":{"columns":["id","content"],"records":[[1,"blog started"],[2,"It works!"]]}}');
130 131
     }
131 132
 
132 133
     public function testListPostsWithTransform()
133 134
     {
134
-        $test = new API($this, static::$config);
135
+        $test = new API($this);
135 136
         $test->get('/posts?transform=1');
136 137
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":2,"user_id":1,"category_id":2,"content":"It works!"}]}');
137 138
     }
138 139
 
139 140
     public function testReadPost()
140 141
     {
141
-        $test = new API($this, static::$config);
142
+        $test = new API($this);
142 143
         $test->get('/posts/2');
143 144
         $test->expect('{"id":2,"user_id":1,"category_id":2,"content":"It works!"}');
144 145
     }
145 146
 
146 147
     public function testReadPosts()
147 148
     {
148
-        $test = new API($this, static::$config);
149
+        $test = new API($this);
149 150
         $test->get('/posts/1,2');
150 151
         $test->expect('[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":2,"user_id":1,"category_id":2,"content":"It works!"}]');
151 152
     }
152 153
 
153 154
     public function testReadPostColumns()
154 155
     {
155
-        $test = new API($this, static::$config);
156
+        $test = new API($this);
156 157
         $test->get('/posts/2?columns=id,content');
157 158
         $test->expect('{"id":2,"content":"It works!"}');
158 159
     }
159 160
 
160 161
     public function testAddPost()
161 162
     {
162
-        $test = new API($this, static::$config);
163
+        $test = new API($this);
163 164
         $test->post('/posts','{"user_id":1,"category_id":1,"content":"test"}');
164 165
         $test->expect('3');
165 166
     }
166 167
 
167 168
     public function testEditPost()
168 169
     {
169
-        $test = new API($this, static::$config);
170
+        $test = new API($this);
170 171
         $test->put('/posts/3','{"user_id":1,"category_id":1,"content":"test (edited)"}');
171 172
         $test->expect('1');
172 173
         $test->get('/posts/3');
@@ -175,7 +176,7 @@ abstract class Tests extends TestBase
175 176
 
176 177
     public function testEditPostColumnsMissingField()
177 178
     {
178
-        $test = new API($this, static::$config);
179
+        $test = new API($this);
179 180
         $test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
180 181
         $test->expect('1');
181 182
         $test->get('/posts/3');
@@ -184,7 +185,7 @@ abstract class Tests extends TestBase
184 185
 
185 186
     public function testEditPostColumnsExtraField()
186 187
     {
187
-        $test = new API($this, static::$config);
188
+        $test = new API($this);
188 189
         $test->put('/posts/3?columns=id,content','{"user_id":2,"content":"test (edited 3)"}');
189 190
         $test->expect('1');
190 191
         $test->get('/posts/3');
@@ -194,7 +195,7 @@ abstract class Tests extends TestBase
194 195
     public function testEditPostWithUtf8Content()
195 196
     {
196 197
         $utf8 = json_encode('Hello world, Καλημέρα κόσμε, コンニチハ');
197
-        $test = new API($this, static::$config);
198
+        $test = new API($this);
198 199
         $test->put('/posts/2','{"content":'.$utf8.'}');
199 200
         $test->expect('1');
200 201
         $test->get('/posts/2');
@@ -206,7 +207,7 @@ abstract class Tests extends TestBase
206 207
         $utf8 = '€ Hello world, Καλημέρα κόσμε, コンニチハ';
207 208
         $url_encoded = urlencode($utf8);
208 209
         $json_encoded = json_encode($utf8);
209
-        $test = new API($this, static::$config);
210
+        $test = new API($this);
210 211
         $test->put('/posts/2','content='.$url_encoded);
211 212
         $test->expect('1');
212 213
         $test->get('/posts/2');
@@ -215,7 +216,7 @@ abstract class Tests extends TestBase
215 216
 
216 217
     public function testDeletePost()
217 218
     {
218
-        $test = new API($this, static::$config);
219
+        $test = new API($this);
219 220
         $test->delete('/posts/3');
220 221
         $test->expect('1');
221 222
         $test->get('/posts/3');
@@ -224,14 +225,14 @@ abstract class Tests extends TestBase
224 225
 
225 226
     public function testAddPostWithPost()
226 227
     {
227
-        $test = new API($this, static::$config);
228
+        $test = new API($this);
228 229
         $test->post('/posts','user_id=1&category_id=1&content=test');
229 230
         $test->expect('4');
230 231
     }
231 232
 
232 233
     public function testEditPostWithPost()
233 234
     {
234
-        $test = new API($this, static::$config);
235
+        $test = new API($this);
235 236
         $test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
236 237
         $test->expect('1');
237 238
         $test->get('/posts/4');
@@ -240,7 +241,7 @@ abstract class Tests extends TestBase
240 241
 
241 242
     public function testDeletePostWithPost()
242 243
     {
243
-        $test = new API($this, static::$config);
244
+        $test = new API($this);
244 245
         $test->delete('/posts/4');
245 246
         $test->expect('1');
246 247
         $test->get('/posts/4');
@@ -249,7 +250,7 @@ abstract class Tests extends TestBase
249 250
 
250 251
     public function testListWithPaginate()
251 252
     {
252
-        $test = new API($this, static::$config);
253
+        $test = new API($this);
253 254
         for ($i=1;$i<=10;$i++) {
254 255
             $test->post('/posts','{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
255 256
             $test->expect(4+$i);
@@ -260,56 +261,56 @@ abstract class Tests extends TestBase
260 261
 
261 262
     public function testListWithPaginateInMultipleOrder()
262 263
     {
263
-        $test = new API($this, static::$config);
264
+        $test = new API($this);
264 265
         $test->get('/posts?page=1,2&order[]=category_id,asc&order[]=id,desc');
265 266
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[14,1,1,"#10"],[12,1,1,"#8"]],"results":11}}');
266 267
     }
267 268
 
268 269
     public function testListWithPaginateInDescendingOrder()
269 270
     {
270
-        $test = new API($this, static::$config);
271
+        $test = new API($this);
271 272
         $test->get('/posts?page=2,2&order=id,desc');
272 273
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[11,1,1,"#7"],[10,1,1,"#6"]],"results":11}}');
273 274
     }
274 275
 
275 276
     public function testListWithPaginateLastPage()
276 277
     {
277
-        $test = new API($this, static::$config);
278
+        $test = new API($this);
278 279
         $test->get('/posts?page=3,5&order=id');
279 280
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[14,1,1,"#10"]],"results":11}}');
280 281
     }
281 282
 
282 283
     public function testListExampleFromReadmeFullRecord()
283 284
     {
284
-        $test = new API($this, static::$config);
285
+        $test = new API($this);
285 286
         $test->get('/posts?filter=id,eq,1');
286 287
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"]]}}');
287 288
     }
288 289
 
289 290
     public function testListExampleFromReadmeWithExclude()
290 291
     {
291
-        $test = new API($this, static::$config);
292
+        $test = new API($this);
292 293
         $test->get('/posts?exclude=id&filter=id,eq,1');
293 294
         $test->expect('{"posts":{"columns":["user_id","category_id","content"],"records":[[1,1,"blog started"]]}}');
294 295
     }
295 296
 
296 297
     public function testListExampleFromReadme()
297 298
     {
298
-        $test = new API($this, static::$config);
299
+        $test = new API($this);
299 300
         $test->get('/posts?include=categories,tags,comments&filter=id,eq,1');
300 301
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2]]},"categories":{"relations":{"id":"posts.category_id"},"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]},"comments":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","message"],"records":[[1,1,"great"],[2,1,"fantastic"]]}}');
301 302
     }
302 303
 
303 304
     public function testListExampleFromReadmeWithTransform()
304 305
     {
305
-        $test = new API($this, static::$config);
306
+        $test = new API($this);
306 307
         $test->get('/posts?include=categories,tags,comments&filter=id,eq,1&transform=1');
307 308
         $test->expect('{"posts":[{"id":1,"post_tags":[{"id":1,"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"id":2,"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}],"comments":[{"id":1,"post_id":1,"message":"great"},{"id":2,"post_id":1,"message":"fantastic"}],"user_id":1,"category_id":1,"categories":[{"id":1,"name":"announcement","icon":null}],"content":"blog started"}]}');
308 309
     }
309 310
 
310 311
     public function testListExampleFromReadmeWithTransformWithExclude()
311 312
     {
312
-        $test = new API($this, static::$config);
313
+        $test = new API($this);
313 314
         $test->get('/posts?include=categories,tags,comments&exclude=comments.message&filter=id,eq,1&transform=1');
314 315
         $test->expect('{"posts":[{"id":1,"post_tags":[{"id":1,"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"id":2,"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}],"comments":[{"id":1,"post_id":1},{"id":2,"post_id":1}],"user_id":1,"category_id":1,"categories":[{"id":1,"name":"announcement","icon":null}],"content":"blog started"}]}');
315 316
     }
@@ -318,7 +319,7 @@ abstract class Tests extends TestBase
318 319
     {
319 320
         $binary = base64_encode("\0abc\0\n\r\b\0");
320 321
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
321
-        $test = new API($this, static::$config);
322
+        $test = new API($this);
322 323
         $test->put('/categories/2','{"icon":"'.$base64url.'"}');
323 324
         $test->expect('1');
324 325
         $test->get('/categories/2');
@@ -327,7 +328,7 @@ abstract class Tests extends TestBase
327 328
 
328 329
     public function testEditCategoryWithNull()
329 330
     {
330
-        $test = new API($this, static::$config);
331
+        $test = new API($this);
331 332
         $test->put('/categories/2','{"icon":null}');
332 333
         $test->expect('1');
333 334
         $test->get('/categories/2');
@@ -338,7 +339,7 @@ abstract class Tests extends TestBase
338 339
     {
339 340
         $binary = base64_encode("€ \0abc\0\n\r\b\0");
340 341
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
341
-        $test = new API($this, static::$config);
342
+        $test = new API($this);
342 343
         $test->put('/categories/2','icon='.$base64url);
343 344
         $test->expect('1');
344 345
         $test->get('/categories/2');
@@ -347,14 +348,14 @@ abstract class Tests extends TestBase
347 348
 
348 349
     public function testListCategoriesWithBinaryContent()
349 350
     {
350
-        $test = new API($this, static::$config);
351
+        $test = new API($this);
351 352
         $test->get('/categories');
352 353
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null],[2,"article","4oKsIABhYmMACg1cYgA="]]}}');
353 354
     }
354 355
 
355 356
     public function testEditCategoryWithNullWithPost()
356 357
     {
357
-        $test = new API($this, static::$config);
358
+        $test = new API($this);
358 359
         $test->put('/categories/2','icon__is_null');
359 360
         $test->expect('1');
360 361
         $test->get('/categories/2');
@@ -363,35 +364,35 @@ abstract class Tests extends TestBase
363 364
 
364 365
     public function testAddPostFailure()
365 366
     {
366
-        $test = new API($this, static::$config);
367
+        $test = new API($this);
367 368
         $test->post('/posts','{"user_id":"a","category_id":1,"content":"tests"}');
368 369
         $test->expect('null');
369 370
     }
370 371
 
371 372
     public function testOptionsRequest()
372 373
     {
373
-        $test = new API($this, static::$config);
374
+        $test = new API($this);
374 375
         $test->options('/posts/2');
375 376
         $test->expect('["Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN","Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH","Access-Control-Allow-Credentials: true","Access-Control-Max-Age: 1728000"]',false);
376 377
     }
377 378
 
378 379
     public function testHidingPasswordColumn()
379 380
     {
380
-        $test = new API($this, static::$config);
381
+        $test = new API($this);
381 382
         $test->get('/users?filter=id,eq,1&transform=1');
382 383
         $test->expect('{"users":[{"id":1,"username":"user1","location":null}]}');
383 384
     }
384 385
 
385 386
     public function testValidatorErrorMessage()
386 387
     {
387
-        $test = new API($this, static::$config);
388
+        $test = new API($this);
388 389
         $test->put('/posts/1','{"category_id":"a"}');
389 390
         $test->expect(false,'{"category_id":"must be numeric"}');
390 391
     }
391 392
 
392 393
     public function testSanitizerToStripTags()
393 394
     {
394
-        $test = new API($this, static::$config);
395
+        $test = new API($this);
395 396
         $test->put('/categories/2','{"name":"<script>alert();</script>"}');
396 397
         $test->expect('1');
397 398
         $test->get('/categories/2');
@@ -400,46 +401,46 @@ abstract class Tests extends TestBase
400 401
 
401 402
     public function testErrorOnInvalidJson()
402 403
     {
403
-        $test = new API($this, static::$config);
404
+        $test = new API($this);
404 405
         $test->post('/posts','{"}');
405 406
         $test->expect(false,'Not found (input)');
406 407
     }
407 408
 
408 409
     public function testErrorOnDuplicatePrimaryKey()
409 410
     {
410
-        $test = new API($this, static::$config);
411
+        $test = new API($this);
411 412
         $test->post('/posts','{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
412 413
         $test->expect('null');
413 414
     }
414 415
 
415 416
     public function testErrorOnFailingForeignKeyConstraint()
416 417
     {
417
-        $test = new API($this, static::$config);
418
+        $test = new API($this);
418 419
         $test->post('/posts','{"user_id":3,"category_id":1,"content":"fk constraint"}');
419 420
         $test->expect('null');
420 421
     }
421 422
 
422 423
     public function testMissingIntermediateTable()
423 424
     {
424
-        $test = new API($this, static::$config);
425
+        $test = new API($this);
425 426
         $test->get('/users?include=posts,tags');
426 427
         $test->expect('{"users":{"columns":["id","username","location"],"records":[[1,"user1",null]]},"posts":{"relations":{"user_id":"users.id"},"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"\u20ac Hello world, \u039a\u03b1\u03bb\u03b7\u03bc\u1f73\u03c1\u03b1 \u03ba\u1f79\u03c3\u03bc\u03b5, \u30b3\u30f3\u30cb\u30c1\u30cf"],[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"],[8,1,1,"#4"],[9,1,1,"#5"],[10,1,1,"#6"],[11,1,1,"#7"],[12,1,1,"#8"],[14,1,1,"#10"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2],[3,2,1],[4,2,2]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]}}');
427 428
     }
428 429
 
429 430
     public function testEditUserPassword()
430 431
     {
431
-        $test = new API($this, static::$config);
432
+        $test = new API($this);
432 433
         $test->put('/users/1','{"password":"testtest"}');
433 434
         $test->expect('1');
434 435
     }
435 436
 
436 437
     public function testEditUserLocation()
437 438
     {
438
-        $test = new API($this, static::$config);
439
+        $test = new API($this);
439 440
         $test->put('/users/1','{"location":"POINT(30 20)"}');
440 441
         $test->expect('1');
441 442
         $test->get('/users/1?columns=id,location');
442
-        if (static::$config['dbengine']=='SQLServer') {
443
+        if (static::NAME=='SQLServer') {
443 444
             $test->expect('{"id":1,"location":"POINT (30 20)"}');
444 445
         } else {
445 446
             $test->expect('{"id":1,"location":"POINT(30 20)"}');
@@ -448,9 +449,9 @@ abstract class Tests extends TestBase
448 449
 
449 450
     public function testListUserLocations()
450 451
     {
451
-        $test = new API($this, static::$config);
452
+        $test = new API($this);
452 453
         $test->get('/users?columns=id,location');
453
-        if (static::$config['dbengine']=='SQLServer') {
454
+        if (static::NAME=='SQLServer') {
454 455
             $test->expect('{"users":{"columns":["id","location"],"records":[[1,"POINT (30 20)"]]}}');
455 456
         } else {
456 457
             $test->expect('{"users":{"columns":["id","location"],"records":[[1,"POINT(30 20)"]]}}');
@@ -459,8 +460,8 @@ abstract class Tests extends TestBase
459 460
 
460 461
     public function testEditUserWithId()
461 462
     {
462
-        if (static::$config['dbengine']!='SQLServer') {
463
-            $test = new API($this, static::$config);
463
+        if (static::NAME!='SQLServer') {
464
+            $test = new API($this);
464 465
             $test->put('/users/1','{"id":2,"password":"testtest2"}');
465 466
             $test->expect('1');
466 467
             $test->get('/users/1?columns=id,username,password');
@@ -470,98 +471,98 @@ abstract class Tests extends TestBase
470 471
 
471 472
     public function testReadOtherUser()
472 473
     {
473
-        $test = new API($this, static::$config);
474
+        $test = new API($this);
474 475
         $test->get('/users/2');
475 476
         $test->expect(false,'Not found (object)');
476 477
     }
477 478
 
478 479
     public function testEditOtherUser()
479 480
     {
480
-        $test = new API($this, static::$config);
481
+        $test = new API($this);
481 482
         $test->put('/users/2','{"password":"testtest"}');
482 483
         $test->expect('0');
483 484
     }
484 485
 
485 486
     public function testFilterCategoryOnNullIcon()
486 487
     {
487
-        $test = new API($this, static::$config);
488
+        $test = new API($this);
488 489
         $test->get('/categories?filter[]=icon,is,null&transform=1');
489 490
         $test->expect('{"categories":[{"id":1,"name":"announcement","icon":null},{"id":2,"name":"alert();","icon":null}]}');
490 491
     }
491 492
 
492 493
     public function testFilterCategoryOnNotNullIcon()
493 494
     {
494
-        $test = new API($this, static::$config);
495
+        $test = new API($this);
495 496
         $test->get('/categories?filter[]=icon,nis,null&transform=1');
496 497
         $test->expect('{"categories":[]}');
497 498
     }
498 499
 
499 500
     public function testFilterPostsNotIn()
500 501
     {
501
-        $test = new API($this, static::$config);
502
+        $test = new API($this);
502 503
         $test->get('/posts?filter[]=id,nin,1,2,3,4,7,8,9,10,11,12,13,14&transform=1');
503 504
         $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
504 505
     }
505 506
 
506 507
     public function testFilterPostsBetween()
507 508
     {
508
-        $test = new API($this, static::$config);
509
+        $test = new API($this);
509 510
         $test->get('/posts?filter[]=id,bt,5,6&transform=1');
510 511
         $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
511 512
     }
512 513
 
513 514
     public function testFilterPostsNotBetween()
514 515
     {
515
-        $test = new API($this, static::$config);
516
+        $test = new API($this);
516 517
         $test->get('/posts?filter[]=id,nbt,2,13&transform=1');
517 518
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":14,"user_id":1,"category_id":1,"content":"#10"}]}');
518 519
     }
519 520
 
520 521
     public function testColumnsWithTable()
521 522
     {
522
-        $test = new API($this, static::$config);
523
+        $test = new API($this);
523 524
         $test->get('/posts?columns=posts.content&filter=id,eq,1&transform=1');
524 525
         $test->expect('{"posts":[{"content":"blog started"}]}');
525 526
     }
526 527
 
527 528
     public function testColumnsWithTableWildcard()
528 529
     {
529
-        $test = new API($this, static::$config);
530
+        $test = new API($this);
530 531
         $test->get('/posts?columns=posts.*&filter=id,eq,1&transform=1');
531 532
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"}]}');
532 533
     }
533 534
 
534 535
     public function testColumnsOnInclude()
535 536
     {
536
-        $test = new API($this, static::$config);
537
+        $test = new API($this);
537 538
         $test->get('/posts?include=categories&columns=categories.name&filter=id,eq,1&transform=1');
538 539
         $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1,"name":"announcement"}]}]}');
539 540
     }
540 541
 
541 542
     public function testFilterOnRelationAnd()
542 543
     {
543
-        $test = new API($this, static::$config);
544
+        $test = new API($this);
544 545
         $test->get('/categories?include=posts&filter[]=id,ge,1&filter[]=id,le,1&filter[]=id,le,2&filter[]=posts.id,lt,8&filter[]=posts.id,gt,4');
545 546
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"posts":{"relations":{"category_id":"categories.id"},"columns":["id","user_id","category_id","content"],"records":[[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"]]}}');
546 547
     }
547 548
 
548 549
     public function testFilterOnRelationOr()
549 550
     {
550
-        $test = new API($this, static::$config);
551
+        $test = new API($this);
551 552
         $test->get('/categories?include=posts&filter[]=id,ge,1&filter[]=id,le,1&filter[]=posts.id,eq,5&filter[]=posts.id,eq,6&filter[]=posts.id,eq,7&satisfy=all,posts.any');
552 553
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"posts":{"relations":{"category_id":"categories.id"},"columns":["id","user_id","category_id","content"],"records":[[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"]]}}');
553 554
     }
554 555
 
555 556
     public function testColumnsOnWrongInclude()
556 557
     {
557
-        $test = new API($this, static::$config);
558
+        $test = new API($this);
558 559
         $test->get('/posts?include=categories&columns=categories&filter=id,eq,1&transform=1');
559 560
         $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1}]}]}');
560 561
     }
561 562
 
562 563
     public function testColumnsOnImplicitJoin()
563 564
     {
564
-        $test = new API($this, static::$config);
565
+        $test = new API($this);
565 566
         $test->get('/posts?include=tags&columns=posts.id,tags.name&filter=id,eq,1&transform=1');
566 567
         $test->expect('{"posts":[{"id":1,"post_tags":[{"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}]}]}');
567 568
     }
@@ -569,7 +570,7 @@ abstract class Tests extends TestBase
569 570
     public function testSpatialFilterWithin()
570 571
     {
571 572
         if (static::$capabilities & self::GIS) {
572
-            $test = new API($this, static::$config);
573
+            $test = new API($this);
573 574
             $test->get('/users?columns=id,username&filter=location,swi,POINT(30 20)');
574 575
             $test->expect('{"users":{"columns":["id","username"],"records":[[1,"user1"]]}}');
575 576
         }
@@ -577,7 +578,7 @@ abstract class Tests extends TestBase
577 578
 
578 579
     public function testAddPostsWithNonExistingCategory()
579 580
     {
580
-        $test = new API($this, static::$config);
581
+        $test = new API($this);
581 582
         $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
582 583
         $test->expect('null');
583 584
         $test->get('/posts?columns=content&filter=content,eq,tests');
@@ -586,7 +587,7 @@ abstract class Tests extends TestBase
586 587
 
587 588
     public function testAddPosts()
588 589
     {
589
-        $test = new API($this, static::$config);
590
+        $test = new API($this);
590 591
         $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
591 592
         $test->expectAny();
592 593
         $test->get('/posts?columns=content&filter=content,eq,tests');
@@ -595,14 +596,14 @@ abstract class Tests extends TestBase
595 596
 
596 597
     public function testListEvents()
597 598
     {
598
-        $test = new API($this, static::$config);
599
+        $test = new API($this);
599 600
         $test->get('/events?columns=datetime');
600 601
         $test->expect('{"events":{"columns":["datetime"],"records":[["2016-01-01 13:01:01"]]}}');
601 602
     }
602 603
 
603 604
     public function testIncrementEventVisitors()
604 605
     {
605
-        $test = new API($this, static::$config);
606
+        $test = new API($this);
606 607
         $test->patch('/events/1','{"visitors":11}');
607 608
         $test->expect('1');
608 609
         $test->get('/events/1');
@@ -611,7 +612,7 @@ abstract class Tests extends TestBase
611 612
 
612 613
     public function testIncrementEventVisitorsWithZero()
613 614
     {
614
-        $test = new API($this, static::$config);
615
+        $test = new API($this);
615 616
         $test->patch('/events/1','{"visitors":0}');
616 617
         $test->expect('1');
617 618
         $test->get('/events/1');
@@ -620,7 +621,7 @@ abstract class Tests extends TestBase
620 621
 
621 622
     public function testDecrementEventVisitors()
622 623
     {
623
-        $test = new API($this, static::$config);
624
+        $test = new API($this);
624 625
         $test->patch('/events/1','{"visitors":-5}');
625 626
         $test->expect('1');
626 627
         $test->get('/events/1');
@@ -629,14 +630,14 @@ abstract class Tests extends TestBase
629 630
 
630 631
     public function testListTagUsage()
631 632
     {
632
-        $test = new API($this, static::$config);
633
+        $test = new API($this);
633 634
         $test->get('/tag_usage');
634 635
         $test->expect('{"tag_usage":{"columns":["name","count"],"records":[["funny",2],["important",2]]}}');
635 636
     }
636 637
 
637 638
     public function testUpdateMultipleTags()
638 639
     {
639
-        $test = new API($this, static::$config);
640
+        $test = new API($this);
640 641
         $test->get('/tags?transform=1');
641 642
         $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
642 643
         $test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
@@ -645,7 +646,7 @@ abstract class Tests extends TestBase
645 646
 
646 647
     public function testUpdateMultipleTagsTooManyIds()
647 648
     {
648
-        $test = new API($this, static::$config);
649
+        $test = new API($this);
649 650
         $test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
650 651
         $test->expect(false,'Not found (subject)');
651 652
         $test->get('/tags?transform=1');
@@ -654,7 +655,7 @@ abstract class Tests extends TestBase
654 655
 
655 656
     public function testUpdateMultipleTagsWithoutFields()
656 657
     {
657
-        $test = new API($this, static::$config);
658
+        $test = new API($this);
658 659
         $test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
659 660
         $test->expect('null');
660 661
         $test->get('/tags?transform=1');
@@ -663,7 +664,7 @@ abstract class Tests extends TestBase
663 664
 
664 665
     public function testDeleteMultipleTags()
665 666
     {
666
-        $test = new API($this, static::$config);
667
+        $test = new API($this);
667 668
         $test->post('/tags','[{"name":"extra"},{"name":"more"}]');
668 669
         $test->expect('[3,4]');
669 670
         $test->delete('/tags/3,4');
@@ -674,14 +675,14 @@ abstract class Tests extends TestBase
674 675
 
675 676
     public function testListProducts()
676 677
     {
677
-        $test = new API($this, static::$config);
678
+        $test = new API($this);
678 679
         $test->get('/products?columns=id,name,price&transform=1');
679 680
         $test->expect('{"products":[{"id":1,"name":"Calculator","price":"23.01"}]}');
680 681
     }
681 682
 
682 683
     public function testListProductsProperties()
683 684
     {
684
-        $test = new API($this, static::$config);
685
+        $test = new API($this);
685 686
         $test->get('/products?columns=id,properties&transform=1');
686 687
         if (static::$capabilities & self::JSON) {
687 688
             $test->expect('{"products":[{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}]}');
@@ -692,7 +693,7 @@ abstract class Tests extends TestBase
692 693
 
693 694
     public function testReadProductProperties()
694 695
     {
695
-        $test = new API($this, static::$config);
696
+        $test = new API($this);
696 697
         $test->get('/products/1?columns=id,properties');
697 698
         if (static::$capabilities & self::JSON) {
698 699
             $test->expect('{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}');
@@ -703,7 +704,7 @@ abstract class Tests extends TestBase
703 704
 
704 705
     public function testWriteProductProperties()
705 706
     {
706
-        $test = new API($this, static::$config);
707
+        $test = new API($this);
707 708
         if (static::$capabilities & self::JSON) {
708 709
             $test->put('/products/1','{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
709 710
         } else {
@@ -720,7 +721,7 @@ abstract class Tests extends TestBase
720 721
 
721 722
     public function testAddProducts()
722 723
     {
723
-        $test = new API($this, static::$config);
724
+        $test = new API($this);
724 725
         if (static::$capabilities & self::JSON) {
725 726
             $test->post('/products','{"name":"Laptop","price":"1299.99","properties":{}}');
726 727
         } else {
@@ -733,7 +734,7 @@ abstract class Tests extends TestBase
733 734
 
734 735
     public function testSoftDeleteProducts()
735 736
     {
736
-        $test = new API($this, static::$config);
737
+        $test = new API($this);
737 738
         $test->delete('/products/1,2');
738 739
         $test->expect('[1,1]');
739 740
         $test->get('/products?columns=id,deleted_at');
@@ -742,7 +743,7 @@ abstract class Tests extends TestBase
742 743
 
743 744
     public function testVarBinaryBarcodes()
744 745
     {
745
-        $test = new API($this, static::$config);
746
+        $test = new API($this);
746 747
         $test->get('/barcodes?transform=1');
747 748
         $test->expect('{"barcodes":[{"id":1,"product_id":1,"hex":"00ff01","bin":"AP8B"}]}');
748 749
     }

Loading…
Cancel
Save