| @@ 307-330 (lines=24) @@ | ||
| 304 | } |
|
| 305 | } |
|
| 306 | ||
| 307 | public function testChangeColumn() |
|
| 308 | { |
|
| 309 | $table = new \Phinx\Db\Table('t', array(), $this->adapter); |
|
| 310 | $table->addColumn('column1', 'string') |
|
| 311 | ->save(); |
|
| 312 | $this->assertTrue($this->adapter->hasColumn('t', 'column1')); |
|
| 313 | $newColumn1 = new \Phinx\Db\Table\Column(); |
|
| 314 | $newColumn1->setType('string'); |
|
| 315 | $table->changeColumn('column1', $newColumn1); |
|
| 316 | $this->assertTrue($this->adapter->hasColumn('t', 'column1')); |
|
| 317 | $newColumn2 = new \Phinx\Db\Table\Column(); |
|
| 318 | $newColumn2->setName('column2') |
|
| 319 | ->setType('string') |
|
| 320 | ->setNull(true); |
|
| 321 | $table->changeColumn('column1', $newColumn2); |
|
| 322 | $this->assertFalse($this->adapter->hasColumn('t', 'column1')); |
|
| 323 | $this->assertTrue($this->adapter->hasColumn('t', 'column2')); |
|
| 324 | $columns = $this->adapter->getColumns('t'); |
|
| 325 | foreach ($columns as $column) { |
|
| 326 | if ($column->getName() == 'column2') { |
|
| 327 | $this->assertTrue($column->isNull()); |
|
| 328 | } |
|
| 329 | } |
|
| 330 | } |
|
| 331 | ||
| 332 | public function testChangeColumnDefaults() |
|
| 333 | { |
|
| @@ 381-404 (lines=24) @@ | ||
| 378 | } |
|
| 379 | } |
|
| 380 | ||
| 381 | public function testChangeColumn() |
|
| 382 | { |
|
| 383 | $table = new \Phinx\Db\Table('t', array(), $this->adapter); |
|
| 384 | $table->addColumn('column1', 'string') |
|
| 385 | ->save(); |
|
| 386 | $this->assertTrue($this->adapter->hasColumn('t', 'column1')); |
|
| 387 | $newColumn1 = new \Phinx\Db\Table\Column(); |
|
| 388 | $newColumn1->setType('string'); |
|
| 389 | $table->changeColumn('column1', $newColumn1); |
|
| 390 | $this->assertTrue($this->adapter->hasColumn('t', 'column1')); |
|
| 391 | $newColumn2 = new \Phinx\Db\Table\Column(); |
|
| 392 | $newColumn2->setName('column2') |
|
| 393 | ->setType('string') |
|
| 394 | ->setNull(true); |
|
| 395 | $table->changeColumn('column1', $newColumn2); |
|
| 396 | $this->assertFalse($this->adapter->hasColumn('t', 'column1')); |
|
| 397 | $this->assertTrue($this->adapter->hasColumn('t', 'column2')); |
|
| 398 | $columns = $this->adapter->getColumns('t'); |
|
| 399 | foreach ($columns as $column) { |
|
| 400 | if ($column->getName() == 'column2') { |
|
| 401 | $this->assertTrue($column->isNull()); |
|
| 402 | } |
|
| 403 | } |
|
| 404 | } |
|
| 405 | ||
| 406 | public function testChangeColumnWithDefault() { |
|
| 407 | $table = new \Phinx\Db\Table('t', array(), $this->adapter); |
|