@@ -337,6 +337,46 @@ public function testSparseUnique(): void
337
337
$ this ->assertEquals (1 , $ index ['unique ' ]);
338
338
}
339
339
340
+ public function testRenameColumn (): void
341
+ {
342
+ DB ::connection ()->collection ('newcollection ' )->insert (['test ' => 'value ' ]);
343
+ DB ::connection ()->collection ('newcollection ' )->insert (['test ' => 'value 2 ' ]);
344
+ DB ::connection ()->collection ('newcollection ' )->insert (['column ' => 'column value ' ]);
345
+
346
+ $ check = DB ::connection ()->collection ('newcollection ' )->get ();
347
+ $ this ->assertCount (3 , $ check );
348
+
349
+ $ this ->assertArrayHasKey ('test ' , $ check [0 ]);
350
+ $ this ->assertArrayNotHasKey ('newtest ' , $ check [0 ]);
351
+
352
+ $ this ->assertArrayHasKey ('test ' , $ check [1 ]);
353
+ $ this ->assertArrayNotHasKey ('newtest ' , $ check [1 ]);
354
+
355
+ $ this ->assertArrayHasKey ('column ' , $ check [2 ]);
356
+ $ this ->assertArrayNotHasKey ('test ' , $ check [2 ]);
357
+ $ this ->assertArrayNotHasKey ('newtest ' , $ check [2 ]);
358
+
359
+ Schema::collection ('newcollection ' , function (Blueprint $ collection ) {
360
+ $ collection ->renameColumn ('test ' , 'newtest ' );
361
+ });
362
+
363
+ $ check2 = DB ::connection ()->collection ('newcollection ' )->get ();
364
+ $ this ->assertCount (3 , $ check2 );
365
+
366
+ $ this ->assertArrayHasKey ('newtest ' , $ check2 [0 ]);
367
+ $ this ->assertArrayNotHasKey ('test ' , $ check2 [0 ]);
368
+ $ this ->assertSame ($ check [0 ]['test ' ], $ check2 [0 ]['newtest ' ]);
369
+
370
+ $ this ->assertArrayHasKey ('newtest ' , $ check2 [1 ]);
371
+ $ this ->assertArrayNotHasKey ('test ' , $ check2 [1 ]);
372
+ $ this ->assertSame ($ check [1 ]['test ' ], $ check2 [1 ]['newtest ' ]);
373
+
374
+ $ this ->assertArrayHasKey ('column ' , $ check2 [2 ]);
375
+ $ this ->assertArrayNotHasKey ('test ' , $ check2 [2 ]);
376
+ $ this ->assertArrayNotHasKey ('newtest ' , $ check2 [2 ]);
377
+ $ this ->assertSame ($ check [2 ]['column ' ], $ check2 [2 ]['column ' ]);
378
+ }
379
+
340
380
protected function getIndex (string $ collection , string $ name )
341
381
{
342
382
$ collection = DB ::getCollection ($ collection );
0 commit comments