From 0737581e00a22214292eeb965602b6c87bd2caec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chav=C3=A9e?= Date: Fri, 23 May 2025 08:55:42 +0000 Subject: [PATCH 1/2] Fix --dry-run option when values to insert are booleans --- src/Phinx/Db/Adapter/PdoAdapter.php | 4 +++ tests/Phinx/Db/Adapter/PdoAdapterTest.php | 43 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/Phinx/Db/Adapter/PdoAdapter.php b/src/Phinx/Db/Adapter/PdoAdapter.php index d5e8aed96..9f8c62f10 100644 --- a/src/Phinx/Db/Adapter/PdoAdapter.php +++ b/src/Phinx/Db/Adapter/PdoAdapter.php @@ -391,6 +391,10 @@ protected function quoteValue(mixed $value): mixed return $value; } + if (is_bool($value)) { + return $this->castToBool($value); + } + if ($value === null) { return 'null'; } diff --git a/tests/Phinx/Db/Adapter/PdoAdapterTest.php b/tests/Phinx/Db/Adapter/PdoAdapterTest.php index dd5b7a07c..ff5a0eb67 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -10,6 +10,7 @@ use RuntimeException; use Test\Phinx\DeprecationException; use Test\Phinx\TestUtils; +use ReflectionMethod; class PdoAdapterTest extends TestCase { @@ -203,4 +204,46 @@ public function testExecuteRightTrimsSemiColons() $this->adapter->setConnection($pdo); $this->adapter->execute('SELECT 1;;'); } + + public function testQuoteValueNumeric() + { + $method = new ReflectionMethod($this->adapter, 'quoteValue'); + $this->assertSame(1.0, $method->invoke($this->adapter, 1.0)); + $this->assertSame(2, $method->invoke($this->adapter, 2)); + } + + public function testQuoteValueBoolean() + { + $method = new ReflectionMethod($this->adapter, 'quoteValue'); + $this->assertSame(1, $method->invoke($this->adapter, true)); + $this->assertSame(0, $method->invoke($this->adapter, false)); + } + + public function testQuoteValueNull() + { + $method = new ReflectionMethod($this->adapter, 'quoteValue'); + $this->assertSame('null', $method->invoke($this->adapter, null)); + } + + public function testQuoteValueString() + { + $mockValue = 'mockvalue'; + $expectedValue = 'mockvalueexpected'; + + /** @var \PDO&\PHPUnit\Framework\MockObject\MockObject $pdo */ + $pdo = $this->getMockBuilder(PDO::class) + ->disableOriginalConstructor() + ->onlyMethods(['quote']) + ->getMock(); + + $pdo->expects($this->once()) + ->method('quote') + ->with($mockValue) + ->willReturn($expectedValue); + + $this->adapter->setConnection($pdo); + + $method = new ReflectionMethod($this->adapter, 'quoteValue'); + $this->assertSame($expectedValue, $method->invoke($this->adapter, $mockValue)); + } } From 45b57c90b98cb7c19961df5e0b2c73f3abdf6220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chav=C3=A9e?= Date: Fri, 23 May 2025 09:02:28 +0000 Subject: [PATCH 2/2] Reorder use statements --- tests/Phinx/Db/Adapter/PdoAdapterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Phinx/Db/Adapter/PdoAdapterTest.php b/tests/Phinx/Db/Adapter/PdoAdapterTest.php index ff5a0eb67..2e894c001 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -7,10 +7,10 @@ use PDOException; use Phinx\Config\Config; use PHPUnit\Framework\TestCase; +use ReflectionMethod; use RuntimeException; use Test\Phinx\DeprecationException; use Test\Phinx\TestUtils; -use ReflectionMethod; class PdoAdapterTest extends TestCase {