Completed
Pull Request — master (#16)
by David
13:19
created

TdbmFluidJunctionTableJsonOptionsTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 9
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testJson() 0 34 1
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 TdbmFluidJunctionTableJsonOptionsTest extends TestCase
10
{
11
    public function testJson()
12
    {
13
        $schema = new Schema();
14
        $fluid = new TdbmFluidSchema($schema);
15
16
        $fluid->table('nodes')
17
            ->column('id')->integer()->primaryKey()->autoIncrement()->jsonSerialize()->ignore()
18
            ->column('alias_id')->references('nodes')->null()->jsonSerialize()->recursive()
19
            ->column('parent_id')->references('nodes')->null()->jsonSerialize()->include()
20
            ->column('root_id')->references('nodes')->null()->jsonSerialize()->ignore()
21
            ->column('owner_id')->references('nodes')->null()->jsonSerialize()->formatUsingProperty('name')->include()
22
            ->column('owner_country')->references('nodes')->null()->jsonSerialize()->formatUsingMethod('myMethod')->include()
23
            ->column('name')->string()->jsonSerialize()->key('basename')
24
            ->column('size')->integer()->notNull()->default(0)->jsonSerialize()->numericFormat(null, null, null, ' o')
25
            ->column('weight')->float()->null()->jsonSerialize()->numericFormat(2, ',', '.', 'g')
26
            ->column('created_at')->date()->null()->jsonSerialize()->datetimeFormat("Y-m-d")
27
            ->column('another_parent')->references('nodes')->comment('@JsonCollection("entries") @JsonFormat(property="entry")');
28
29
        $nodesTable = $schema->getTable('nodes');
30
        $this->assertContains("@JsonIgnore", $nodesTable->getColumn('id')->getComment());
31
        $this->assertContains("@JsonRecursive", $nodesTable->getColumn('alias_id')->getComment());
32
        $this->assertContains("@JsonInclude", $nodesTable->getColumn('parent_id')->getComment());
33
        $this->assertContains("@JsonIgnore", $nodesTable->getColumn('root_id')->getComment());
34
        $this->assertContains('@JsonFormat(property = "name")', $nodesTable->getColumn('owner_id')->getComment());
35
        $this->assertContains('@JsonFormat(method = "myMethod")', $nodesTable->getColumn('owner_country')->getComment());
36
        $this->assertContains("@JsonKey(key = \"basename\")", $nodesTable->getColumn('name')->getComment());
37
        $this->assertContains("@JsonFormat(unit = \" o\")", $nodesTable->getColumn('size')->getComment());
38
        $this->assertContains("@JsonFormat(decimals = 2, point = \",\", separator = \".\", unit = \"g\")", $nodesTable->getColumn('weight')->getComment());
39
        $this->assertContains("@JsonFormat(date = \"Y-m-d\")", $nodesTable->getColumn('created_at')->getComment());
40
        $this->assertContains("@JsonCollection(\"entries\")", $nodesTable->getColumn('another_parent')->getComment());
41
42
        $anotherColumn = $fluid->table('nodes')->column('another_column')->integer();
43
        $this->assertSame($anotherColumn, $anotherColumn->jsonSerialize()->endJsonSerialize());
44
    }
45
}
46