1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Platforms; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\MariaDb1027Platform; |
6
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
7
|
|
|
use Doctrine\DBAL\Schema\Table; |
8
|
|
|
use Doctrine\DBAL\Types\Type; |
9
|
|
|
|
10
|
|
|
class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
public function createPlatform() : MariaDb1027Platform |
16
|
|
|
{ |
17
|
|
|
return new MariaDb1027Platform(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testHasNativeJsonType() : void |
21
|
|
|
{ |
22
|
|
|
self::assertTrue($this->_platform->hasNativeJsonType()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testReturnsJsonTypeDeclarationSQL() : void |
26
|
|
|
{ |
27
|
|
|
self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([])); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testInitializesJsonTypeMapping() : void |
31
|
|
|
{ |
32
|
|
|
self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); |
33
|
|
|
self::assertSame(Type::JSON, $this->_platform->getDoctrineTypeMapping('json')); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Overrides and skips AbstractMySQLPlatformTestCase test regarding propagation |
38
|
|
|
* of unsupported default values for Blob and Text columns. |
39
|
|
|
* |
40
|
|
|
* @see AbstractMySQLPlatformTestCase::testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() |
41
|
|
|
*/ |
42
|
|
|
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : void |
43
|
|
|
{ |
44
|
|
|
$this->markTestSkipped('MariaDB102Platform support propagation of default values for BLOB and TEXT columns'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Since MariaDB 10.2, Text and Blob can have a default value. |
49
|
|
|
*/ |
50
|
|
|
public function testPropagateDefaultValuesForTextAndBlobColumnTypes() : void |
51
|
|
|
{ |
52
|
|
|
$table = new Table("text_blob_default_value"); |
53
|
|
|
|
54
|
|
|
$table->addColumn('def_text', 'text', array('default' => "d''ef")); |
55
|
|
|
$table->addColumn('def_blob', 'blob', array('default' => 'def')); |
56
|
|
|
|
57
|
|
|
self::assertSame( |
58
|
|
|
["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"], |
59
|
|
|
$this->_platform->getCreateTableSQL($table) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$diffTable = clone $table; |
63
|
|
|
|
64
|
|
|
$diffTable->changeColumn('def_text', ['default' => "d''ef"]); |
65
|
|
|
$diffTable->changeColumn('def_blob', ['default' => 'def']); |
66
|
|
|
|
67
|
|
|
$comparator = new Comparator(); |
68
|
|
|
|
69
|
|
|
self::assertFalse($comparator->diffTable($table, $diffTable)); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testPropagateDefaultValuesForJsonColumnType() : void |
73
|
|
|
{ |
74
|
|
|
$table = new Table("text_json_default_value"); |
75
|
|
|
|
76
|
|
|
$json = json_encode(['prop1' => "O'Connor", 'prop2' => 10]); |
77
|
|
|
|
78
|
|
|
$table->addColumn('def_json', 'text', ['default' => $json]); |
79
|
|
|
|
80
|
|
|
self::assertSame( |
81
|
|
|
["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"], |
82
|
|
|
$this->_platform->getCreateTableSQL($table) |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$diffTable = clone $table; |
86
|
|
|
|
87
|
|
|
$diffTable->changeColumn('def_json', ['default' => $json]); |
88
|
|
|
|
89
|
|
|
$comparator = new Comparator(); |
90
|
|
|
|
91
|
|
|
self::assertFalse($comparator->diffTable($table, $diffTable)); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.