forked from joomla-framework/database
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractDatabaseDriverTestCase.php
More file actions
1037 lines (892 loc) · 28.2 KB
/
AbstractDatabaseDriverTestCase.php
File metadata and controls
1037 lines (892 loc) · 28.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Database\Tests;
use Joomla\Database\DatabaseIterator;
use Joomla\Database\Monitor\ChainedMonitor;
use Joomla\Database\Monitor\DebugMonitor;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Test\DatabaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* Base test class for Joomla\Database\DatabaseDriver
*/
abstract class AbstractDatabaseDriverTestCase extends DatabaseTestCase
{
/**
* Loads the example data into the database.
*
* @return void
*/
protected function loadExampleData(): void
{
$data = [
(object) [
'id' => 1,
'title' => 'Testing1',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row one',
],
(object) [
'id' => 2,
'title' => 'Testing2',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row two',
],
(object) [
'id' => 3,
'title' => 'Testing3',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row three',
],
(object) [
'id' => 4,
'title' => 'Testing4',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row four',
],
];
foreach ($data as $row) {
static::$connection->insertObject('#__dbtest', $row);
}
}
/**
* @testdox The connection can be checked for encryption support
*/
public function testIsConnectionEncryptionSupported()
{
$this->assertTrue(
\is_bool(static::$connection->isConnectionEncryptionSupported()),
'The driver should report whether connection encryption is supported.'
);
}
/**
* Data provider for table dropping test cases
*
* @return array
*/
public static function dataDropTable(): array
{
return [
'database exists before query' => ['#__dbtest', true],
'database does not exist before query' => ['#__foo', false],
];
}
/**
* @testdox A database table can be dropped
*
* @param string $table The name of the database table to drop.
* @param boolean $alreadyExists Flag indicating the table should exist before the DROP TABLE query.
*/
#[DataProvider('dataDropTable')]
public function testDropTable(string $table, bool $alreadyExists)
{
$this->assertSame(
$alreadyExists,
\in_array(static::$connection->replacePrefix($table), static::$connection->getTableList())
);
$this->assertSame(
static::$connection,
static::$connection->dropTable($table, true),
'The database driver supports method chaining'
);
$this->assertFalse(
\in_array(static::$connection->replacePrefix($table), static::$connection->getTableList())
);
}
/**
* Data provider for escaping test cases
*
* @return array
*/
abstract public static function dataEscape(): array;
/**
* @testdox Text can be escaped
*
* @param string $text The string to be escaped.
* @param boolean $extra Optional parameter to provide extra escaping.
* @param string $expected The expected result.
*/
#[DataProvider('dataEscape')]
public function testEscape($text, $extra, $expected)
{
$this->assertSame(
$expected,
static::$connection->escape($text, $extra)
);
}
/**
* @testdox Values can be escaped in a locale aware context
*/
public function testEscapeNonLocaleAware()
{
$origin = setlocale(LC_NUMERIC, 0);
// Test with decimal_point equals to comma
setlocale(LC_NUMERIC, 'pl_PL');
$this->assertSame('3.14', static::$connection->escape(3.14));
// Test with C locale
setlocale(LC_NUMERIC, 'C');
$this->assertSame('3.14', static::$connection->escape(3.14));
// Revert to origin locale
setlocale(LC_NUMERIC, $origin);
}
/**
* @testdox The number of executed SQL statements can be retrieved
*/
public function testGetCount()
{
$this->assertTrue(
is_int(static::$connection->getCount()),
'The count of the number of executed SQL statements should be retrieved'
);
}
/**
* @testdox A PHP DateTime compatible date format for the database driver can be retrieved
*/
public function testGetDateFormat()
{
$this->assertSame(
'Y-m-d H:i:s',
static::$connection->getDateFormat()
);
}
/**
* @testdox The minimum supported database version is retrieved
*/
public function testGetMinimum()
{
$this->assertTrue(
\is_string(static::$connection->getMinimum()),
'The minimum version is returned as a string'
);
}
/**
* @testdox The number of rows returned by the query can be retrieved
*/
public function testGetNumRows()
{
$this->loadExampleData();
static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
->where(static::$connection->quoteName('description') . ' = ' . static::$connection->quote('test row one'))
);
static::$connection->execute();
$this->assertSame(1, static::$connection->getNumRows());
}
/**
* @testdox A cached query instance can be retrieved
*/
public function testGetQueryCachedQuery()
{
$query = static::$connection->createQuery()
->select('*')
->from('#__dbtest');
static::$connection->setQuery($query);
$this->assertSame($query, static::$connection->getQuery(false));
}
/**
* @testdox An iterator for the database driver can be created
*/
public function testGetIterator()
{
$this->loadExampleData();
static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
);
$this->assertInstanceOf(
DatabaseIterator::class,
static::$connection->getIterator()
);
}
/**
* Data provider for fetching table column test cases
*
* @return array
*/
abstract public static function dataGetTableColumns(): array;
/**
* @testdox Information about the columns of a database table is returned
*
* @param string $table The name of the database table.
* @param boolean $typeOnly True (default) to only return field types.
* @param array $expected Expected result.
*/
#[DataProvider('dataGetTableColumns')]
public function testGetTableColumns(string $table, bool $typeOnly, array $expected)
{
$this->assertEquals(
$expected,
static::$connection->getTableColumns($table, $typeOnly)
);
}
/**
* @testdox The list of tables is returned
*/
public function testGetTableList()
{
$this->assertSame(
[
static::$connection->replacePrefix('#__dbtest'),
],
static::$connection->getTableList()
);
}
/**
* @testdox The database version is returned
*/
public function testGetVersion()
{
$this->assertNotEmpty(
static::$connection->getVersion()
);
}
/**
* @testdox The connection can be checked for UTF support
*/
public function testHasUtfSupport()
{
$this->assertTrue(
static::$connection->hasUtfSupport()
);
}
/**
* @testdox An object can be inserted into the database
*/
public function testInsertObject()
{
$this->loadExampleData();
$data = (object) [
'id' => null,
'title' => 'Testing insertObject',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test insertObject row',
];
static::$connection->insertObject(
'#__dbtest',
$data,
'id'
);
$this->assertNotNull($data->id, 'When given a key, the insertObject method should set the row ID');
}
/**
* @testdox The database server can be checked if it is running a version matching the minimum supported version
*/
public function testIsMinimumVersion()
{
$this->assertTrue(
static::$connection->isMinimumVersion()
);
}
/**
* @testdox The first row of a result set can be loaded as an associative array, using old getQuery(true) syntax
*/
public function testLoadAssocWithOldGetQueryTrueSyntax()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->getQuery(true)
->select('title')
->from('#__dbtest')
)->loadAssoc();
$this->assertEquals(
[
'title' => 'Testing1',
],
$result
);
}
/**
* @testdox The first row of a result set can be loaded as an associative array
*/
public function testLoadAssoc()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('title')
->from('#__dbtest')
)->loadAssoc();
$this->assertEquals(
[
'title' => 'Testing1',
],
$result
);
}
/**
* @testdox All rows of a result set can be loaded as an associative array
*/
public function testLoadAssocList()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('title')
->from('#__dbtest')
)->loadAssocList();
$this->assertEquals(
[
['title' => 'Testing1'],
['title' => 'Testing2'],
['title' => 'Testing3'],
['title' => 'Testing4'],
],
$result
);
}
/**
* @testdox The specified column from all rows of a result set can be loaded as an array
*/
public function testLoadColumn()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('title')
->from('#__dbtest')
)->loadColumn();
$this->assertEquals(
[
'Testing1',
'Testing2',
'Testing3',
'Testing4',
],
$result
);
}
/**
* @testdox The first row of a result set can be loaded as a PHP object
*/
public function testLoadObject()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
)->loadObject();
$expected = (object) [
'id' => '1',
'title' => 'Testing1',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row one',
'data' => null,
];
$this->assertEquals($expected, $result);
}
/**
* @testdox All rows of a result set can be loaded as PHP objects
*/
public function testLoadObjectList()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
)->loadObjectList();
$expected = [
(object) [
'id' => '1',
'title' => 'Testing1',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row one',
'data' => null,
],
(object) [
'id' => '2',
'title' => 'Testing2',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row two',
'data' => null,
],
(object) [
'id' => '3',
'title' => 'Testing3',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row three',
'data' => null,
],
(object) [
'id' => '4',
'title' => 'Testing4',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test row four',
'data' => null,
],
];
$this->assertEquals($expected, $result);
}
/**
* @testdox The first field from the first row of a result set can be loaded
*/
public function testLoadResult()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
)->loadResult();
$this->assertEquals('1', $result);
}
/**
* @testdox The first row of a result set can be loaded as an array
*/
public function testLoadRow()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
)->loadRow();
$expected = [
'1',
'Testing1',
'2019-10-26 00:00:00',
'test row one',
null,
];
$this->assertEquals($expected, $result);
}
/**
* @testdox All rows of a result set can be loaded as an array
*/
public function testLoadRowList()
{
$this->loadExampleData();
$result = static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
)->loadRowList();
$expected = [
[
'1',
'Testing1',
'2019-10-26 00:00:00',
'test row one',
null,
],
[
'2',
'Testing2',
'2019-10-26 00:00:00',
'test row two',
null,
],
[
'3',
'Testing3',
'2019-10-26 00:00:00',
'test row three',
null,
],
[
'4',
'Testing4',
'2019-10-26 00:00:00',
'test row four',
null,
],
];
$this->assertEquals($expected, $result);
}
/**
* @testdox A database table can be locked and unlocked
*/
public function testLockAndUnlockTable()
{
$this->assertSame(
static::$connection,
static::$connection->lockTable('#__dbtest'),
'The database driver supports method chaining'
);
$this->assertSame(
static::$connection,
static::$connection->unlockTables(),
'The database driver supports method chaining'
);
}
/**
* Data provider for binary quoting test cases
*
* @return array
*/
abstract public static function dataQuoteBinary(): array;
/**
* @testdox A binary value is quoted properly
*
* @param string $data The binary quoted input string.
* @param string $expected The expected result.
*/
#[DataProvider('dataQuoteBinary')]
public function testQuoteBinary($data, $expected)
{
$this->assertSame($expected, static::$connection->quoteBinary($data));
}
/**
* Data provider for name quoting test cases
*
* @return array
*/
abstract public static function dataQuoteName(): array;
/**
* @testdox A value is name quoted properly
*
* @param array|string $name The identifier name to wrap in quotes, or an array of identifier names to wrap in quotes.
* @param array|string $as The AS query part associated to $name.
* @param array|string $expected The expected result.
*/
#[DataProvider('dataQuoteName')]
public function testQuoteName($name, $as, $expected)
{
$this->assertSame(
$expected,
static::$connection->quoteName($name, $as)
);
}
/**
* @testdox A database table can be renamed
*/
public function testRenameTable()
{
$oldTableName = '#__dbtest';
$newTableName = 'bak_dbtest';
$this->assertSame(
static::$connection,
static::$connection->renameTable($oldTableName, $newTableName),
'The database driver supports method chaining'
);
$this->assertTrue(
\in_array($newTableName, static::$connection->getTableList())
);
// Restore initial state
static::$connection->renameTable($newTableName, $oldTableName);
$this->assertFalse(
\in_array($newTableName, static::$connection->getTableList())
);
}
/**
* @testdox A query monitor can be set and retrieved
*/
public function testGetAndSetQueryMonitor()
{
$this->assertNull(static::$connection->getMonitor(), 'A database driver has no monitor by default');
$monitor = new ChainedMonitor();
$this->assertSame(
static::$connection,
static::$connection->setMonitor($monitor),
'The database driver supports method chaining'
);
$this->assertSame(
$monitor,
static::$connection->getMonitor()
);
}
/**
* @testdox A QueryInterface object can be set to the driver without an offset or limit
*/
public function testSetQueryWithQueryObjectWithoutOffsetOrLimit()
{
$query = static::$connection->createQuery()
->select('*')
->from('#__dbtest');
$this->assertSame(
static::$connection,
static::$connection->setQuery($query),
'The database driver supports method chaining'
);
$this->assertSame(
$query,
static::$connection->getQuery(false),
'The injected query object should be returned'
);
}
/**
* @testdox A QueryInterface object can be set to the driver with an offset or limit
*/
public function testSetQueryWithQueryObjectWithOffsetAndLimit()
{
$query = static::$connection->createQuery()
->select('*')
->from('#__dbtest');
$this->assertSame(
static::$connection,
static::$connection->setQuery($query, 3, 10),
'The database driver supports method chaining'
);
$queryFromDriver = static::$connection->getQuery(false);
$this->assertSame(
$query,
$queryFromDriver,
'The injected query object should be returned'
);
$this->assertSame(
3,
$queryFromDriver->offset,
'An offset should be set to the query object.'
);
$this->assertSame(
10,
$queryFromDriver->limit,
'A limit should be set to the query object.'
);
}
/**
* @testdox A QueryInterface object can be set to the driver while retraining the offset and limit from the query
*/
public function testSetQueryWithQueryObjectWithOffsetAndLimitOnQuery()
{
$query = static::$connection->createQuery()
->select('*')
->from('#__dbtest')
->setLimit(10, 3);
$this->assertSame(
static::$connection,
static::$connection->setQuery($query),
'The database driver supports method chaining'
);
$queryFromDriver = static::$connection->getQuery(false);
$this->assertSame(
$query,
$queryFromDriver,
'The injected query object should be returned'
);
$this->assertSame(
3,
$queryFromDriver->offset,
'An offset should be set to the query object.'
);
$this->assertSame(
10,
$queryFromDriver->limit,
'A limit should be set to the query object.'
);
}
/**
* @testdox A string can be set to the driver without an offset or limit
*/
public function testSetQueryWithStringWithoutOffsetOrLimit()
{
$query = 'SELECT * FROM #__dbtest';
$this->assertSame(
static::$connection,
static::$connection->setQuery($query),
'The database driver supports method chaining'
);
$this->assertInstanceOf(
QueryInterface::class,
static::$connection->getQuery(false),
\sprintf('A string should be converted to a %s instance', QueryInterface::class)
);
}
/**
* @testdox An invalid query type cannot be set to the driver
*/
public function testSetQueryWithInvalidQueryType()
{
$this->expectException(\InvalidArgumentException::class);
static::$connection->setQuery(new \stdClass());
}
/**
* @testdox A database can be selected for use
*/
public function testSelect()
{
$this->assertTrue(
static::$connection->select(static::$dbManager->getDbName())
);
}
/**
* @testdox An object can be used to update a row in the database
*/
public function testUpdateObject()
{
$this->loadExampleData();
$data = (object) [
'id' => 1,
'title' => 'Testing updateObject',
'start_date' => '2019-10-26 00:00:00',
'description' => 'test updateObject row',
'data' => null,
];
static::$connection->updateObject(
'#__dbtest',
$data,
'id'
);
// Fetch row to validate update
$row = static::$connection->setQuery(
static::$connection->createQuery()
->select('*')
->from('#__dbtest')
->where('id = :id')
->bind(':id', $data->id, ParameterType::INTEGER)
)->loadObject();
$this->assertSame($row->title, $data->title);
}
/**
* @testdox Queries using the querySet type are correctly built and executed
*/
public function testQuerySetWithUnionAll()
{
$this->loadExampleData();
$query = static::$connection->createQuery();
$union1 = static::$connection->createQuery();
$union2 = static::$connection->createQuery();
$union1->select('id, title')
->from('#__dbtest')
->where('id = 4')
->setLimit(1);
$union2->select('id, title')
->from('#__dbtest')
->where('id < 4')
->order('id DESC')
->setLimit(2, 1);
$query->querySet($union1)
->unionAll($union2)
->order('id');
$result = static::$connection->setQuery($query, 0, 3)->loadAssocList();
$this->assertEquals(
[
['id' => '1', 'title' => 'Testing1'],
['id' => '2', 'title' => 'Testing2'],
['id' => '4', 'title' => 'Testing4'],
],
$result
);
}
/**
* @testdox Queries converted to the querySet type are correctly built and executed
*/
public function testSelectToQuerySetWithUnionAll()
{
$this->loadExampleData();
$query = static::$connection->createQuery();
$union = static::$connection->createQuery();
$query->select('id, title')
->from('#__dbtest')
->where('id = 4')
->setLimit(1)
->toQuerySet();
$union->select('id, title')
->from('#__dbtest')
->where('id < 4')
->order('id DESC')
->setLimit(2, 1);
$query->unionAll($union)
->order('id');
$result = static::$connection->setQuery($query)->loadAssocList();
$this->assertEquals(
[
['id' => '1', 'title' => 'Testing1'],
],
$result
);
}
/**
* @testdox Select statements can be prepared once and executed repeatedly
*/
public function testRepeatedSelectStatement()
{
$this->loadExampleData();
$results = [];
$query = static::$connection->createQuery();
$query->select('id, title')
->from('#__dbtest')
->where('id = :id')
->bind(':id', $id, ParameterType::INTEGER);
// Test repeated statements.
static::$connection->setQuery($query);
$id = 1;
$results[] = static::$connection->loadAssoc();
$id = 4;
$results[] = static::$connection->loadAssoc();
// Also test that running a new query works.
static::$connection->setQuery($query);
$id = 2;
$results[] = static::$connection->loadAssoc();
$this->assertEquals(
[
['id' => '1', 'title' => 'Testing1'],
['id' => '4', 'title' => 'Testing4'],
['id' => '2', 'title' => 'Testing2'],
],
$results
);
}
/**
* @testdox DebugMonitor reports correct parameters with reusable query
*/
public function testMonitorWithReusableQuery()
{
static::$connection->setMonitor(new DebugMonitor());
$title = 'test';
$query = static::$connection->createQuery()
->select('id')
->from('#__dbtest')
->where('title = :title')
->bind(':title', $title);
static::$connection->setQuery($query);
static::$connection->loadResult();
$id = 2;
$query->clear()
->select('id')
->from('#__dbtest')
->where('id = :id')
->bind(':id', $id, ParameterType::INTEGER);
static::$connection->setQuery($query);
static::$connection->loadResult();
$params = [];
foreach (static::$connection->getMonitor()->getBoundParams() as $queryParams) {
foreach ($queryParams as $queryParam) {
$params[] = [$queryParam->value, $queryParam->dataType];
}
}
$this->assertSame(
[
['test', 'string'],
[2, 'int'],
],
$params