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
|
|
|
$fluid->table('node_entries') |
43
|
|
|
->column('id')->integer()->primaryKey()->autoIncrement() |
44
|
|
|
->column('node_id')->references('nodes')->jsonSerialize()->collection("entries") |
45
|
|
|
->column('entry')->string()->null(); |
46
|
|
|
|
47
|
|
|
$this->assertContains('@JsonCollection(key = "entries")', $schema->getTable('node_entries')->getColumn('node_id')->getComment()); |
48
|
|
|
|
49
|
|
|
$anotherColumn = $fluid->table('nodes')->column('another_column')->integer(); |
50
|
|
|
$this->assertSame($anotherColumn, $anotherColumn->jsonSerialize()->endJsonSerialize()); |
51
|
|
|
$this->assertSame($fluid->table('nodes'), $anotherColumn->jsonSerialize()->then()); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|