From 63843fb704dd497d1a863d14263dcf358dfa2853 Mon Sep 17 00:00:00 2001 From: rh389 Date: Sun, 24 Jul 2016 15:37:42 +0100 Subject: [PATCH 1/3] Support native JSON type on MySQL 5.7 --- .../DBAL/Platforms/MySQL57Platform.php | 25 +++++++++++++++++++ .../DBAL/Driver/AbstractMySQLDriverTest.php | 4 +-- .../DBAL/Platforms/MySQL57PlatformTest.php | 24 ++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php index 36b525e2063..6d9b437aae1 100644 --- a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php @@ -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'; + } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index 83e15cf9521..27367bdc1f0 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -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'), diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index 2fb87070d9a..f0db1b715b0 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -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())); + } + /** + * @group DBAL-553 + */ + public function testInitializesJsonTypeMapping() + { + $this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); + $this->assertEquals('json_array', $this->_platform->getDoctrineTypeMapping('json')); + } } From 8644f8878fba7e99039fc5cddf47849807c0eea5 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Mon, 26 Sep 2016 12:09:52 +0100 Subject: [PATCH 2/3] assertEquals -> assertSame --- tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index f0db1b715b0..ebb6a0ba0d0 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -87,6 +87,6 @@ public function testReturnsJsonTypeDeclarationSQL() public function testInitializesJsonTypeMapping() { $this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); - $this->assertEquals('json_array', $this->_platform->getDoctrineTypeMapping('json')); + $this->assertSame('json_array', $this->_platform->getDoctrineTypeMapping('json')); } } From 66be08a7e38419e6bce54f804d35ca2981c7557d Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Wed, 12 Oct 2016 18:06:52 +0200 Subject: [PATCH 3/3] Fix missing newline --- tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index ebb6a0ba0d0..5807b7c82dc 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -81,6 +81,7 @@ public function testReturnsJsonTypeDeclarationSQL() { $this->assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array())); } + /** * @group DBAL-553 */