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..2e894c001 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -7,6 +7,7 @@ use PDOException; use Phinx\Config\Config; use PHPUnit\Framework\TestCase; +use ReflectionMethod; use RuntimeException; use Test\Phinx\DeprecationException; use Test\Phinx\TestUtils; @@ -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)); + } }