@@ -292,24 +292,44 @@ public function testQueryStringResolvesWithResultWithTypeStringAndRunsUntilQuit(
292
292
$ this ->assertSame (array (array ('value ' => 'hellö ' )), $ data );
293
293
}
294
294
295
+ public function provideSqlDataWillBeReturnedWithType ()
296
+ {
297
+ return array_merge (
298
+ [
299
+ ['42 ' , 42 ],
300
+ ['2.5 ' , 2.5 ],
301
+ ['null ' , null ],
302
+ ['"hello" ' , 'hello ' ],
303
+ ['"hellö" ' , 'hellö ' ]
304
+ ],
305
+ (PHP_VERSION_ID < 50606 ) ? [] : [
306
+ // preserving zero fractions is only supported as of PHP 5.6.6
307
+ ['1.0 ' , 1.0 ]
308
+ ],
309
+ (SQLite3::version ()['versionNumber ' ] < 3023000 ) ? [] : [
310
+ // boolean identifiers exist only as of SQLite 3.23.0 (2018-04-02)
311
+ // @link https://www.sqlite.org/lang_expr.html#booleanexpr
312
+ ['true ' , 1 ],
313
+ ['false ' , 0 ]
314
+ ]
315
+ );
316
+ }
317
+
295
318
/**
296
- * @dataProvider provideSocketFlags
297
- * @param bool $flag
319
+ * @dataProvider provideSqlDataWillBeReturnedWithType
320
+ * @param mixed $value
321
+ * @param mixed $expected
298
322
*/
299
- public function testQueryIntegerPlaceholderPositionalResolvesWithResultWithTypeIntegerAndRunsUntilQuit ( $ flag )
323
+ public function testQueryValueInStatementResolvesWithResultWithTypeAndRunsUntilQuit ( $ value , $ expected )
300
324
{
301
325
$ loop = React \EventLoop \Factory::create ();
302
326
$ factory = new Factory ($ loop );
303
327
304
- $ ref = new ReflectionProperty ($ factory , 'useSocket ' );
305
- $ ref ->setAccessible (true );
306
- $ ref ->setValue ($ factory , $ flag );
307
-
308
328
$ promise = $ factory ->open (':memory: ' );
309
329
310
330
$ data = null ;
311
- $ promise ->then (function (DatabaseInterface $ db ) use (&$ data ){
312
- $ db ->query ('SELECT ? AS value ' , array ( 1 ) )->then (function (Result $ result ) use (&$ data ) {
331
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data, $ value ){
332
+ $ db ->query ('SELECT ' . $ value . ' AS value ' )->then (function (Result $ result ) use (&$ data ) {
313
333
$ data = $ result ->rows ;
314
334
});
315
335
@@ -318,27 +338,66 @@ public function testQueryIntegerPlaceholderPositionalResolvesWithResultWithTypeI
318
338
319
339
$ loop ->run ();
320
340
321
- $ this ->assertSame (array (array ('value ' => 1 )), $ data );
341
+ $ this ->assertSame (array (array ('value ' => $ expected )), $ data );
342
+ }
343
+
344
+ public function provideDataWillBeReturnedWithType ()
345
+ {
346
+ return array_merge (
347
+ [
348
+ [0 ],
349
+ [1 ],
350
+ [1.5 ],
351
+ [null ],
352
+ ['hello ' ],
353
+ ['hellö ' ]
354
+ ],
355
+ (PHP_VERSION_ID < 50606 ) ? [] : [
356
+ // preserving zero fractions is only supported as of PHP 5.6.6
357
+ [1.0 ]
358
+ ]
359
+ );
322
360
}
323
361
324
362
/**
325
- * @dataProvider provideSocketFlags
326
- * @param bool $flag
363
+ * @dataProvider provideDataWillBeReturnedWithType
364
+ * @param mixed $value
327
365
*/
328
- public function testQueryIntegerPlaceholderNamedResolvesWithResultWithTypeIntegerAndRunsUntilQuit ( $ flag )
366
+ public function testQueryValuePlaceholderPositionalResolvesWithResultWithExactTypeAndRunsUntilQuit ( $ value )
329
367
{
330
368
$ loop = React \EventLoop \Factory::create ();
331
369
$ factory = new Factory ($ loop );
332
370
333
- $ ref = new ReflectionProperty ($ factory , 'useSocket ' );
334
- $ ref ->setAccessible (true );
335
- $ ref ->setValue ($ factory , $ flag );
371
+ $ promise = $ factory ->open (':memory: ' );
372
+
373
+ $ data = null ;
374
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data , $ value ){
375
+ $ db ->query ('SELECT ? AS value ' , array ($ value ))->then (function (Result $ result ) use (&$ data ) {
376
+ $ data = $ result ->rows ;
377
+ });
378
+
379
+ $ db ->quit ();
380
+ });
381
+
382
+ $ loop ->run ();
383
+
384
+ $ this ->assertSame (array (array ('value ' => $ value )), $ data );
385
+ }
386
+
387
+ /**
388
+ * @dataProvider provideDataWillBeReturnedWithType
389
+ * @param mixed $value
390
+ */
391
+ public function testQueryValuePlaceholderNamedResolvesWithResultWithExactTypeAndRunsUntilQuit ($ value )
392
+ {
393
+ $ loop = React \EventLoop \Factory::create ();
394
+ $ factory = new Factory ($ loop );
336
395
337
396
$ promise = $ factory ->open (':memory: ' );
338
397
339
398
$ data = null ;
340
- $ promise ->then (function (DatabaseInterface $ db ) use (&$ data ){
341
- $ db ->query ('SELECT :value AS value ' , array ('value ' => 1 ))->then (function (Result $ result ) use (&$ data ) {
399
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data, $ value ){
400
+ $ db ->query ('SELECT :value AS value ' , array ('value ' => $ value ))->then (function (Result $ result ) use (&$ data ) {
342
401
$ data = $ result ->rows ;
343
402
});
344
403
@@ -347,27 +406,64 @@ public function testQueryIntegerPlaceholderNamedResolvesWithResultWithTypeIntege
347
406
348
407
$ loop ->run ();
349
408
350
- $ this ->assertSame (array (array ('value ' => 1 )), $ data );
409
+ $ this ->assertSame (array (array ('value ' => $ value )), $ data );
410
+ }
411
+
412
+ public function provideDataWillBeReturnedWithOtherType ()
413
+ {
414
+ return array_merge (
415
+ [
416
+ [true , 1 ],
417
+ [false , 0 ],
418
+ ],
419
+ (PHP_VERSION_ID >= 50606 ) ? [] : [
420
+ // preserving zero fractions is supported as of PHP 5.6.6, otherwise cast to int
421
+ [1.0 , 1 ]
422
+ ]
423
+ );
351
424
}
352
425
353
426
/**
354
- * @dataProvider provideSocketFlags
355
- * @param bool $flag
427
+ * @dataProvider provideDataWillBeReturnedWithOtherType
428
+ * @param mixed $value
429
+ * @param mixed $expected
356
430
*/
357
- public function testQueryNullPlaceholderPositionalResolvesWithResultWithTypeNullAndRunsUntilQuit ( $ flag )
431
+ public function testQueryValuePlaceholderPositionalResolvesWithResultWithOtherTypeAndRunsUntilQuit ( $ value , $ expected )
358
432
{
359
433
$ loop = React \EventLoop \Factory::create ();
360
434
$ factory = new Factory ($ loop );
361
435
362
- $ ref = new ReflectionProperty ($ factory , 'useSocket ' );
363
- $ ref ->setAccessible (true );
364
- $ ref ->setValue ($ factory , $ flag );
436
+ $ promise = $ factory ->open (':memory: ' );
437
+
438
+ $ data = null ;
439
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data , $ value ){
440
+ $ db ->query ('SELECT ? AS value ' , array ($ value ))->then (function (Result $ result ) use (&$ data ) {
441
+ $ data = $ result ->rows ;
442
+ });
443
+
444
+ $ db ->quit ();
445
+ });
446
+
447
+ $ loop ->run ();
448
+
449
+ $ this ->assertSame (array (array ('value ' => $ expected )), $ data );
450
+ }
451
+
452
+ /**
453
+ * @dataProvider provideDataWillBeReturnedWithOtherType
454
+ * @param mixed $value
455
+ * @param mixed $expected
456
+ */
457
+ public function testQueryValuePlaceholderNamedResolvesWithResultWithOtherTypeAndRunsUntilQuit ($ value , $ expected )
458
+ {
459
+ $ loop = React \EventLoop \Factory::create ();
460
+ $ factory = new Factory ($ loop );
365
461
366
462
$ promise = $ factory ->open (':memory: ' );
367
463
368
464
$ data = null ;
369
- $ promise ->then (function (DatabaseInterface $ db ) use (&$ data ){
370
- $ db ->query ('SELECT ? AS value ' , array (null ))->then (function (Result $ result ) use (&$ data ) {
465
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data, $ value ){
466
+ $ db ->query ('SELECT :value AS value ' , array (' value ' => $ value ))->then (function (Result $ result ) use (&$ data ) {
371
467
$ data = $ result ->rows ;
372
468
});
373
469
@@ -376,7 +472,7 @@ public function testQueryNullPlaceholderPositionalResolvesWithResultWithTypeNull
376
472
377
473
$ loop ->run ();
378
474
379
- $ this ->assertSame (array (array ('value ' => null )), $ data );
475
+ $ this ->assertSame (array (array ('value ' => $ expected )), $ data );
380
476
}
381
477
382
478
/**
0 commit comments