Esempio n. 1
0
 public function testChangeColumnWithoutAColumnObject()
 {
     // stub adapter
     $adapterStub = $this->getMock('\\Phinx\\Db\\Adapter\\MysqlAdapter', array(), array(array()));
     $adapterStub->expects($this->once())->method('changeColumn');
     $table = new \Phinx\Db\Table('ntable', array(), $adapterStub);
     $table->changeColumn('test1', 'text', array('null' => false));
 }
 /**
  * @depends testCanAddColumnComment
  */
 public function testCanRemoveColumnComment()
 {
     $table = new \Phinx\Db\Table('table1', array(), $this->adapter);
     $table->addColumn('field1', 'string', array('comment' => 'Comments from column "field1"'))->save();
     $table->changeColumn('field1', 'string', array('comment' => 'null'))->save();
     $row = $this->adapter->fetchRow('SELECT
             (select pg_catalog.col_description(oid,cols.ordinal_position::int)
         from pg_catalog.pg_class c
         where c.relname=cols.table_name ) as column_comment
         FROM information_schema.columns cols
         WHERE cols.table_catalog=\'' . TESTS_PHINX_DB_ADAPTER_POSTGRES_DATABASE . '\'
         AND cols.table_name=\'table1\'
         AND cols.column_name = \'field1\'');
     $this->assertEmpty($row['column_comment'], 'Dont remove column comment correctly');
 }
Esempio n. 3
0
 public function testChangeColumnDefaultToNull()
 {
     $table = new \Phinx\Db\Table('t', array(), $this->adapter);
     $table->addColumn('column1', 'string', array('default' => 'test'))->save();
     $newColumn1 = new \Phinx\Db\Table\Column();
     $newColumn1->setDefault(null)->setType('string');
     $table->changeColumn('column1', $newColumn1);
     $rows = $this->adapter->fetchAll('SHOW COLUMNS FROM t');
     $this->assertNull($rows[1]['Default']);
 }
Esempio n. 4
0
 /**
  * @depends testAddColumnComment
  */
 public function testRemoveColumnComment()
 {
     $table = new \Phinx\Db\Table('table1', array(), $this->adapter);
     $table->addColumn('field1', 'string', array('comment' => 'Comments from column "field1"'))->save();
     $table->changeColumn('field1', 'string', array('comment' => 'null'))->save();
     $resultComment = $this->adapter->getColumnComment('table1', 'field1');
     $this->assertEmpty($resultComment, 'Dont remove column comment correctly');
 }
 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());
         }
     }
 }