Completed
Push — develop ( fa6865...01fb76 )
by Freddie
10:19
created

ColumnTest::testItDefinitionPk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 18
rs 9.8333
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Database\Tests;
11
12
use FlexPHP\Database\Column;
13
use FlexPHP\Schema\SchemaAttribute;
14
15
class ColumnTest extends TestCase
16
{
17
    public function testItDefinition(): void
18
    {
19
        $schemaAttribute = new SchemaAttribute('foo', 'string', [
20
            'min' => 10,
21
            'max' => 100,
22
        ]);
23
24
        $column = new Column($schemaAttribute);
25
26
        $this->assertEquals($schemaAttribute->name(), $column->getName());
27
        $this->assertEquals($schemaAttribute->dataType(), $column->getType());
28
        $this->assertFalse($column->isPrimaryKey());
29
        $this->assertFalse($column->isForeingKey());
30
        $this->assertEquals([
31
            'length' => $schemaAttribute->maxLength(),
32
            'notnull' => $schemaAttribute->isRequired(),
33
            'autoincrement' => $schemaAttribute->isAi(),
34
            'comment' => $schemaAttribute->name(),
35
        ], $column->getOptions());
36
    }
37
38
    public function testItDefinitionAi(): void
39
    {
40
        $schemaAttribute = new SchemaAttribute('foo', 'integer', [
41
            'pk' => true,
42
            'ai' => true,
43
        ]);
44
45
        $column = new Column($schemaAttribute);
46
47
        $this->assertEquals($schemaAttribute->name(), $column->getName());
48
        $this->assertEquals($schemaAttribute->dataType(), $column->getType());
49
        $this->assertTrue($column->isPrimaryKey());
50
        $this->assertFalse($column->isForeingKey());
51
        $this->assertEquals([
52
            'length' => $schemaAttribute->maxLength(),
53
            'notnull' => $schemaAttribute->isRequired(),
54
            'autoincrement' => $schemaAttribute->isAi(),
55
            'comment' => $schemaAttribute->name(),
56
        ], $column->getOptions());
57
    }
58
59
    public function testItDefinitionPk(): void
60
    {
61
        $schemaAttribute = new SchemaAttribute('bar', 'integer', [
62
            'fk' => 'baz',
63
        ]);
64
65
        $column = new Column($schemaAttribute);
66
67
        $this->assertEquals($schemaAttribute->name(), $column->getName());
68
        $this->assertEquals($schemaAttribute->dataType(), $column->getType());
69
        $this->assertFalse($column->isPrimaryKey());
70
        $this->assertTrue($column->isForeingKey());
71
        $this->assertEquals([
72
            'length' => $schemaAttribute->maxLength(),
73
            'notnull' => $schemaAttribute->isRequired(),
74
            'autoincrement' => $schemaAttribute->isAi(),
75
            'comment' => $schemaAttribute->name(),
76
        ], $column->getOptions());
77
    }
78
}
79