Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
4fff9761
Unverified
Commit
4fff9761
authored
Sep 27, 2017
by
belgattitude
Committed by
Luís Cobucci
Nov 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test JSON default values and refactoring
parent
1f9deec3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
235 additions
and
124 deletions
+235
-124
AbstractMySQLDriver.php
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
+9
-6
MariaDb102Platform.php
lib/Doctrine/DBAL/Platforms/MariaDb102Platform.php
+3
-4
MySqlSchemaManager.php
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
+9
-13
AbstractMySQLDriverTest.php
tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
+4
-4
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+116
-97
MariaDb102PlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/MariaDb102PlatformTest.php
+94
-0
No files found.
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
View file @
4fff9761
...
...
@@ -23,9 +23,10 @@ use Doctrine\DBAL\DBALException;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Exception
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Platforms\MySQL57Platform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
use
Doctrine\DBAL\Schema\MySqlSchemaManager
;
use
Doctrine\DBAL\VersionAwarePlatformDriver
;
...
...
@@ -126,7 +127,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
*
* @return AbstractPlatform|MariaDb102
7
Platform|MySQL57Platform|MySqlPlatform
* @return AbstractPlatform|MariaDb102Platform|MySQL57Platform|MySqlPlatform
* @throws DBALException
*/
public
function
createDatabasePlatformForVersion
(
$version
)
:
AbstractPlatform
...
...
@@ -134,7 +135,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
if
(
false
!==
stripos
(
$version
,
'mariadb'
))
{
$versionNumber
=
$this
->
getMariaDbMysqlVersionNumber
(
$version
);
if
(
version_compare
(
$versionNumber
,
'10.2.7'
,
'>='
))
{
return
new
MariaDb102
7
Platform
();
return
new
MariaDb102Platform
();
}
}
else
{
$versionNumber
=
$this
->
getOracleMysqlVersionNumber
(
$version
);
...
...
@@ -196,7 +197,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
*/
public
function
getDatabase
(
\Doctrine\DBAL\Connection
$conn
)
public
function
getDatabase
(
\Doctrine\DBAL\Connection
$conn
)
:
?
string
{
$params
=
$conn
->
getParams
();
...
...
@@ -209,16 +210,18 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
* @return MySqlPlatform
*/
public
function
getDatabasePlatform
()
public
function
getDatabasePlatform
()
:
AbstractPlatform
{
return
new
MySqlPlatform
();
}
/**
* {@inheritdoc}
* @return MySqlSchemaManager
*/
public
function
getSchemaManager
(
\Doctrine\DBAL\Connection
$conn
)
public
function
getSchemaManager
(
\Doctrine\DBAL\Connection
$conn
)
:
AbstractSchemaManager
{
return
new
MySqlSchemaManager
(
$conn
);
}
...
...
lib/Doctrine/DBAL/Platforms/MariaDb102
7
Platform.php
→
lib/Doctrine/DBAL/Platforms/MariaDb102Platform.php
View file @
4fff9761
...
...
@@ -19,18 +19,17 @@
namespace
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\Types\BlobType
;
use
Doctrine\DBAL\Types\StringType
;
use
Doctrine\DBAL\Types\TextType
;
use
Doctrine\DBAL\Types\Type
;
/**
* Provides the behavior, features and SQL dialect of the MariaDB 10.2 (10.2.7 GA) database platform.
*
* Note: Should not be used with versions prior ro 10.2.7.
*
* @author Vanvelthem Sébastien
* @link www.doctrine-project.org
*/
final
class
MariaDb102
7
Platform
extends
MySqlPlatform
final
class
MariaDb102Platform
extends
MySqlPlatform
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
View file @
4fff9761
...
...
@@ -19,7 +19,7 @@
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Types\Type
;
...
...
@@ -181,7 +181,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$isNotNull
=
$tableColumn
[
'null'
]
!==
'YES'
;
if
(
$this
->
_platform
instanceof
MariaDb102
7
Platform
)
{
if
(
$this
->
_platform
instanceof
MariaDb102Platform
)
{
$columnDefault
=
$this
->
getMariaDb1027ColumnDefault
(
$this
->
_platform
,
$tableColumn
[
'default'
]
??
null
);
}
else
{
$columnDefault
=
(
isset
(
$tableColumn
[
'default'
]))
?
$tableColumn
[
'default'
]
:
null
;
...
...
@@ -217,24 +217,20 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* Return column default value for MariaDB >= 10.2.7 servers that is
* compatible with existing doctrine mysql implementation (unquoted literals)
* Return Doctrine/Mysql-compatible column default values for MariaDB 10.2.7+ servers.
*
* Since 10.2.7:
*
* 1. Column defaults stored in information_schema are now quoted
* - Since MariaDb 10.2.7 column defaults stored in information_schema are now quoted
* to distinguish them from expressions (see MDEV-10134 for a what is an expression).
* - CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE are stored in information_schema
* as current_timestamp(), currdate(), currtime()
* - Literal escaping is normalized in information schema (store "''" instead of "\'")
*
* @link https://mariadb.com/kb/en/library/information-schema-columns-table/
* @link https://jira.mariadb.org/browse/MDEV-13132
*
* 2. Quoted string defaults use double single quotes as escaping character in information_schema.
*
* @links https://mariadb.com/kb/en/library/string-literals/
*
* @param null|string $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7
*/
private
function
getMariaDb1027ColumnDefault
(
MariaDb102
7
Platform
$platform
,
?
string
$columnDefault
)
:
?
string
{
private
function
getMariaDb1027ColumnDefault
(
MariaDb102Platform
$platform
,
?
string
$columnDefault
)
:
?
string
{
if
(
$columnDefault
===
'NULL'
||
$columnDefault
===
null
)
{
$defaultValue
=
null
;
}
elseif
(
strpos
(
$columnDefault
,
"'"
)
===
0
)
{
...
...
tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
View file @
4fff9761
...
...
@@ -3,7 +3,7 @@
namespace
Doctrine\Tests\DBAL\Driver
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Platforms\MySQL57Platform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\MySqlSchemaManager
;
...
...
@@ -69,9 +69,9 @@ class AbstractMySQLDriverTest extends AbstractDriverTest
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'
,
MariaDb102
7
Platform
::
class
),
array
(
'10.2.8-MariaDB-10.2.8+maria~xenial-log'
,
MariaDb102
7
Platform
::
class
),
array
(
'10.2.8-MariaDB-1~lenny-log'
,
MariaDb102
7
Platform
::
class
)
array
(
'5.5.5-MariaDB-10.2.8+maria~xenial-log'
,
MariaDb102Platform
::
class
),
array
(
'10.2.8-MariaDB-10.2.8+maria~xenial-log'
,
MariaDb102Platform
::
class
),
array
(
'10.2.8-MariaDB-1~lenny-log'
,
MariaDb102Platform
::
class
)
);
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
4fff9761
...
...
@@ -2,12 +2,13 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\Types\MySqlPointType
;
class
MySqlSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
{
...
...
@@ -17,7 +18,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
parent
::
setUp
();
if
(
!
Type
::
hasType
(
'point'
))
{
Type
::
addType
(
'point'
,
'Doctrine\Tests\Types\MySqlPointType'
);
Type
::
addType
(
'point'
,
MySqlPointType
::
class
);
}
}
...
...
@@ -157,15 +158,15 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
*/
public
function
testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes
()
{
if
(
$this
->
_sm
->
getDatabasePlatform
()
instanceof
MariaDb102
7
Platform
)
{
$this
->
markTestSkipped
(
'MariaDb102
7
Platform supports default values for BLOB and TEXT columns and will propagate values'
);
if
(
$this
->
_sm
->
getDatabasePlatform
()
instanceof
MariaDb102Platform
)
{
$this
->
markTestSkipped
(
'MariaDb102Platform supports default values for BLOB and TEXT columns and will propagate values'
);
}
$table
=
new
Table
(
"text_blob_default_value"
);
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
'def'
)
);
$table
->
addColumn
(
'def_text_null'
,
'text'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
)
);
$table
->
addColumn
(
'def_blob'
,
'blob'
,
array
(
'default'
=>
'def'
)
);
$table
->
addColumn
(
'def_blob_null'
,
'blob'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
)
);
$table
->
addColumn
(
'def_text'
,
'text'
,
[
'default'
=>
'def'
]
);
$table
->
addColumn
(
'def_text_null'
,
'text'
,
[
'notnull'
=>
false
,
'default'
=>
'def'
]
);
$table
->
addColumn
(
'def_blob'
,
'blob'
,
[
'default'
=>
'def'
]
);
$table
->
addColumn
(
'def_blob_null'
,
'blob'
,
[
'notnull'
=>
false
,
'default'
=>
'def'
]
);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
...
...
@@ -192,37 +193,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertFalse
(
$onlineTable
->
getColumn
(
'def_blob_null'
)
->
getNotnull
());
}
/**
* Since MariaDB 10.2.1, Blob and text columns can have a default value
*
* @link https://mariadb.com/kb/en/library/blob-and-text-data-types
*/
public
function
testDefaultValueSupportForBlobAndText
()
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
instanceof
MariaDb1027Platform
)
{
$this
->
markTestSkipped
(
'Only MariaDb1027Platform supports default values for BLOB and TEXT columns'
);
}
$table
=
new
Table
(
"text_blob_default_value"
);
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_text_null'
,
'text'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
));
$table
->
addColumn
(
'def_blob'
,
'blob'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_blob_null'
,
'blob'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
));
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"text_blob_default_value"
);
self
::
assertSame
(
'def'
,
$onlineTable
->
getColumn
(
'def_text'
)
->
getDefault
());
self
::
assertSame
(
'def'
,
$onlineTable
->
getColumn
(
'def_text_null'
)
->
getDefault
());
self
::
assertSame
(
'def'
,
$onlineTable
->
getColumn
(
'def_blob'
)
->
getDefault
());
self
::
assertSame
(
'def'
,
$onlineTable
->
getColumn
(
'def_blob_null'
)
->
getDefault
());
$comparator
=
new
Comparator
();
self
::
assertFalse
(
$comparator
->
diffTable
(
$table
,
$onlineTable
));
}
public
function
testColumnCollation
()
{
$table
=
new
Table
(
'test_collation'
);
...
...
@@ -374,13 +344,12 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
*/
public
function
testColumnDefaultValuesDoubleQuoted
()
:
void
{
$table
=
new
Table
(
"test_column_default_values_double_quoted"
);
$table
->
addColumn
(
'string_nullable_quoted'
,
'string'
,
[
'notnull'
=>
false
,
'default'
=>
'NULL'
]);
$table
->
addColumn
(
'string_nullable_double_quoted'
,
'string'
,
[
'notnull'
=>
false
,
'default'
=>
"'NULL'"
]);
$table
->
addColumn
(
'string_notnull_quoted'
,
'string'
,
[
'notnull'
=>
true
,
'default'
=>
'NULL'
]);
//
$table->addColumn('string_notnull_double_quoted', 'string', ['notnull' => true, 'default' => "\\'NULL\\'"]);
$table
->
addColumn
(
'string_notnull_double_quoted'
,
'string'
,
[
'notnull'
=>
true
,
'default'
=>
"
\\
'NULL
\\
'"
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
...
...
@@ -389,16 +358,14 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertSame
(
"'NULL'"
,
$onlineTable
->
getColumn
(
'string_nullable_double_quoted'
)
->
getDefault
());
self
::
assertSame
(
"NULL"
,
$onlineTable
->
getColumn
(
'string_notnull_quoted'
)
->
getDefault
());
//self::assertSame("'NULL
'", $onlineTable->getColumn('string_notnull_double_quoted')->getDefault());
self
::
assertSame
(
"
\\
'NULL
\\
'"
,
$onlineTable
->
getColumn
(
'string_notnull_double_quoted'
)
->
getDefault
());
$comparator
=
new
Comparator
();
$diff
=
$comparator
->
diffTable
(
$table
,
$onlineTable
);
self
::
assertFalse
(
$diff
,
"Tables should be identical with double quoted literals."
);
}
public
function
testColumnDefaultCurrentTimestamp
()
:
void
{
$platform
=
$this
->
_sm
->
getDatabasePlatform
();
...
...
@@ -423,43 +390,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
}
/**
* Test default CURRENT_TIME and CURRENT_DATE as default values
*
* Note: MySQL (as of 5.7.19) does not support default value
* for DATE and TIME fields while MariaDB 10.2+ does
*/
public
function
testColumnDefaultCurrentTimeAndDate
()
{
$platform
=
$this
->
_sm
->
getDatabasePlatform
();
if
(
!
$platform
instanceof
MariaDb1027Platform
)
{
$this
->
markTestSkipped
(
'Currently only MariaDb1027Platform supports setting CURRENT_TIME and CURRENT_DATE default values.'
);
}
$table
=
new
Table
(
"test_column_defaults_current_time_and_date"
);
$currentTimeSql
=
$platform
->
getCurrentTimeSQL
();
$currentDateSql
=
$platform
->
getCurrentDateSQL
();
$table
->
addColumn
(
'col_date'
,
'date'
,
[
'notnull'
=>
true
,
'default'
=>
$currentDateSql
]);
$table
->
addColumn
(
'col_time'
,
'time'
,
[
'notnull'
=>
true
,
'default'
=>
$currentTimeSql
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"test_column_defaults_current_time_and_date"
);
self
::
assertSame
(
$currentDateSql
,
$onlineTable
->
getColumn
(
'col_date'
)
->
getDefault
());
self
::
assertSame
(
$currentTimeSql
,
$onlineTable
->
getColumn
(
'col_time'
)
->
getDefault
());
$comparator
=
new
Comparator
();
$diff
=
$comparator
->
diffTable
(
$table
,
$onlineTable
);
self
::
assertFalse
(
$diff
,
"Tables should be identical with column defaults."
);
}
/**
*
* @link https://mariadb.com/kb/en/library/string-literals
*/
public
function
testColumnDefaultValuesEscaping
()
:
void
...
...
@@ -483,9 +413,26 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertFalse
(
$diff
,
"Tables should be identical with values escape sequences."
);
}
public
function
test
ColumnDefaultsUsingDoctrineTabl
e
()
:
void
public
function
test
JsonColumnTyp
e
()
:
void
{
$platform
=
$this
->
_sm
->
getDatabasePlatform
();
if
(
!
$platform
->
hasNativeJsonType
())
{
$this
->
markTestSkipped
(
"Requires native JSON type"
);
}
$table
=
new
Table
(
'test_mysql_json'
);
$table
->
addColumn
(
'col_json'
,
'json'
);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$columns
=
$this
->
_sm
->
listTableColumns
(
'test_mysql_json'
);
self
::
assertSame
(
TYPE
::
JSON
,
$columns
[
'col_json'
]
->
getType
()
->
getName
());
}
/**
* @todo split into multiple tests (most of them already made) and remove
*/
public
function
testColumnDefaultsUsingDoctrineTable
()
:
void
{
$table
=
new
Table
(
"test_column_defaults_with_table"
);
$table
->
addColumn
(
'col0'
,
'integer'
,
[
'notnull'
=>
false
]);
$table
->
addColumn
(
'col1'
,
'integer'
,
[
'notnull'
=>
false
,
'default'
=>
null
]);
...
...
@@ -534,20 +481,22 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
}
/**
* Ensure that an existing table with quoted (literals) default values
* does not trigger a table change.
* Ensure that a table created outside doctrine and containing
* quoted default values does not trigger a table diff change. I
* Note: MariaDb 10.2 silently change "\'" into "''" when storing in
* information schema, MariaDb102Platform should normalize the table details.
*/
public
function
test
ColumnDefaultsDoesNotTriggerADiff
()
:
void
public
function
test
ExistingTableWithQuotedDefaultsDoesNotTriggerChange
()
:
void
{
$this
->
_conn
->
query
(
'DROP TABLE IF EXISTS test_column_defaults_
no_diff
'
);
$this
->
_conn
->
query
(
'DROP TABLE IF EXISTS test_column_defaults_
with_create
'
);
$sql
=
"
CREATE TABLE test_column_defaults_with_create (
col1 VARCHAR(255) NULL DEFAULT 'O''Connor\'
\"
',
col2 VARCHAR(255) NULL DEFAULT '''A'''
);
"
;
$this
->
_conn
->
query
(
$sql
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"test_column_defaults_with_create"
);
self
::
assertSame
(
"O'Connor'
\"
"
,
$onlineTable
->
getColumn
(
'col1'
)
->
getDefault
());
self
::
assertSame
(
"'A'"
,
$onlineTable
->
getColumn
(
'col2'
)
->
getDefault
());
...
...
@@ -561,16 +510,87 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertFalse
(
$diff
);
}
/**
* Since MariaDB 10.2.1, Blob and text columns can have a default value
*
* @link https://mariadb.com/kb/en/library/blob-and-text-data-types
*/
public
function
testDoesPropagateDefaultValuesForBlobTextAndJson
()
:
void
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
instanceof
MariaDb102Platform
)
{
$this
->
markTestSkipped
(
'Only relevant for MariaDb102Platform.'
);
}
$table
=
new
Table
(
"text_blob_default_value"
);
$json
=
json_encode
([
'prop1'
=>
"O'Connor"
,
'prop2'
=>
10
]);
$table
->
addColumn
(
'def_text'
,
'text'
,
[
'default'
=>
"O'Connor"
]);
$table
->
addColumn
(
'def_text_null'
,
'text'
,
[
'notnull'
=>
false
,
'default'
=>
'def'
]);
$table
->
addColumn
(
'def_blob'
,
'blob'
,
[
'default'
=>
'def'
]);
$table
->
addColumn
(
'def_json'
,
'json'
,
[
'default'
=>
$json
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"text_blob_default_value"
);
self
::
assertSame
(
"O'Connor"
,
$onlineTable
->
getColumn
(
'def_text'
)
->
getDefault
());
self
::
assertSame
(
'def'
,
$onlineTable
->
getColumn
(
'def_text_null'
)
->
getDefault
());
self
::
assertSame
(
'def'
,
$onlineTable
->
getColumn
(
'def_blob'
)
->
getDefault
());
self
::
assertSame
(
$json
,
$onlineTable
->
getColumn
(
'def_json'
)
->
getDefault
());
$comparator
=
new
Comparator
();
self
::
assertFalse
(
$comparator
->
diffTable
(
$table
,
$onlineTable
));
}
/**
* Note: MySQL (as of 5.7.19) does not support default value
* for DATE and TIME fields while MariaDB 10.2+ does
*/
public
function
testColumnDefaultValuesCurrentTimeAndDate
()
:
void
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
instanceof
MariaDb102Platform
)
{
$this
->
markTestSkipped
(
'Only relevant for MariaDb102Platform.'
);
}
$platform
=
$this
->
_sm
->
getDatabasePlatform
();
$table
=
new
Table
(
"test_column_defaults_current_time_and_date"
);
$currentTimeSql
=
$platform
->
getCurrentTimeSQL
();
$currentDateSql
=
$platform
->
getCurrentDateSQL
();
$table
->
addColumn
(
'col_date'
,
'date'
,
[
'notnull'
=>
true
,
'default'
=>
$currentDateSql
]);
$table
->
addColumn
(
'col_time'
,
'time'
,
[
'notnull'
=>
true
,
'default'
=>
$currentTimeSql
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"test_column_defaults_current_time_and_date"
);
self
::
assertSame
(
$currentDateSql
,
$onlineTable
->
getColumn
(
'col_date'
)
->
getDefault
());
self
::
assertSame
(
$currentTimeSql
,
$onlineTable
->
getColumn
(
'col_time'
)
->
getDefault
());
$comparator
=
new
Comparator
();
$diff
=
$comparator
->
diffTable
(
$table
,
$onlineTable
);
self
::
assertFalse
(
$diff
,
"Tables should be identical with column defaults."
);
}
/**
* MariaDB supports expressions as default values
*
* @todo remove or implement !!!
*
* @link https://mariadb.com/kb/en/library/information-schema-columns-table/
*/
public
function
testColumnDefaultExpressions
()
:
void
{
$this
->
markTestSkipped
(
'Setting an expression as a default value is not yet supported (WIP)'
);
if
(
$this
->
_sm
->
getDatabasePlatform
()
instanceof
MariaDb1027Platform
)
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
instanceof
MariaDb102Platform
)
{
$this
->
markTestSkipped
(
'Only relevant for MariaDb102Platform.'
);
}
$table
=
new
Table
(
"test_column_default_expressions"
);
...
...
@@ -586,6 +606,5 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$diff
=
$comparator
->
diffTable
(
$table
,
$onlineTable
);
self
::
assertFalse
(
$diff
,
"Tables should be identical with expression column defaults."
);
}
}
}
tests/Doctrine/Tests/DBAL/Platforms/MariaDb102
7
PlatformTest.php
→
tests/Doctrine/Tests/DBAL/Platforms/MariaDb102PlatformTest.php
View file @
4fff9761
...
...
@@ -2,19 +2,19 @@
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Types\Type
;
class
MariaDb102
7
PlatformTest
extends
AbstractMySQLPlatformTestCase
class
MariaDb102PlatformTest
extends
AbstractMySQLPlatformTestCase
{
/**
* {@inheritdoc}
*/
public
function
createPlatform
()
{
return
new
MariaDb102
7
Platform
();
return
new
MariaDb102Platform
();
}
public
function
testHasNativeJsonType
()
...
...
@@ -34,29 +34,61 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
}
/**
* Overrides AbstractMySQLPlatformTestCase::testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
* Overrides and skips AbstractMySQLPlatformTestCase test regarding propagation
* of unsupported default values for Blob and Text columns.
*
* @see AbstractMySQLPlatformTestCase::testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
*/
public
function
testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes
()
{
$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
()
{
$table
=
new
Table
(
"text_blob_default_value"
);
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
"d''ef"
));
$table
->
addColumn
(
'def_blob'
,
'blob'
,
array
(
'default'
=>
'def'
));
self
::
assertSame
(
array
(
'CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT \'def\' NOT NULL, def_blob LONGBLOB DEFAULT \'def\' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
)
,
[
"CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT 'd''''ef' NOT NULL, def_blob LONGBLOB DEFAULT 'def' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"
]
,
$this
->
_platform
->
getCreateTableSQL
(
$table
)
);
$diffTable
=
clone
$table
;
$diffTable
->
changeColumn
(
'def_text'
,
array
(
'default'
=>
'def'
)
);
$diffTable
->
changeColumn
(
'def_blob'
,
array
(
'default'
=>
'def'
)
);
$diffTable
->
changeColumn
(
'def_text'
,
[
'default'
=>
"d''ef"
]
);
$diffTable
->
changeColumn
(
'def_blob'
,
[
'default'
=>
'def'
]
);
$comparator
=
new
Comparator
();
self
::
assertFalse
(
$comparator
->
diffTable
(
$table
,
$diffTable
));
}
public
function
testPropagateDefaultValuesForJsonColumnType
()
{
$table
=
new
Table
(
"text_json_default_value"
);
$json
=
json_encode
([
'prop1'
=>
"O'Connor"
,
'prop2'
=>
10
]);
$table
->
addColumn
(
'def_json'
,
'text'
,
[
'default'
=>
$json
]);
self
::
assertSame
(
[
"CREATE TABLE text_json_default_value (def_json LONGTEXT DEFAULT '
{
\"prop1\":\"O''Connor\",\"prop2\":10
}
' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"
],
$this
->
_platform
->
getCreateTableSQL
(
$table
)
);
$diffTable
=
clone
$table
;
$diffTable
->
changeColumn
(
'def_json'
,
[
'default'
=>
$json
]);
$comparator
=
new
Comparator
();
self
::
assertFalse
(
$comparator
->
diffTable
(
$table
,
$diffTable
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment