Failed Conditions
Pull Request — master (#2825)
by Sébastien
25:59
created

MariaDb1027PlatformTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 90
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createPlatform() 0 4 1
A testHasNativeJsonType() 0 4 1
A testReturnsJsonTypeDeclarationSQL() 0 4 1
A testInitializesJsonTypeMapping() 0 5 1
A testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() 0 4 1
A testPropagateDefaultValuesForTextAndBlobColumnTypes() 0 21 1
A testPropagateDefaultValuesForJsonColumnType() 0 23 1
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
    /**
26
     * From MariaDB 10.2.7, JSON type is an alias to LONGTEXT
27
     * @link https://mariadb.com/kb/en/library/json-data-type/
28
     */
29
    public function testReturnsJsonTypeDeclarationSQL() : void
30
    {
31
        self::assertSame('LONGTEXT', $this->_platform->getJsonTypeDeclarationSQL([]));
32
    }
33
34
    public function testInitializesJsonTypeMapping() : void
35
    {
36
        self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('json'));
37
        self::assertSame(Type::JSON, $this->_platform->getDoctrineTypeMapping('json'));
38
    }
39
40
    /**
41
     * Overrides and skips AbstractMySQLPlatformTestCase test regarding propagation
42
     * of unsupported default values for Blob and Text columns.
43
     *
44
     * @see AbstractMySQLPlatformTestCase::testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
45
     */
46
    public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : void
47
    {
48
        $this->markTestSkipped('MariaDB102Platform support propagation of default values for BLOB and TEXT columns');
49
    }
50
51
    /**
52
     * Since MariaDB 10.2, Text and Blob can have a default value.
53
     */
54
    public function testPropagateDefaultValuesForTextAndBlobColumnTypes() : void
55
    {
56
        $table = new Table("text_blob_default_value");
57
58
        $table->addColumn('def_text', Type::TEXT, ['default' => "hello"]);
59
        $table->addColumn('def_blob', Type::BLOB, ['default' => 'world']);
60
61
        self::assertSame(
62
            ["CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT 'hello' NOT NULL, def_blob LONGBLOB DEFAULT 'world' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"],
63
            $this->_platform->getCreateTableSQL($table)
64
        );
65
66
        $diffTable = clone $table;
67
68
        $diffTable->changeColumn('def_text', ['default' => "hello"]);
69
        $diffTable->changeColumn('def_blob', ['default' => 'world']);
70
71
        $comparator = new Comparator();
72
73
        self::assertFalse($comparator->diffTable($table, $diffTable));
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) targeting Doctrine\DBAL\Schema\Comparator::diffTable() can also be of type object<Doctrine\DBAL\Schema\TableDiff>; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

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.

Loading history...
74
    }
75
76
    public function testPropagateDefaultValuesForJsonColumnType() : void
77
    {
78
        $table = new Table("text_json_default_value");
79
80
        $json = json_encode(['prop1' => "Hello", 'prop2' => 10]);
81
82
        $table->addColumn('def_json', Type::TEXT, ['default' => $json]);
83
84
        $jsonType = $this->createPlatform()->getJsonTypeDeclarationSQL($table->getColumn('def_json')->toArray());
85
86
        self::assertSame(
87
            ["CREATE TABLE text_json_default_value (def_json $jsonType DEFAULT '{\"prop1\":\"Hello\",\"prop2\":10}' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"],
88
            $this->_platform->getCreateTableSQL($table)
89
        );
90
91
        $diffTable = clone $table;
92
93
        $diffTable->changeColumn('def_json', ['default' => $json]);
94
95
        $comparator = new Comparator();
96
97
        self::assertFalse($comparator->diffTable($table, $diffTable));
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table, $diffTable) targeting Doctrine\DBAL\Schema\Comparator::diffTable() can also be of type object<Doctrine\DBAL\Schema\TableDiff>; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

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.

Loading history...
98
    }
99
}
100