33
44namespace Test \Phinx \Db \Adapter ;
55
6+ use Cake \I18n \Date ;
7+ use Cake \I18n \DateTime ;
68use PDO ;
79use PDOException ;
810use Phinx \Config \Config ;
11+ use Phinx \Util \Literal ;
912use PHPUnit \Framework \TestCase ;
1013use ReflectionMethod ;
1114use RuntimeException ;
@@ -205,31 +208,42 @@ public function testExecuteRightTrimsSemiColons()
205208 $ this ->adapter ->execute ('SELECT 1;; ' );
206209 }
207210
208- public function testQuoteValueNumeric ()
211+ public function quoteValueDataProvider (): array
209212 {
210- $ method = new ReflectionMethod ($ this ->adapter , 'quoteValue ' );
211- $ this ->assertSame (1.0 , $ method ->invoke ($ this ->adapter , 1.0 ));
212- $ this ->assertSame (2 , $ method ->invoke ($ this ->adapter , 2 ));
213+ return [
214+ [1.0 , 1.0 ],
215+ [2 , 2 ],
216+ [true , 1 ],
217+ [false , 0 ],
218+ [null , 'null ' ],
219+ [Literal::from ('CURRENT_TIMESTAMP ' ), 'CURRENT_TIMESTAMP ' ],
220+ ];
213221 }
214222
215- public function testQuoteValueBoolean ()
223+ /**
224+ * @dataProvider quoteValueDataProvider
225+ */
226+ public function testQuoteValue ($ input , $ expected ): void
216227 {
217228 $ method = new ReflectionMethod ($ this ->adapter , 'quoteValue ' );
218- $ this ->assertSame (1 , $ method ->invoke ($ this ->adapter , true ));
219- $ this ->assertSame (0 , $ method ->invoke ($ this ->adapter , false ));
229+ $ this ->assertSame ($ expected , $ method ->invoke ($ this ->adapter , $ input ));
220230 }
221231
222- public function testQuoteValueNull ()
232+ public function quoteValueStringDataProvider (): array
223233 {
224- $ method = new ReflectionMethod ($ this ->adapter , 'quoteValue ' );
225- $ this ->assertSame ('null ' , $ method ->invoke ($ this ->adapter , null ));
234+ return [
235+ ['mockvalue ' , "'mockvalue' " ],
236+ [new Date ('2023-01-01 ' ), "'2023-01-01' " ],
237+ [new DateTime ('2023-01-01 12:00:00 ' ), "'2023-01-01 12:00:00' " ],
238+ ];
226239 }
227240
228- public function testQuoteValueString ()
229- {
230- $ mockValue = 'mockvalue ' ;
231- $ expectedValue = 'mockvalueexpected ' ;
241+ /**
242+ * @dataProvider quoteValueStringDataProvider
243+ */
232244
245+ public function testQuoteValueString ($ input , $ expected ): void
246+ {
233247 /** @var \PDO&\PHPUnit\Framework\MockObject\MockObject $pdo */
234248 $ pdo = $ this ->getMockBuilder (PDO ::class)
235249 ->disableOriginalConstructor ()
@@ -238,12 +252,13 @@ public function testQuoteValueString()
238252
239253 $ pdo ->expects ($ this ->once ())
240254 ->method ('quote ' )
241- ->with ($ mockValue )
242- ->willReturn ($ expectedValue );
255+ ->willReturnCallback (function (string $ input ) {
256+ return "' $ input' " ;
257+ });
243258
244259 $ this ->adapter ->setConnection ($ pdo );
245260
246261 $ method = new ReflectionMethod ($ this ->adapter , 'quoteValue ' );
247- $ this ->assertSame ($ expectedValue , $ method ->invoke ($ this ->adapter , $ mockValue ));
262+ $ this ->assertSame ($ expected , $ method ->invoke ($ this ->adapter , $ input ));
248263 }
249264}
0 commit comments