1616use Cycle \Annotated \Tests \Fixtures \Fixtures16 \Employee ;
1717use Cycle \Annotated \Tests \Fixtures \Fixtures16 \Executive ;
1818use Cycle \Annotated \Tests \Fixtures \Fixtures16 \Person ;
19+ use Cycle \Annotated \Tests \Fixtures \Fixtures16 \Tool ;
1920use Cycle \ORM \SchemaInterface ;
2021use Cycle \Schema \Compiler ;
2122use Cycle \Schema \Generator \GenerateRelations ;
@@ -69,6 +70,9 @@ public function testTableInheritance(ReaderInterface $reader): void
6970 // Ceo - Single table inheritance {value: ceo}
7071 // Beaver - Separate table
7172
73+ // Tool
74+ $ this ->assertArrayHasKey ('tool ' , $ schema );
75+
7276 // Person
7377 $ this ->assertCount (3 , $ schema ['person ' ][SchemaInterface::CHILDREN ]);
7478 $ this ->assertEquals ([
@@ -86,57 +90,72 @@ public function testTableInheritance(ReaderInterface $reader): void
8690 // 'bonus' => 'bonus', // JTI
8791 'preferences ' => 'preferences ' ,
8892 'stocks ' => 'stocks ' ,
93+ 'tool_id ' => 'tool_id ' ,
8994 // 'teethAmount' => 'teeth_amount', // Not child
9095 ], $ schema ['person ' ][SchemaInterface::COLUMNS ]);
9196 $ this ->assertEmpty ($ schema ['person ' ][SchemaInterface::PARENT ] ?? null );
9297 $ this ->assertEmpty ($ schema ['person ' ][SchemaInterface::PARENT_KEY ] ?? null );
9398 $ this ->assertSame ('people ' , $ schema ['person ' ][SchemaInterface::TABLE ]);
99+ $ this ->assertCount (1 , $ schema ['person ' ][SchemaInterface::RELATIONS ]);
94100
95101 // Employee
96102 $ this ->assertArrayHasKey ('employee ' , $ schema );
97103 $ this ->assertCount (1 , $ schema ['employee ' ]);
98104 $ this ->assertSame (Employee::class, $ schema ['employee ' ][SchemaInterface::ENTITY ]);
99105 $ this ->assertNull ($ schema ['employee ' ][SchemaInterface::TABLE ] ?? null );
106+ $ this ->assertCount (0 , $ schema ['employee ' ][SchemaInterface::RELATIONS ] ?? []);
100107
101108 // Customer
102109 $ this ->assertArrayHasKey ('customer ' , $ schema );
103110 $ this ->assertCount (1 , $ schema ['customer ' ]);
104111 $ this ->assertSame (Customer::class, $ schema ['customer ' ][SchemaInterface::ENTITY ]);
105112 $ this ->assertNull ($ schema ['customer ' ][SchemaInterface::TABLE ] ?? null );
113+ $ this ->assertCount (0 , $ schema ['customer ' ][SchemaInterface::RELATIONS ] ?? []);
106114
107115 // Executive
108116 $ this ->assertSame ('employee ' , $ schema ['executive ' ][SchemaInterface::PARENT ]);
109117 $ this ->assertSame ('foo_id ' , $ schema ['executive ' ][SchemaInterface::PARENT_KEY ]);
110118 $ this ->assertSame ('executives ' , $ schema ['executive ' ][SchemaInterface::TABLE ]);
111- $ this ->assertSame (
119+ $ this ->assertEquals (
112120 [
113121 'bonus ' => 'bonus ' ,
114122 'proxyFieldWithAnnotation ' => 'proxy ' ,
115123 'foo_id ' => 'id ' ,
116124 'hidden ' => 'hidden ' ,
125+ 'added_tool_id ' => 'added_tool_id ' ,
117126 ],
118- $ schema ['executive ' ][SchemaInterface::COLUMNS ]
127+ $ schema ['executive ' ][SchemaInterface::COLUMNS ],
119128 );
129+ $ this ->assertCount (1 , $ schema ['executive ' ][SchemaInterface::RELATIONS ]);
130+
131+ // Executive2
132+ $ this ->assertSame ('executive ' , $ schema ['executive2 ' ][SchemaInterface::PARENT ]);
133+ $ this ->assertSame ('foo_id ' , $ schema ['executive2 ' ][SchemaInterface::PARENT_KEY ]);
134+ $ this ->assertEquals (['foo_id ' => 'id ' ], $ schema ['executive2 ' ][SchemaInterface::COLUMNS ]);
135+ $ this ->assertCount (0 , $ schema ['executive2 ' ][SchemaInterface::RELATIONS ]);
120136
121137 // Ceo
122138 $ this ->assertArrayHasKey ('ceo ' , $ schema );
123139 $ this ->assertCount (1 , $ schema ['ceo ' ]);
124140 $ this ->assertSame (Ceo::class, $ schema ['ceo ' ][SchemaInterface::ENTITY ]);
125141 $ this ->assertNull ($ schema ['ceo ' ][SchemaInterface::TABLE ] ?? null );
142+ $ this ->assertCount (0 , $ schema ['ceo ' ][SchemaInterface::RELATIONS ] ?? []);
126143
127144 // Beaver
128145 $ this ->assertEmpty ($ schema ['beaver ' ][SchemaInterface::DISCRIMINATOR ] ?? null );
129146 $ this ->assertEmpty ($ schema ['beaver ' ][SchemaInterface::PARENT ] ?? null );
130147 $ this ->assertEmpty ($ schema ['beaver ' ][SchemaInterface::PARENT_KEY ] ?? null );
131148 $ this ->assertEmpty ($ schema ['beaver ' ][SchemaInterface::CHILDREN ] ?? null );
132149 $ this ->assertSame ('beavers ' , $ schema ['beaver ' ][SchemaInterface::TABLE ]);
133- $ this ->assertSame ([
150+ $ this ->assertEquals ([
134151 'teethAmount ' => 'teeth_amount ' ,
135152 'foo_id ' => 'id ' ,
136153 'name ' => 'name ' ,
137154 'type ' => 'type ' ,
138155 'hidden ' => 'hidden ' ,
156+ 'tool_id ' => 'tool_id ' ,
139157 ], $ schema ['beaver ' ][SchemaInterface::COLUMNS ]);
158+ $ this ->assertCount (1 , $ schema ['beaver ' ][SchemaInterface::RELATIONS ] ?? []);
140159 }
141160
142161 public function testTableInheritanceWithIncorrectClassesOrder (): void
@@ -150,6 +169,7 @@ public function testTableInheritanceWithIncorrectClassesOrder(): void
150169 new \ReflectionClass (Employee::class),
151170 new \ReflectionClass (Executive::class),
152171 new \ReflectionClass (Person::class),
172+ new \ReflectionClass (Tool::class),
153173 ]);
154174
155175 $ schema = (new Compiler ())->compile ($ r , [
0 commit comments