Completed
Pull Request — 2.6 (#2865)
by Gawain
04:57
created

SqliteSchemaManagerTest::getDataColumnCollation()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Schema;
4
5
use Doctrine\DBAL\Platforms\SqlitePlatform;
6
use Doctrine\DBAL\Schema\SqliteSchemaManager;
7
8
class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase
9
{
10
    /**
11
     * @dataProvider getDataColumnCollation
12
     */
13 View Code Duplication
    public function testParseColumnCollation($collation, $column, $sql)
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...
14
    {
15
        $conn = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
16
        $conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue(new SqlitePlatform()));
17
18
        $manager = new SqliteSchemaManager($conn);
19
        $ref = new \ReflectionMethod($manager, 'parseColumnCollationFromSQL');
20
        $ref->setAccessible(true);
21
22
        $this->assertEquals($collation, $ref->invoke($manager, $column, $sql));
23
    }
24
25
    public function getDataColumnCollation()
26
    {
27
        return array(
28
            array(
29
                'RTRIM', 'a', 'CREATE TABLE "a" ("a" text DEFAULT "aa" COLLATE "RTRIM" NOT NULL)'
30
            ),
31
            array(
32
                'utf-8', 'a', 'CREATE TABLE "a" ("b" text UNIQUE NOT NULL COLLATE NOCASE, "a" text DEFAULT "aa" COLLATE "utf-8" NOT NULL)'
33
            ),
34
            array(
35
                'NOCASE', 'a', 'CREATE TABLE "a" ("a" text DEFAULT (lower(ltrim(" a") || rtrim("a "))) CHECK ("a") NOT NULL COLLATE NOCASE UNIQUE, "b" text COLLATE RTRIM)'
36
            ),
37
            array(
38
                false, 'a', 'CREATE TABLE "a" ("a" text CHECK ("a") NOT NULL, "b" text COLLATE RTRIM)'
39
            ),
40
            array(
41
                'RTRIM', 'a"b', 'CREATE TABLE "a" ("a""b" text COLLATE RTRIM)'
42
            ),
43
            array(
44
                'BINARY', 'b', 'CREATE TABLE "a" (bb TEXT COLLATE RTRIM, b VARCHAR(42) NOT NULL COLLATE BINARY)'
45
            ),
46
            array(
47
                'BINARY', 'b', 'CREATE TABLE "a" (bbb TEXT COLLATE NOCASE, bb TEXT COLLATE RTRIM, b VARCHAR(42) NOT NULL COLLATE BINARY)'
48
            ),
49
            array(
50
                'BINARY', 'b', 'CREATE TABLE "a" (b VARCHAR(42) NOT NULL COLLATE BINARY, bb TEXT COLLATE RTRIM)'
51
            ),
52
        );
53
    }
54
55
    /**
56
     * @dataProvider getDataColumnComment
57
     */
58 View Code Duplication
    public function testParseColumnCommentFromSQL($comment, $column, $sql)
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...
59
    {
60
        $conn = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
61
        $conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue(new SqlitePlatform()));
62
63
        $manager = new SqliteSchemaManager($conn);
64
        $ref = new \ReflectionMethod($manager, 'parseColumnCommentFromSQL');
65
        $ref->setAccessible(true);
66
67
        $this->assertEquals($comment, $ref->invoke($manager, $column, $sql));
68
    }
69
70
    public function getDataColumnComment()
71
    {
72
        return array(
73
            'Single column with no comment' => array(
74
                false, 'a', 'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)',
75
            ),
76
77
            'Single column with type comment' => array(
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' => array(
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' => array(
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' => array(
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' => array(
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
        );
99
    }
100
}
101