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

MariaDb102PlatformTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 85
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 21 1
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\Platforms\MariaDb102Platform;
6
use Doctrine\DBAL\Schema\Comparator;
7
use Doctrine\DBAL\Schema\Table;
8
use Doctrine\DBAL\Types\Type;
9
10
class MariaDb102PlatformTest extends AbstractMySQLPlatformTestCase
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function createPlatform()
16
    {
17
        return new MariaDb102Platform();
18
    }
19
20
    public function testHasNativeJsonType()
21
    {
22
        self::assertTrue($this->_platform->hasNativeJsonType());
23
    }
24
25
    public function testReturnsJsonTypeDeclarationSQL()
26
    {
27
        self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([]));
28
    }
29
30
    public function testInitializesJsonTypeMapping()
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()
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()
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));
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...
70
    }
71
72
    public function testPropagateDefaultValuesForJsonColumnType()
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));
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...
92
    }
93
94
}
95