public function testAddForeignKey() { $adapter = new MysqlAdapter([]); $table = new \Phinx\Db\Table('ntable', [], $adapter); $table->addForeignKey('test', 'testTable', 'testRef'); $fks = $table->getForeignKeys(); $this->assertCount(1, $fks); $this->assertContains('test', $fks[0]->getColumns()); $this->assertContains('testRef', $fks[0]->getReferencedColumns()); $this->assertEquals('testTable', $fks[0]->getReferencedTable()->getName()); }
public function testCreateTableWithForeignKey() { $refTable = new \Phinx\Db\Table('ref_table', array(), $this->adapter); $refTable->addColumn('field1', 'string')->save(); $table = new \Phinx\Db\Table('table', array(), $this->adapter); $table->addColumn('ref_table_id', 'integer'); $table->addForeignKey('ref_table_id', 'ref_table', 'id'); $table->save(); $this->assertTrue($this->adapter->hasTable($table->getName())); $this->assertTrue($this->adapter->hasForeignKey($table->getName(), array('ref_table_id'))); }