22
33namespace Teto \SQL \Type ;
44
5+ use DomainException ;
56use Teto \SQL \DummyPDO ;
67use Yoast \PHPUnitPolyfills \TestCases \TestCase ;
78
@@ -12,14 +13,15 @@ class PgIdentifierTest extends TestCase
1213
1314 public function set_up ()
1415 {
16+ /** @noinspection PhpMultipleClassDeclarationsInspection */
1517 parent ::set_up ();
1618
1719 $ this ->subject = new PgIdentifier ([]);
1820 }
1921
2022 /**
2123 * @dataProvider escapeValuesProvider
22- * @phpstan-param string|array<string> $input
24+ * @phpstan-param string|array<string>|bool $input
2325 * @param string $type
2426 * @param string $expected
2527 * @return void
@@ -33,7 +35,7 @@ public function testEscapeValue($input, $type, $expected)
3335 }
3436
3537 /**
36- * @return array<array{string|array<?string>,string,string}>
38+ * @return array<array{string|array<?string>|bool ,string,string}>
3739 */
3840 public function escapeValuesProvider ()
3941 {
@@ -47,6 +49,49 @@ public function escapeValuesProvider()
4749 [['"foo" ' => null ] , '@column[] ' , '"foo" ' ],
4850 [['foo ' => null , 'bar ' => 'buz ' ] , '@column[] ' , 'foo,bar AS "buz" ' ],
4951 [['"foo" ' => null , 'bar ' => '' ] , '@column[] ' , '"foo",bar ' ],
52+ [true , '@bool ' , 'true ' ],
53+ [false , '@bool ' , 'false ' ],
54+ ];
55+ }
56+
57+ /**
58+ * @dataProvider escapeValuesUnexpectedValuesProvider
59+ * @phpstan-param string|array<string> $input
60+ * @param string $type
61+ * @phpstan-param array{class: class-string<\Exception>, message: non-empty-string} $expected
62+ * @return void
63+ */
64+ public function testEscapeValue_raiseError ($ input , $ type , array $ expected )
65+ {
66+ $ this ->expectException ($ expected ['class ' ]);
67+ $ this ->expectExceptionMessage ($ expected ['message ' ]);
68+
69+ $ pdo = new DummyPDO ();
70+ $ bind_values = [];
71+ $ _ = $ this ->subject ->escapeValue ($ pdo , ':key ' , $ type , $ input , $ bind_values );
72+ }
73+
74+ /**
75+ * @return array<array{mixed, string, array{class: class-string<\Exception>, message: non-empty-string}}>
76+ */
77+ public function escapeValuesUnexpectedValuesProvider ()
78+ {
79+ /** @phpstan-var class-string<DomainException> $DomainException */
80+ $ DomainException = 'DomainException ' ;
81+
82+ return [
83+ [1 , '@bool ' , ['class ' => $ DomainException , 'message ' => 'param ":key" must be bool ' ]],
84+ ['' , '@bool ' , ['class ' => $ DomainException , 'message ' => 'param ":key" must be bool ' ]],
85+ [null , '@bool ' , ['class ' => $ DomainException , 'message ' => 'param ":key" must be bool ' ]],
86+ ['true ' , '@bool ' , ['class ' => $ DomainException , 'message ' => 'param ":key" must be bool ' ]],
87+ [
88+ ['"foo" ' => null , 'bar ' => '' ],
89+ '@table ' ,
90+ [
91+ 'class ' => $ DomainException ,
92+ 'message ' => "Passed unexpected \$value as type '@table'. please check your query and parameters. " ,
93+ ],
94+ ],
5095 ];
5196 }
5297
0 commit comments