@@ -279,24 +279,34 @@ public function testQueryStringResolvesWithResultWithTypeStringAndRunsUntilQuit(
279
279
$ this ->assertSame (array (array ('value ' => 'hellö ' )), $ data );
280
280
}
281
281
282
+ public function provideSqlDataWillBeReturnedWithType ()
283
+ {
284
+ return [
285
+ ['42 ' , 42 ],
286
+ ['1.5 ' , 1.5 ],
287
+ ['null ' , null ],
288
+ ['"hello" ' , 'hello ' ],
289
+ ['"hellö" ' , 'hellö ' ],
290
+ ['true ' , 1 ],
291
+ ['false ' , 0 ],
292
+ ];
293
+ }
294
+
282
295
/**
283
- * @dataProvider provideSocketFlags
284
- * @param bool $flag
296
+ * @dataProvider provideSqlDataWillBeReturnedWithType
297
+ * @param mixed $value
298
+ * @param mixed $expected
285
299
*/
286
- public function testQueryIntegerPlaceholderPositionalResolvesWithResultWithTypeIntegerAndRunsUntilQuit ( $ flag )
300
+ public function testQueryValueInStatementResolvesWithResultWithTypeAndRunsUntilQuit ( $ value , $ expected )
287
301
{
288
302
$ loop = React \EventLoop \Factory::create ();
289
303
$ factory = new Factory ($ loop );
290
304
291
- $ ref = new ReflectionProperty ($ factory , 'useSocket ' );
292
- $ ref ->setAccessible (true );
293
- $ ref ->setValue ($ factory , $ flag );
294
-
295
305
$ promise = $ factory ->open (':memory: ' );
296
306
297
307
$ data = null ;
298
- $ promise ->then (function (DatabaseInterface $ db ) use (&$ data ){
299
- $ db ->query ('SELECT ? AS value ' , array ( 1 ) )->then (function (Result $ result ) use (&$ data ) {
308
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data, $ value ){
309
+ $ db ->query ('SELECT ' . $ value . ' AS value ' )->then (function (Result $ result ) use (&$ data ) {
300
310
$ data = $ result ->rows ;
301
311
});
302
312
@@ -305,27 +315,60 @@ public function testQueryIntegerPlaceholderPositionalResolvesWithResultWithTypeI
305
315
306
316
$ loop ->run ();
307
317
308
- $ this ->assertSame (array (array ('value ' => 1 )), $ data );
318
+ $ this ->assertSame (array (array ('value ' => $ expected )), $ data );
319
+ }
320
+
321
+ public function provideDataWillBeReturnedWithType ()
322
+ {
323
+ return [
324
+ [0 ],
325
+ [1 ],
326
+ [1.5 ],
327
+ [null ],
328
+ ['hello ' ],
329
+ ['hellö ' ]
330
+ ];
309
331
}
310
332
311
333
/**
312
- * @dataProvider provideSocketFlags
313
- * @param bool $flag
334
+ * @dataProvider provideDataWillBeReturnedWithType
335
+ * @param mixed $value
314
336
*/
315
- public function testQueryIntegerPlaceholderNamedResolvesWithResultWithTypeIntegerAndRunsUntilQuit ( $ flag )
337
+ public function testQueryValuePlaceholderPositionalResolvesWithResultWithExactTypeAndRunsUntilQuit ( $ value )
316
338
{
317
339
$ loop = React \EventLoop \Factory::create ();
318
340
$ factory = new Factory ($ loop );
319
341
320
- $ ref = new ReflectionProperty ($ factory , 'useSocket ' );
321
- $ ref ->setAccessible (true );
322
- $ ref ->setValue ($ factory , $ flag );
342
+ $ promise = $ factory ->open (':memory: ' );
343
+
344
+ $ data = null ;
345
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data , $ value ){
346
+ $ db ->query ('SELECT ? AS value ' , array ($ value ))->then (function (Result $ result ) use (&$ data ) {
347
+ $ data = $ result ->rows ;
348
+ });
349
+
350
+ $ db ->quit ();
351
+ });
352
+
353
+ $ loop ->run ();
354
+
355
+ $ this ->assertSame (array (array ('value ' => $ value )), $ data );
356
+ }
357
+
358
+ /**
359
+ * @dataProvider provideDataWillBeReturnedWithType
360
+ * @param mixed $value
361
+ */
362
+ public function testQueryValuePlaceholderNamedResolvesWithResultWithExactTypeAndRunsUntilQuit ($ value )
363
+ {
364
+ $ loop = React \EventLoop \Factory::create ();
365
+ $ factory = new Factory ($ loop );
323
366
324
367
$ promise = $ factory ->open (':memory: ' );
325
368
326
369
$ data = null ;
327
- $ promise ->then (function (DatabaseInterface $ db ) use (&$ data ){
328
- $ db ->query ('SELECT :value AS value ' , array ('value ' => 1 ))->then (function (Result $ result ) use (&$ data ) {
370
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data, $ value ){
371
+ $ db ->query ('SELECT :value AS value ' , array ('value ' => $ value ))->then (function (Result $ result ) use (&$ data ) {
329
372
$ data = $ result ->rows ;
330
373
});
331
374
@@ -334,27 +377,59 @@ public function testQueryIntegerPlaceholderNamedResolvesWithResultWithTypeIntege
334
377
335
378
$ loop ->run ();
336
379
337
- $ this ->assertSame (array (array ('value ' => 1 )), $ data );
380
+ $ this ->assertSame (array (array ('value ' => $ value )), $ data );
381
+ }
382
+
383
+ public function provideDataWillBeReturnedWithOtherType ()
384
+ {
385
+ return [
386
+ 'true ' => [true , 1 ],
387
+ 'false ' => [false , 0 ],
388
+ 'float without fraction is int ' => [1.0 , 1 ]
389
+ ];
338
390
}
339
391
340
392
/**
341
- * @dataProvider provideSocketFlags
342
- * @param bool $flag
393
+ * @dataProvider provideDataWillBeReturnedWithOtherType
394
+ * @param mixed $value
395
+ * @param mixed $expected
343
396
*/
344
- public function testQueryNullPlaceholderPositionalResolvesWithResultWithTypeNullAndRunsUntilQuit ( $ flag )
397
+ public function testQueryValuePlaceholderPositionalResolvesWithResultWithOtherTypeAndRunsUntilQuit ( $ value , $ expected )
345
398
{
346
399
$ loop = React \EventLoop \Factory::create ();
347
400
$ factory = new Factory ($ loop );
348
401
349
- $ ref = new ReflectionProperty ($ factory , 'useSocket ' );
350
- $ ref ->setAccessible (true );
351
- $ ref ->setValue ($ factory , $ flag );
402
+ $ promise = $ factory ->open (':memory: ' );
403
+
404
+ $ data = null ;
405
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data , $ value ){
406
+ $ db ->query ('SELECT ? AS value ' , array ($ value ))->then (function (Result $ result ) use (&$ data ) {
407
+ $ data = $ result ->rows ;
408
+ });
409
+
410
+ $ db ->quit ();
411
+ });
412
+
413
+ $ loop ->run ();
414
+
415
+ $ this ->assertSame (array (array ('value ' => $ expected )), $ data );
416
+ }
417
+
418
+ /**
419
+ * @dataProvider provideDataWillBeReturnedWithOtherType
420
+ * @param mixed $value
421
+ * @param mixed $expected
422
+ */
423
+ public function testQueryValuePlaceholderNamedResolvesWithResultWithOtherTypeAndRunsUntilQuit ($ value , $ expected )
424
+ {
425
+ $ loop = React \EventLoop \Factory::create ();
426
+ $ factory = new Factory ($ loop );
352
427
353
428
$ promise = $ factory ->open (':memory: ' );
354
429
355
430
$ data = null ;
356
- $ promise ->then (function (DatabaseInterface $ db ) use (&$ data ){
357
- $ db ->query ('SELECT ? AS value ' , array (null ))->then (function (Result $ result ) use (&$ data ) {
431
+ $ promise ->then (function (DatabaseInterface $ db ) use (&$ data, $ value ){
432
+ $ db ->query ('SELECT :value AS value ' , array (' value ' => $ value ))->then (function (Result $ result ) use (&$ data ) {
358
433
$ data = $ result ->rows ;
359
434
});
360
435
@@ -363,7 +438,7 @@ public function testQueryNullPlaceholderPositionalResolvesWithResultWithTypeNull
363
438
364
439
$ loop ->run ();
365
440
366
- $ this ->assertSame (array (array ('value ' => null )), $ data );
441
+ $ this ->assertSame (array (array ('value ' => $ expected )), $ data );
367
442
}
368
443
369
444
/**
0 commit comments