Skip to content
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

Use native JSON type on MySQL >=5.7 #2455

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/Doctrine/DBAL/Platforms/MySQL57Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,29 @@ protected function getReservedKeywordsClass()
{
return 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords';
}

/**
* {@inheritdoc}
*/
protected function initializeDoctrineTypeMappings()
{
parent::initializeDoctrineTypeMappings();
$this->doctrineTypeMapping['json'] = 'json_array';
}

/**
* {@inheritdoc}
*/
public function hasNativeJsonType()
{
return true;
}

/**
* {@inheritdoc}
*/
public function getJsonTypeDeclarationSQL(array $field)
{
return 'JSON';
}
}
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ protected function getDatabasePlatformsForVersions()
return array(
array('5.6.9', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
array('5.7', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.0', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.1', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.8', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.13', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('6', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('10.0.15-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
array('10.1.2a-MariaDB-a1~lenny-log', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
Expand Down
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,28 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
'ALTER TABLE mytable RENAME INDEX idx_foo TO idx_foo_renamed',
);
}

/**
* @group DBAL-553
*/
public function hasNativeJsonType()
{
$this->assertTrue($this->_platform->hasNativeJsonType());
}

/**
* @group DBAL-553
*/
public function testReturnsJsonTypeDeclarationSQL()
{
$this->assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array()));
}
/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot - fixed

* @group DBAL-553
*/
public function testInitializesJsonTypeMapping()
{
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('json'));
$this->assertEquals('json_array', $this->_platform->getDoctrineTypeMapping('json'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not assertSame()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - updated.

}
}