88use Doctrine \DBAL \Schema \Table ;
99use Doctrine \DBAL \Tests \FunctionalTestCase ;
1010use Doctrine \DBAL \Tests \TestUtil ;
11+ use Doctrine \DBAL \Types \Types ;
1112
1213class BooleanBindingTest extends FunctionalTestCase
1314{
@@ -18,7 +19,7 @@ protected function setUp(): void
1819 }
1920
2021 $ table = new Table ('boolean_test_table ' );
21- $ table ->addColumn ('val ' , 'boolean ' );
22+ $ table ->addColumn ('val ' , 'boolean ' )-> setNotnull ( false ) ;
2223 $ this ->dropAndCreateTable ($ table );
2324 }
2425
@@ -28,7 +29,7 @@ protected function tearDown(): void
2829 }
2930
3031 /** @dataProvider booleanProvider */
31- public function testBooleanInsert ( bool $ input ): void
32+ public function testBooleanParameterInsert (? bool $ input ): void
3233 {
3334 $ queryBuilder = $ this ->connection ->createQueryBuilder ();
3435
@@ -37,11 +38,37 @@ public function testBooleanInsert(bool $input): void
3738 ])->executeStatement ();
3839
3940 self ::assertSame (1 , $ result );
41+
42+ self ::assertSame ($ input , $ this ->connection ->convertToPHPValue (
43+ $ this ->connection ->fetchOne ('SELECT val FROM boolean_test_table ' ),
44+ Types::BOOLEAN ,
45+ ));
46+ }
47+
48+ /** @dataProvider booleanProvider */
49+ public function testBooleanTypeInsert (?bool $ input ): void
50+ {
51+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
52+
53+ $ result = $ queryBuilder ->insert ('boolean_test_table ' )->values ([
54+ 'val ' => $ queryBuilder ->createNamedParameter ($ input , Types::BOOLEAN ),
55+ ])->executeStatement ();
56+
57+ self ::assertSame (1 , $ result );
58+
59+ self ::assertSame ($ input , $ this ->connection ->convertToPHPValue (
60+ $ this ->connection ->fetchOne ('SELECT val FROM boolean_test_table ' ),
61+ Types::BOOLEAN ,
62+ ));
4063 }
4164
42- /** @return bool[][] */
65+ /** @return array<string, array{ bool|null}> */
4366 public static function booleanProvider (): array
4467 {
45- return [[true ], [false ]];
68+ return [
69+ 'true ' => [true ],
70+ 'false ' => [false ],
71+ 'null ' => [null ],
72+ ];
4673 }
4774}
0 commit comments