-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test to verify null cast in boolean type #632
Changes from all commits
f624876
031f38c
43d13fc
4ebdb8c
24bf3bc
fd3b116
1a7fa0c
7b29bd5
907513f
598503d
e8d7820
8065c83
8eb2ddc
9c91857
1f5456a
f2aa22c
e2b1177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ protected function setUp() | |
|
||
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,4 +89,92 @@ public function testBooleanConversionBoolParamEmulatedPrepares() | |
|
||
$this->assertFalse($row['bool_col']); | ||
} | ||
|
||
/** | ||
* @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 | ||
// 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)); | ||
$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->assertSame($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->assertSame($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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this assumption is wrong and is exactly the issue I was talking about. Why should I expect to get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We aren't getting from the database, we are inserting into the database. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because "NULL" is neither "true" or "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) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty newline before this line