Independent tests for introspection and insert

parent 87c417fd
...@@ -1407,43 +1407,55 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -1407,43 +1407,55 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
* *
* @return array * @return array
*/ */
public function getEscapedLiterals(): array private function getEscapedLiterals(): array
{ {
return [ return [
'An ASCII NUL (X\'00\')' => ["\\0"], ['An ASCII NUL (X\'00\')', "foo\\0bar"],
'Single quote, C-style' => ["\\'"], ['Single quote, C-style', "foo\\'bar"],
'Single quote, doubled-style' => ["''"], ['Single quote, doubled-style', "foo''bar"],
'Double quote, C-style' => ['\\"'], ['Double quote, C-style', 'foo\\"bar'],
'Double quote, double-style' => ['""'], ['Double quote, double-style', 'foo""bar'],
'Backspace' => ['\\b'], ['Backspace', 'foo\\bbar'],
'New-line' => ['\\n'], ['New-line', 'foo\\nbar'],
'Carriage return' => ['\\r'], ['Carriage return', 'foo\\rbar'],
'Tab' => ['\\t'], ['Tab', 'foo\\tbar'],
'ASCII 26 (Control+Z)' => ['\\Z'], ['ASCII 26 (Control+Z)', 'foo\\Zbar'],
'Backslash (\)' => ['\\\\'], ['Backslash (\)', 'foo\\\\bar'],
'Percent (%)' => ['\\%'], ['Percent (%)', 'foo\\%bar'],
'Underscore (_)' => ['\\_'], ['Underscore (_)', 'foo\\_bar'],
]; ];
} }
/** private function createTableForDefaultValues(): void
* @dataProvider getEscapedLiterals
*
* @param string $value
*/
public function testEscapedDefaultValueMustBePreserved(string $value) : void
{ {
$value = 'foo' . $value . 'bar';
$table = new Table('string_escaped_default_value'); $table = new Table('string_escaped_default_value');
$table->addColumn('def_string', 'string', array('default' => $value)); foreach ($this->getEscapedLiterals() as $i => $literal) {
$table->addColumn('field' . $i, 'string', ['default' => $literal[1]]);
}
$table->addColumn('def_foo', 'string'); $table->addColumn('def_foo', 'string');
$this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateTable($table);
}
public function testEscapedDefaultValueCanBeIntrospected(): void
{
$this->createTableForDefaultValues();
$onlineTable = $this->_sm->listTableDetails('string_escaped_default_value'); $onlineTable = $this->_sm->listTableDetails('string_escaped_default_value');
self::assertSame($value, $onlineTable->getColumn('def_string')->getDefault(), 'should be able introspect the value of default'); foreach ($this->getEscapedLiterals() as $i => $literal) {
self::assertSame($literal[1], $onlineTable->getColumn('field' . $i)->getDefault(), 'should be able introspect the value of default for: ' . $literal[0]);
}
}
$this->_conn->insert('string_escaped_default_value', array('def_foo' => 'foo')); public function testEscapedDefaultValueCanBeInserted(): void
$row = $this->_conn->fetchAssoc('SELECT def_string FROM string_escaped_default_value'); {
self::assertSame($value, $row['def_string'], 'inserted default value should be the configured default value'); $this->createTableForDefaultValues();
$this->_conn->insert('string_escaped_default_value', ['def_foo' => 'foo']);
$row = $this->_conn->fetchAssoc('SELECT * FROM string_escaped_default_value');
foreach ($this->getEscapedLiterals() as $i => $literal) {
self::assertSame($literal[1], $row['field' . $i], 'inserted default value should be the configured default value for: ' . $literal[0]);
}
} }
} }
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