public function testActions() { $constraint = new ForeignKey('name', 'column', 'parent_table', 'column', 'CASCADE', 'CASCADE'); $this->assertSame('CASCADE', $constraint->getUpdateRule()); $this->assertSame('CASCADE', $constraint->getDeleteRule()); $constraint = new ForeignKey('name', 'column', 'parent_table', 'column', 'NO ACTION', 'NO ACTION'); $this->assertSame('RESTRICT', $constraint->getUpdateRule()); $this->assertSame('RESTRICT', $constraint->getDeleteRule()); $constraint = new ForeignKey('name', 'column', 'parent_table', 'column', 'SET DEFAULT', 'SET DEFAULT'); $this->assertSame('SET DEFAULT', $constraint->getUpdateRule()); $this->assertSame('SET DEFAULT', $constraint->getDeleteRule()); $constraint = new ForeignKey('name', 'column', 'parent_table', 'column', 'SET NULL', 'SET NULL'); $this->assertSame('SET NULL', $constraint->getUpdateRule()); $this->assertSame('SET NULL', $constraint->getDeleteRule()); }
public final function setForeignKeyObject(ForeignKey $foreign_key) : TableInterface { if ($this->isImmutable()) { throw SchemaException::immutable(static::class); } if ($this->hasForeignKey($foreign_key->getName())) { throw SchemaException::foreignKeyAlreadySet(static::class, $foreign_key->getName()); } $missing = array_diff($foreign_key->getColumns(), array_keys($this->getColumns())); if ($missing !== []) { throw TableException::columnNotSet(static::class, implode(', ', $missing)); } $this->foreign_keys[$foreign_key->getName()] = $foreign_key; if (!$this->hasIndexWithColumns(...$foreign_key->getColumns())) { $this->setIndexObject(new Index($foreign_key->getName(), ...$foreign_key->getColumns())); } return $this; }