TdbmFluidColumnTest::testReference()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\FluidSchema;
4
5
use Doctrine\DBAL\Schema\Schema;
6
use Doctrine\DBAL\Types\Type;
7
use PHPUnit\Framework\TestCase;
8
9
class TdbmFluidColumnTest extends TestCase
10
{
11
    public function testTypes()
12
    {
13
        $schema = new Schema();
14
        $fluid = new TdbmFluidSchema($schema);
15
16
        $posts = $fluid->table('posts');
17
18
        $column = $posts->column('foo');
19
20
        $dbalColumn = $schema->getTable('posts')->getColumn('foo');
21
22
        $column->integer();
23
        $this->assertSame(Type::getType(Type::INTEGER), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::INTEGER has been deprecated with message: Use {@see DefaultTypes::INTEGER} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
24
25
        $column->smallInt();
26
        $this->assertSame(Type::getType(Type::SMALLINT), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::SMALLINT has been deprecated with message: Use {@see DefaultTypes::SMALLINT} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
27
28
        $column->bigInt();
29
        $this->assertSame(Type::getType(Type::BIGINT), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::BIGINT has been deprecated with message: Use {@see DefaultTypes::BIGINT} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
30
31
        $column->decimal(12, 32);
32
        $this->assertSame(Type::getType(Type::DECIMAL), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::DECIMAL has been deprecated with message: Use {@see DefaultTypes::DECIMAL} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
33
        $this->assertSame(12, $dbalColumn->getPrecision());
34
        $this->assertSame(32, $dbalColumn->getScale());
35
36
        $column->float(32, 12);
37
        $this->assertSame(Type::getType(Type::FLOAT), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::FLOAT has been deprecated with message: Use {@see DefaultTypes::FLOAT} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
38
        $this->assertSame(32, $dbalColumn->getPrecision());
39
        $this->assertSame(12, $dbalColumn->getScale());
40
41
        $column->string(42, true);
42
        $this->assertSame(Type::getType(Type::STRING), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::STRING has been deprecated with message: Use {@see DefaultTypes::STRING} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
43
        $this->assertSame(42, $dbalColumn->getLength());
44
        $this->assertSame(true, $dbalColumn->getFixed());
45
46
        $column->text();
47
        $this->assertSame(Type::getType(Type::TEXT), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::TEXT has been deprecated with message: Use {@see DefaultTypes::TEXT} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
48
49
        $column->guid();
50
        $this->assertSame(Type::getType(Type::GUID), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::GUID has been deprecated with message: Use {@see DefaultTypes::GUID} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
51
52
        $column->blob();
53
        $this->assertSame(Type::getType(Type::BLOB), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::BLOB has been deprecated with message: Use {@see DefaultTypes::BLOB} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
54
55
        $column->boolean();
56
        $this->assertSame(Type::getType(Type::BOOLEAN), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::BOOLEAN has been deprecated with message: Use {@see DefaultTypes::BOOLEAN} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
57
58
        $column->date();
59
        $this->assertSame(Type::getType(Type::DATE), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::DATE has been deprecated with message: Use {@see DefaultTypes::DATE_MUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
60
61
        $column->datetime();
62
        $this->assertSame(Type::getType(Type::DATETIME), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::DATETIME has been deprecated with message: Use {@see DefaultTypes::DATETIME_MUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
63
64
        $column->datetimeTz();
65
        $this->assertSame(Type::getType(Type::DATETIMETZ), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::DATETIMETZ has been deprecated with message: Use {@see DefaultTypes::DATETIMETZ_MUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
66
67
        $column->time();
68
        $this->assertSame(Type::getType(Type::TIME), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::TIME has been deprecated with message: Use {@see DefaultTypes::TIME_MUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
69
70
        $column->array();
71
        $this->assertSame(Type::getType(Type::TARRAY), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::TARRAY has been deprecated with message: Use {@see DefaultTypes::ARRAY} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
72
73
        $column->simpleArray();
74
        $this->assertSame(Type::getType(Type::SIMPLE_ARRAY), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::SIMPLE_ARRAY has been deprecated with message: Use {@see DefaultTypes::SIMPLE_ARRAY} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
75
76
        $column->jsonArray();
77
        $this->assertSame(Type::getType(Type::JSON_ARRAY), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::JSON_ARRAY has been deprecated with message: Use {@see DefaultTypes::JSON_ARRAY} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
78
79
        $column->object();
80
        $this->assertSame(Type::getType(Type::OBJECT), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::OBJECT has been deprecated with message: Use {@see DefaultTypes::OBJECT} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
81
82
        if (defined('Doctrine\\DBAL\\Types\\Type::BINARY')) {
83
            $column->binary(43);
84
            $this->assertSame(Type::getType(Type::BINARY), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::BINARY has been deprecated with message: Use {@see DefaultTypes::BINARY} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
85
            $this->assertSame(43, $dbalColumn->getLength());
86
            $this->assertSame(false, $dbalColumn->getFixed());
87
        }
88
89
        if (defined('Doctrine\\DBAL\\Types\\Type::DATE_IMMUTABLE')) {
90
            // Doctrine DBAL 2.6+
91
            $column->dateImmutable();
92
            $this->assertSame(Type::getType('date_immutable'), $dbalColumn->getType());
93
94
            $column->datetimeImmutable();
95
            $this->assertSame(Type::getType(Type::DATETIME_IMMUTABLE), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::DATETIME_IMMUTABLE has been deprecated with message: Use {@see DefaultTypes::DATETIME_IMMUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
96
97
            $column->datetimeTzImmutable();
98
            $this->assertSame(Type::getType(Type::DATETIMETZ_IMMUTABLE), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::DATETIMETZ_IMMUTABLE has been deprecated with message: Use {@see DefaultTypes::DATETIMETZ_IMMUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
99
100
            $column->time();
101
            $this->assertSame(Type::getType(Type::TIME), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::TIME has been deprecated with message: Use {@see DefaultTypes::TIME_MUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
102
103
            $column->timeImmutable();
104
            $this->assertSame(Type::getType(Type::TIME_IMMUTABLE), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::TIME_IMMUTABLE has been deprecated with message: Use {@see DefaultTypes::TIME_IMMUTABLE} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
105
106
            $column->dateInterval();
107
            $this->assertSame(Type::getType(Type::DATEINTERVAL), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::DATEINTERVAL has been deprecated with message: Use {@see DefaultTypes::DATEINTERVAL} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
108
109
            $column->json();
110
            $this->assertSame(Type::getType(Type::JSON), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::JSON has been deprecated with message: Use {@see DefaultTypes::JSON} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
111
        }
112
113
        $this->assertSame('foo', $column->getDbalColumn()->getName());
114
    }
115
116 View Code Duplication
    public function testReference()
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...
117
    {
118
        $schema = new Schema();
119
        $fluid = new TdbmFluidSchema($schema);
120
121
        $countries = $fluid->table('countries');
122
        $countries->id();
123
124
        $users = $fluid->table('users');
125
        $users->column('country_id')->references('countries', 'myfk');
126
127
        $dbalColumn = $schema->getTable('users')->getColumn('country_id');
128
129
        $this->assertSame(Type::getType(Type::INTEGER), $dbalColumn->getType());
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::INTEGER has been deprecated with message: Use {@see DefaultTypes::INTEGER} instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
130
        $fk = $schema->getTable('users')->getForeignKey('myfk');
131
        $this->assertSame('users', $fk->getLocalTableName());
132
        $this->assertSame('countries', $fk->getForeignTableName());
133
        $this->assertSame(['country_id'], $fk->getLocalColumns());
134
    }
135
136
    public function testReferenceException()
137
    {
138
        $schema = new Schema();
139
        $fluid = new TdbmFluidSchema($schema);
140
141
        $countries = $fluid->table('countries');
142
        $countries->column('id1')->integer();
143
        $countries->column('id2')->integer();
144
        $countries->primaryKey(['id1','id2']);
145
146
        $users = $fluid->table('users');
147
        $this->expectException(FluidSchemaException::class);
148
        $users->column('country_id')->references('countries', 'myfk');
149
    }
150
}
151