Passed
Pull Request — master (#2865)
by Gawain
42:12
created

SqliteSchemaManagerTest::getDataColumnComment()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 39
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Schema;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Platforms\SqlitePlatform;
7
use Doctrine\DBAL\Schema\SqliteSchemaManager;
8
9
class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase
10
{
11
    /**
12
     * @dataProvider getDataColumnCollation
13
     */
14 View Code Duplication
    public function testParseColumnCollation($collation, string $column, string $sql) : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    {
16
        $conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
17
        $conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform());
18
19
        $manager = new SqliteSchemaManager($conn);
20
        $ref     = new \ReflectionMethod($manager, 'parseColumnCollationFromSQL');
21
        $ref->setAccessible(true);
22
23
        self::assertEquals($collation, $ref->invoke($manager, $column, $sql));
24
    }
25
26
    public function getDataColumnCollation()
27
    {
28
        return [
29
            [
30
                'RTRIM', 'a', 'CREATE TABLE "a" ("a" text DEFAULT "aa" COLLATE "RTRIM" NOT NULL)',
31
            ],
32
            [
33
                'utf-8', 'a', 'CREATE TABLE "a" ("b" text UNIQUE NOT NULL COLLATE NOCASE, "a" text DEFAULT "aa" COLLATE "utf-8" NOT NULL)',
34
            ],
35
            [
36
                'NOCASE', 'a', 'CREATE TABLE "a" ("a" text DEFAULT (lower(ltrim(" a") || rtrim("a "))) CHECK ("a") NOT NULL COLLATE NOCASE UNIQUE, "b" text COLLATE RTRIM)',
37
            ],
38
            [
39
                false, 'a', 'CREATE TABLE "a" ("a" text CHECK ("a") NOT NULL, "b" text COLLATE RTRIM)',
40
            ],
41
            [
42
                'RTRIM', 'a"b', 'CREATE TABLE "a" ("a""b" text COLLATE RTRIM)',
43
            ],
44
            [
45
                'BINARY', 'b', 'CREATE TABLE "a" (bb TEXT COLLATE RTRIM, b VARCHAR(42) NOT NULL COLLATE BINARY)',
46
            ],
47
            [
48
                'BINARY', 'b', 'CREATE TABLE "a" (bbb TEXT COLLATE NOCASE, bb TEXT COLLATE RTRIM, b VARCHAR(42) NOT NULL COLLATE BINARY)',
49
            ],
50
            [
51
                'BINARY', 'b', 'CREATE TABLE "a" (b VARCHAR(42) NOT NULL COLLATE BINARY, bb TEXT COLLATE RTRIM)',
52
            ],
53
        ];
54
    }
55
56
    /**
57
     * @dataProvider getDataColumnComment
58
     */
59 View Code Duplication
    public function testParseColumnCommentFromSQL($comment, string $column, string $sql) : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
62
        $conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform());
63
64
        $manager = new SqliteSchemaManager($conn);
65
        $ref     = new \ReflectionMethod($manager, 'parseColumnCommentFromSQL');
66
        $ref->setAccessible(true);
67
68
        self::assertSame($comment, $ref->invoke($manager, $column, $sql));
69
    }
70
71
    public function getDataColumnComment()
72
    {
73
        return [
74
            'Single column with no comment' => [
75
                false, 'a', 'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)',
76
            ],
77
            'Single column with type comment' => [
78
                '(DC2Type:x)', 'a', 'CREATE TABLE "a" ("a" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x)
79
)',
80
            ],
81
82
            'Multiple similar columns with type comment 1' => [
83
                false, 'b', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" TEXT DEFAULT "a" COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x)
84
)',
85
            ],
86
            'Multiple similar columns with type comment 2' => [
87
                '(DC2Type:x)', 'b', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" TEXT DEFAULT "a" COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x)
88
)',
89
            ],
90
            'Multiple similar columns on different lines, with type comment 1' => [
91
                false, 'bb', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x)
92
, "bb" TEXT DEFAULT "a" COLLATE RTRIM',
93
            ],
94
            'Multiple similar columns on different lines, with type comment 2' => [
95
                '(DC2Type:x)', 'bb', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x)
96
, "b" TEXT DEFAULT "a" COLLATE RTRIM',
97
            ],
98
            'Column with numeric but no comment 1' => [
99
                false, 'a', 'CREATE TABLE "a" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array)
100
, "c" CHAR(36) NOT NULL --(DC2Type:guid)
101
)',
102
            ],
103
            'Column with numeric but no comment 2' => [
104
                false, 'a', 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array)
105
, "c" CHAR(36) NOT NULL --(DC2Type:guid)
106
)',
107
            ],
108
            'Column with numeric but no comment 3' => [
109
                '(DC2Type:guid)', 'c', 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array)
110
, "c" CHAR(36) NOT NULL --(DC2Type:guid)
111
)',
112
            ],
113
        ];
114
    }
115
}
116