Commit 437f4160 authored by Tiago Brito's avatar Tiago Brito Committed by Steve Müller

refs #632 check boolean conversion with and without PDO type value

Add unit test to check boolean conversion with and without PDO boolean type
parent fc1606fa
......@@ -24,6 +24,7 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
try {
$this->_conn->exec('CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);');
$this->_conn->exec('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);');
} catch (DBALException $e) {
}
$this->running = true;
......@@ -88,11 +89,14 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
$this->assertFalse($row['bool_col']);
}
public function testBooleanConversionNullParamEmulatedPrepares()
{
$this->_conn->exec('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);');
/**
* @dataProvider booleanTypeConversionWithoutPdoTypeProvider
*/
public function testBooleanConversionNullParamEmulatedPrepares(
$statementValue,
$databaseConvertedValue
) {
$this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
// PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated in php 5.6. PDO::ATTR_EMULATE_PREPARES should
......@@ -104,15 +108,73 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
$platform = $this->_conn->getDatabasePlatform();
$stmt = $this->_conn->prepare('INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)');
$stmt->bindValue(1, $platform->convertBooleansToDatabaseValue(null));
$stmt->bindValue(1, $platform->convertBooleansToDatabaseValue($statementValue));
$stmt->execute();
$id = $this->_conn->lastInsertId('dbal630_id_seq');
$id = $this->_conn->lastInsertId('dbal630_allow_nulls_id_seq');
$this->assertNotEmpty($id);
$row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', array($id));
$this->assertEquals($databaseConvertedValue, $row['bool_col']);
}
/**
* @dataProvider booleanTypeConversionUsingBooleanTypeProvider
*/
public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInBindValue(
$statementValue,
$databaseConvertedValue
) {
$this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
// PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated in php 5.6. PDO::ATTR_EMULATE_PREPARES should
// be used instead. so should only it be set when it is supported.
if (PHP_VERSION_ID < 50600) {
$this->_conn->getWrappedConnection()->setAttribute(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, true);
}
$platform = $this->_conn->getDatabasePlatform();
$stmt = $this->_conn->prepare('INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)');
$stmt->bindValue(1, $platform->convertBooleansToDatabaseValue($statementValue), PDO::PARAM_BOOL);
$stmt->execute();
$id = $this->_conn->lastInsertId('dbal630_allow_nulls_id_seq');
$this->assertNotEmpty($id);
$row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', array($id));
$this->assertNull($row['bool_col']);
$this->assertEquals($databaseConvertedValue, $row['bool_col']);
}
/**
* Boolean conversion mapping provider
* @return array
*/
public function booleanTypeConversionUsingBooleanTypeProvider()
{
return array(
// statement value, database converted value result
array(true, true),
array(false, false),
array(null, false)
);
}
/**
* Boolean conversion mapping provider
* @return array
*/
public function booleanTypeConversionWithoutPdoTypeProvider()
{
return array(
// statement value, database converted value result
array(true, true),
array(false, false),
array(null, null)
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment