public function testAddIndex() { $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->addColumn('email', 'string')->save(); $this->assertFalse($table->hasIndex('email')); $table->addIndex('email')->save(); $this->assertTrue($table->hasIndex('email')); }
public function testAddIndexWithLimit() { $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->addColumn('email', 'string')->save(); $this->assertFalse($table->hasIndex('email')); $table->addIndex('email', array('limit' => 50))->save(); $this->assertTrue($table->hasIndex('email')); $index_data = $this->adapter->query('SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "phinx_testing" AND TABLE_NAME = "table1" AND INDEX_NAME = "email"')->fetch(\PDO::FETCH_ASSOC); $expected_limit = $index_data['SUB_PART']; $this->assertEquals($expected_limit, 50); }
public function testAddIndexWithIndexObject() { $adapter = new MysqlAdapter(array()); $index = new \Phinx\Db\Table\Index(); $index->setType(\Phinx\Db\Table\Index::INDEX)->setColumns(array('email')); $table = new \Phinx\Db\Table('ntable', array(), $adapter); $table->addIndex($index); $indexes = $table->getIndexes(); $this->assertEquals(\Phinx\Db\Table\Index::INDEX, $indexes[0]->getType()); $this->assertContains('email', $indexes[0]->getColumns()); }
public function testAddIndexWithoutType() { $adapter = new MysqlAdapter([]); $table = new \Phinx\Db\Table('ntable', [], $adapter); $table->addIndex(['email']); $indexes = $table->getIndexes(); $this->assertEquals(\Phinx\Db\Table\Index::INDEX, $indexes[0]->getType()); $this->assertContains('email', $indexes[0]->getColumns()); }