TdbmFluidColumnOptionsTest::testOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 9.216
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 TdbmFluidColumnOptionsTest extends TestCase
10
{
11
    public function testOptions()
12
    {
13
        $schema = new Schema();
14
        $fluid = new TdbmFluidSchema($schema);
15
16
        $posts = $fluid->table('posts');
17
18
        $column = $posts->column('foo');
19
        $columnOptions = $column->integer();
20
21
        $dbalColumn = $schema->getTable('posts')->getColumn('foo');
22
23
        $columnOptions->null();
24
        $this->assertSame(false, $dbalColumn->getNotnull());
25
26
        $columnOptions->notNull();
27
        $this->assertSame(true, $dbalColumn->getNotnull());
28
29
        $columnOptions->unique();
30
        $this->assertSame(true, $dbalColumn->getCustomSchemaOption('unique'));
31
32
        $columnOptions->comment('foo');
33
        $this->assertSame('foo', $dbalColumn->getComment());
34
35
        $columnOptions->autoIncrement();
36
        $this->assertSame(true, $dbalColumn->getAutoincrement());
37
38
        $columnOptions->default(42);
39
        $this->assertSame(42, $dbalColumn->getDefault());
40
41
        $columnOptions->protectedGetter();
42
        $this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedGetter', $dbalColumn->getComment());
43
44
        $columnOptions->protectedSetter();
45
        $this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedSetter', $dbalColumn->getComment());
46
47
        $columnOptions->protectedOneToMany();
48
        $this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedOneToMany', $dbalColumn->getComment());
49
50
        $this->assertSame($posts, $columnOptions->then());
51
52
        $columnOptions->column('bar');
53
        $this->assertTrue($schema->getTable('posts')->hasColumn('bar'));
54
    }
55
56
    public function testIndex()
57
    {
58
        $schema = new Schema();
59
        $fluid = new TdbmFluidSchema($schema);
60
61
        $posts = $fluid->table('posts');
62
63
        $posts->column('foo')->integer()->index();
64
65
        $this->assertCount(1, $schema->getTable('posts')->getIndexes());
66
    }
67
68 View Code Duplication
    public function testPrimaryKey()
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...
69
    {
70
        $schema = new Schema();
71
        $fluid = new TdbmFluidSchema($schema);
72
73
        $posts = $fluid->table('posts');
74
75
        $posts->column('id')->integer()->primaryKey('pkname');
76
77
        $this->assertTrue($schema->getTable('posts')->hasPrimaryKey());
78
        $this->assertTrue($schema->getTable('posts')->hasIndex('pkname'));
79
    }
80
}
81