Пример #1
0
 public function testAddColumnWithColumnObject()
 {
     $adapter = new MysqlAdapter(array());
     $column = new \Phinx\Db\Table\Column();
     $column->setName('email')->setType('integer');
     $table = new \Phinx\Db\Table('ntable', array(), $adapter);
     $table->addColumn($column);
     $columns = $table->getPendingColumns();
     $this->assertEquals('email', $columns[0]->getName());
     $this->assertEquals('integer', $columns[0]->getType());
 }
Пример #2
0
 public function testProxyAdapterCanInvertAddColumn()
 {
     $table = new \Phinx\Db\Table('atable');
     $column = new \Phinx\Db\Table\Column();
     $column->setName('acolumn');
     $this->adapter->addColumn($table, $column);
     $commands = $this->adapter->getInvertedCommands();
     $this->assertEquals('dropColumn', $commands[0]['name']);
     $this->assertEquals('atable', $commands[0]['arguments'][0]);
     $this->assertContains('acolumn', $commands[0]['arguments'][1]);
 }
 public function testChangeColumnWithDropDefault()
 {
     $table = new \Phinx\Db\Table('t', array(), $this->adapter);
     $table->addColumn('column1', 'string', array('default' => 'Test'))->save();
     $columns = $this->adapter->getColumns('t');
     foreach ($columns as $column) {
         if ($column->getName() === 'column1') {
             $this->assertRegExp('/Test/', $column->getDefault());
         }
     }
     $newColumn1 = new \Phinx\Db\Table\Column();
     $newColumn1->setName('column1')->setType('string');
     $table->changeColumn('column1', $newColumn1);
     $columns = $this->adapter->getColumns('t');
     foreach ($columns as $column) {
         if ($column->getName() === 'column1') {
             $this->assertNull($column->getDefault());
         }
     }
 }
Пример #4
0
 public function testChangeColumn()
 {
     $table = new \Phinx\Db\Table('t', array(), $this->adapter);
     $table->addColumn('column1', 'string')->save();
     $this->assertTrue($this->adapter->hasColumn('t', 'column1'));
     $newColumn1 = new \Phinx\Db\Table\Column();
     $newColumn1->setType('string');
     $table->changeColumn('column1', $newColumn1);
     $this->assertTrue($this->adapter->hasColumn('t', 'column1'));
     $newColumn2 = new \Phinx\Db\Table\Column();
     $newColumn2->setName('column2')->setType('string');
     $table->changeColumn('column1', $newColumn2);
     $this->assertFalse($this->adapter->hasColumn('t', 'column1'));
     $this->assertTrue($this->adapter->hasColumn('t', 'column2'));
 }
Пример #5
0
 public function testChangeColumn()
 {
     $table = new \Phinx\Db\Table('t', array(), $this->adapter);
     $table->addColumn('column1', 'string')->save();
     $this->assertTrue($this->adapter->hasColumn('t', 'column1'));
     $newColumn1 = new \Phinx\Db\Table\Column();
     $newColumn1->setType('string');
     $table->changeColumn('column1', $newColumn1);
     $this->assertTrue($this->adapter->hasColumn('t', 'column1'));
     $newColumn2 = new \Phinx\Db\Table\Column();
     $newColumn2->setName('column2')->setType('string')->setNull(true);
     $table->changeColumn('column1', $newColumn2);
     $this->assertFalse($this->adapter->hasColumn('t', 'column1'));
     $this->assertTrue($this->adapter->hasColumn('t', 'column2'));
     $columns = $this->adapter->getColumns('t');
     foreach ($columns as $column) {
         if ($column->getName() == 'column2') {
             $this->assertTrue($column->isNull());
         }
     }
 }