Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Phinx/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
43 changes: 43 additions & 0 deletions tests/Phinx/Db/Adapter/PdoAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Loading