コード例 #1
0
 public function testDropColumnInvalidColumnName()
 {
     $tbl = new Table("test_table", 'MyISAM');
     $tbl->addColumn($this->getMock('Cytracom\\Squasher\\Database\\Column', [], ['string', 'myColumn']));
     $cols = $tbl->getColumns();
     $this->assertEquals(1, count($cols));
     $tbl->dropColumn('bad column name');
     $cols = $tbl->getColumns();
     $this->assertEquals(1, count($cols));
 }
コード例 #2
0
 /**
  * Create the function call based on the column on the line.
  *
  * @param Table $table
  * @param $line
  * @param $matches
  */
 protected function createMigrationFunctionCall(Table $table, $line, $matches)
 {
     $line = str_replace('"', "'", $line);
     $segments = explode("'", $line);
     $matches[0] = preg_replace('/>| |,/', '', $matches[0]);
     switch ($matches[0]) {
         case 'primary':
             $table->setPrimaryKey($segments[1]);
             break;
         case 'unique':
             $table->getColumn($segments[1])->unique = true;
             break;
         case 'renameColumn':
             $table->renameColumn($segments[1], $segments[3]);
             break;
         case 'foreign':
             $table->addRelationship(new Relationship($segments[1], $segments[3], $segments[5]));
             break;
         case 'dropColumn':
         case 'dropIfExists':
             $table->dropColumn($segments[1]);
             break;
         case 'dropForeign':
             $table->dropRelationship($segments[1]);
             break;
         case 'dropSoftDeletes':
             $table->dropColumn('softDeletes');
             break;
         case 'dropTimestamps':
             $table->dropColumn('timestamps');
             break;
         case 'timestamps':
         case 'softDeletes':
         case 'nullableTimestamps':
         case 'rememberToken':
             $segments[1] = $matches[0];
         case 'string':
         case 'integer':
         case 'increments':
         case 'bigIncrements':
         case 'bigInteger':
         case 'smallInteger':
         case 'float':
         case 'double':
         case 'decimal':
         case 'boolean':
         case 'date':
         case 'dateTime':
         case 'datetime':
         case 'time':
         case 'timestamp':
         case 'text':
         case 'binary':
         case 'morphs':
         case 'mediumText':
         case 'longText':
         case 'mediumInteger':
         case 'tinyInteger':
         case 'unsignedBigInteger':
         case 'unsignedInteger':
         case 'enum':
             $table->addColumn($this->createStandardColumn($matches, $segments, $line));
             break;
         case 'index':
         case 'dropUnique':
             echo "ERROR, cannot handle " . $matches[0] . PHP_EOL;
             var_dump($segments);
             break;
         default:
             echo "Unknown table operation: " . $matches[0] . PHP_EOL;
             exit;
     }
     $matches = null;
 }