Skip to content

Commit

Permalink
Latest reviews fixes: morozov, Majkl578
Browse files Browse the repository at this point in the history
  • Loading branch information
belgattitude committed Oct 13, 2017
1 parent 4862313 commit ad52f40
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 80 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ protected function isDefaultValueSupportedForType(Type $field) : bool
public function getDefaultValueDeclarationSQL($field)
{
// Unset the default value if the given field type does not allow default values.
if (!$this->isDefaultValueSupportedForType($field['type'])) {
if (! $this->isDefaultValueSupportedForType($field['type'])) {
$field['default'] = null;
}

Expand Down Expand Up @@ -595,7 +595,7 @@ public function getAlterTableSQL(TableDiff $diff)
// Don't propagate default value changes for unsupported column types.
if ($columnDiff->hasChanged('default') &&
count($columnDiff->changedProperties) === 1 &&
!$this->isDefaultValueSupportedForType($columnArray['type'])
! $this->isDefaultValueSupportedForType($columnArray['type'])
) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
if ($this->_platform instanceof MariaDb1027Platform) {
$columnDefault = $this->getMariaDb1027ColumnDefault($this->_platform, $tableColumn['default']);
} else {
$columnDefault = (isset($tableColumn['default'])) ? $tableColumn['default'] : null;
$columnDefault = $tableColumn['default'];
}

$options = [
Expand Down Expand Up @@ -237,7 +237,7 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str
if ($columnDefault === 'NULL' || $columnDefault === null) {
return null;
}
if (strpos($columnDefault, "'") === 0) {
if ($columnDefault[0] === "'") {
return stripslashes(
str_replace("''", "'",
preg_replace('/^\'(.*)\'$/', '$1', $columnDefault)
Expand Down
36 changes: 18 additions & 18 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ protected function createSchemaManager(Connection $connection)
return new MySqlSchemaManager($connection);
}

protected function getDatabasePlatformsForVersions()
protected function getDatabasePlatformsForVersions(): array
{
return array(
array('5.6.9', MySqlPlatform::class),
array('5.7', MySQL57Platform::class),
array('5.7.0', MySqlPlatform::class),
array('5.7.8', MySqlPlatform::class),
array('5.7.9', MySQL57Platform::class),
array('5.7.10', MySQL57Platform::class),
array('6', MySQL57Platform::class),
array('10.0.15-MariaDB-1~wheezy', MySqlPlatform::class),
array('5.5.5-10.1.25-MariaDB', MySqlPlatform::class),
array('10.1.2a-MariaDB-a1~lenny-log', MySqlPlatform::class),
array('5.5.40-MariaDB-1~wheezy', MySqlPlatform::class),
array('5.5.40-MariaDB-1~wheezy', MySqlPlatform::class),
array('5.5.5-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class),
array('10.2.8-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class),
array('10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class)
);
return [
['5.6.9', MySqlPlatform::class],
['5.7', MySQL57Platform::class],
['5.7.0', MySqlPlatform::class],
['5.7.8', MySqlPlatform::class],
['5.7.9', MySQL57Platform::class],
['5.7.10', MySQL57Platform::class],
['6', MySQL57Platform::class],
['10.0.15-MariaDB-1~wheezy', MySqlPlatform::class],
['5.5.5-10.1.25-MariaDB', MySqlPlatform::class],
['10.1.2a-MariaDB-a1~lenny-log', MySqlPlatform::class],
['5.5.40-MariaDB-1~wheezy', MySqlPlatform::class],
['5.5.40-MariaDB-1~wheezy', MySqlPlatform::class],
['5.5.5-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class],
['10.2.8-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class],
['10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class]
];
}

protected function getExceptionConversionData()
Expand Down
12 changes: 6 additions & 6 deletions tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ protected function createSchemaManager(Connection $connection)
return new DrizzleSchemaManager($connection);
}

protected function getDatabasePlatformsForVersions()
protected function getDatabasePlatformsForVersions() : array
{
return array(
array('foo', 'Doctrine\DBAL\Platforms\DrizzlePlatform'),
array('bar', 'Doctrine\DBAL\Platforms\DrizzlePlatform'),
array('baz', 'Doctrine\DBAL\Platforms\DrizzlePlatform'),
);
return [
['foo', 'Doctrine\DBAL\Platforms\DrizzlePlatform'],
['bar', 'Doctrine\DBAL\Platforms\DrizzlePlatform'],
['baz', 'Doctrine\DBAL\Platforms\DrizzlePlatform'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -908,19 +908,4 @@ public function testListTableForeignKeysSQLEvaluatesDatabase()
self::assertContains('bar', $sql);
self::assertNotContains('DATABASE()', $sql);
}

public function testGetDefaultValueDeclarationSQLIsQuotedWithLiteral()
{
$field = [
'type' => Type::getType('string'),
'default' => "'O'Connor said: \"Hello\" \ \r'"
];

self::assertSame(sprintf(
' DEFAULT %s',
$this->_platform->quoteStringLiteral("'O'Connor said: \"Hello\" \ \r'")
),
$this->_platform->getDefaultValueDeclarationSQL($field)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -919,19 +919,4 @@ public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL()
true
);
}

public function testGetDefaultValueDeclarationSQLIsQuotedWithLiteral()
{
$field = [
'type' => Type::getType('string'),
'default' => "'O'Connor said: \"Hello\" \ \r'"
];

self::assertSame(sprintf(
' DEFAULT %s',
$this->_platform->quoteStringLiteral("'O'Connor said: \"Hello\" \ \r'")
),
$this->_platform->getDefaultValueDeclarationSQL($field)
);
}
}
14 changes: 7 additions & 7 deletions tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
/**
* {@inheritdoc}
*/
public function createPlatform()
public function createPlatform() : MariaDb1027Platform
{
return new MariaDb1027Platform();
}

public function testHasNativeJsonType()
public function testHasNativeJsonType() : void
{
self::assertTrue($this->_platform->hasNativeJsonType());
}

public function testReturnsJsonTypeDeclarationSQL()
public function testReturnsJsonTypeDeclarationSQL() : void
{
self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([]));
}

public function testInitializesJsonTypeMapping()
public function testInitializesJsonTypeMapping() : void
{
self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('json'));
self::assertSame(Type::JSON, $this->_platform->getDoctrineTypeMapping('json'));
Expand All @@ -39,15 +39,15 @@ public function testInitializesJsonTypeMapping()
*
* @see AbstractMySQLPlatformTestCase::testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
*/
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : void
{
$this->markTestSkipped('MariaDB102Platform support propagation of default values for BLOB and TEXT columns');
}

/**
* Since MariaDB 10.2, Text and Blob can have a default value.
*/
public function testPropagateDefaultValuesForTextAndBlobColumnTypes()
public function testPropagateDefaultValuesForTextAndBlobColumnTypes() : void
{
$table = new Table("text_blob_default_value");

Expand All @@ -69,7 +69,7 @@ public function testPropagateDefaultValuesForTextAndBlobColumnTypes()
self::assertFalse($comparator->diffTable($table, $diffTable));
}

public function testPropagateDefaultValuesForJsonColumnType()
public function testPropagateDefaultValuesForJsonColumnType() : void
{
$table = new Table("text_json_default_value");

Expand Down
15 changes: 0 additions & 15 deletions tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,19 +874,4 @@ public function testQuotesDatabaseNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true);
}

public function testGetDefaultValueDeclarationSQLIsQuotedWithLiteral()
{
$field = [
'type' => Type::getType('string'),
'default' => "'O'Connor said: \"Hello\" \ \r'"
];

self::assertSame(sprintf(
' DEFAULT %s',
$this->_platform->quoteStringLiteral("'O'Connor said: \"Hello\" \ \r'")
),
$this->_platform->getDefaultValueDeclarationSQL($field)
);
}
}

0 comments on commit ad52f40

Please sign in to comment.