/** * @throws \RuntimeException * @return \DatabaseExporterImporter\Entity\Column[] */ public function getDependentColumns() { if (null === $this->parentColumn->getTable()) { throw new \RuntimeException('The parent column does not contain a parent table.'); } $columns = []; foreach ($this->tables as $table) { foreach ($table->getColumns() as $column) { if (null !== $column->getForeignKey() && $column->getForeignKey()->getColumnName() === $this->parentColumn->getName() && $column->getForeignKey()->getTableName() === $this->parentColumn->getTable()->getName()) { $columns[] = $column; } } } return $columns; }
public function test() { $foreignKey = new ForeignKey(); $foreignKey->setTableName('table1')->setColumnName('column1'); $subject = new Column('name'); $subject->setForeignKey($foreignKey)->setTable(new Table('test_table')); static::assertSame('name', $subject->getName()); static::assertInstanceOf(ForeignKey::class, $subject->getForeignKey()); $subject->removeForeignKey(); static::assertSame(null, $subject->getForeignKey()); static::assertFalse($subject->isAutoIncrement()); $subject->setAutoIncrement(true); static::assertTrue($subject->isAutoIncrement()); static::assertSame('test_table', $subject->getTable()->getName()); }