Skip to content

Commit 198b6ca

Browse files
authored
Fix --dry-run option when values to insert are booleans (#2358)
1 parent 842c374 commit 198b6ca

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/Phinx/Db/Adapter/PdoAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ protected function quoteValue(mixed $value): mixed
391391
return $value;
392392
}
393393

394+
if (is_bool($value)) {
395+
return $this->castToBool($value);
396+
}
397+
394398
if ($value === null) {
395399
return 'null';
396400
}

tests/Phinx/Db/Adapter/PdoAdapterTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PDOException;
88
use Phinx\Config\Config;
99
use PHPUnit\Framework\TestCase;
10+
use ReflectionMethod;
1011
use RuntimeException;
1112
use Test\Phinx\DeprecationException;
1213
use Test\Phinx\TestUtils;
@@ -203,4 +204,46 @@ public function testExecuteRightTrimsSemiColons()
203204
$this->adapter->setConnection($pdo);
204205
$this->adapter->execute('SELECT 1;;');
205206
}
207+
208+
public function testQuoteValueNumeric()
209+
{
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+
}
214+
215+
public function testQuoteValueBoolean()
216+
{
217+
$method = new ReflectionMethod($this->adapter, 'quoteValue');
218+
$this->assertSame(1, $method->invoke($this->adapter, true));
219+
$this->assertSame(0, $method->invoke($this->adapter, false));
220+
}
221+
222+
public function testQuoteValueNull()
223+
{
224+
$method = new ReflectionMethod($this->adapter, 'quoteValue');
225+
$this->assertSame('null', $method->invoke($this->adapter, null));
226+
}
227+
228+
public function testQuoteValueString()
229+
{
230+
$mockValue = 'mockvalue';
231+
$expectedValue = 'mockvalueexpected';
232+
233+
/** @var \PDO&\PHPUnit\Framework\MockObject\MockObject $pdo */
234+
$pdo = $this->getMockBuilder(PDO::class)
235+
->disableOriginalConstructor()
236+
->onlyMethods(['quote'])
237+
->getMock();
238+
239+
$pdo->expects($this->once())
240+
->method('quote')
241+
->with($mockValue)
242+
->willReturn($expectedValue);
243+
244+
$this->adapter->setConnection($pdo);
245+
246+
$method = new ReflectionMethod($this->adapter, 'quoteValue');
247+
$this->assertSame($expectedValue, $method->invoke($this->adapter, $mockValue));
248+
}
206249
}

0 commit comments

Comments
 (0)