Пример #1
0
 public function testRemoveForeignKeyWithoutIndexByRemoveIndex()
 {
     try {
         $this->object->removeIndex('users', 'address', array('foreignKey' => true));
         $this->fail('removeForeignKey does not accept empty string for table ref name!');
     } catch (Phigrate_Exception_Argument $ex) {
         $msg = 'Missing table ref name parameter';
         $this->assertEquals($msg, $ex->getMessage());
     }
     //create it
     $sql = "CREATE TABLE `users` (name varchar(20), address varchar(25), title varchar(20), other tinyint(1)) ENGINE=InnoDB;";
     $this->object->executeDdl($sql);
     $sql = "CREATE TABLE `addresses` (name varchar(25), street varchar(20)) ENGINE=InnoDB;";
     $this->object->executeDdl($sql);
     $this->assertFalse($this->object->isPrimaryKey('addresses', 'name'));
     $this->assertFalse($this->object->hasIndex('addresses', 'name'));
     $this->assertFalse($this->object->hasIndex('users', 'address', array('name' => 'users_ibfk_address')));
     $this->object->addForeignKey('users', 'address', 'addresses', 'name');
     $this->assertTrue($this->object->hasIndex('users', 'address', array('name' => 'users_ibfk_address')));
     $this->assertTrue($this->object->hasIndex('addresses', 'name'));
     $this->object->removeIndex('users', 'address', array('foreignKey' => true, 'tableRef' => 'addresses', 'columnRef' => 'name'));
     $this->assertFalse($this->object->hasIndex('users', 'address', array('name' => 'users_ibfk_address')));
     $this->assertFalse($this->object->hasIndex('addresses', 'name'));
 }