|
7 | 7 | use DragonCode\LaravelDeployOperations\Constants\Names; |
8 | 8 | use DragonCode\LaravelDeployOperations\Jobs\OperationJob; |
9 | 9 | use Exception; |
| 10 | +use Illuminate\Database\Console\Migrations\RollbackCommand; |
10 | 11 | use Illuminate\Support\Facades\DB; |
11 | 12 | use Illuminate\Support\Facades\Queue; |
12 | 13 | use Illuminate\Support\Str; |
@@ -746,4 +747,47 @@ public function testSync() |
746 | 747 | $this->assertDatabaseOperationHas($this->table, 'foo_bar'); |
747 | 748 | $this->assertDatabaseOperationDoesntLike($this->table, 'every_time'); |
748 | 749 | } |
| 750 | + |
| 751 | + public function testViaMigrationMethod() |
| 752 | + { |
| 753 | + $this->copyViaMigrations(); |
| 754 | + |
| 755 | + $table = 'test'; |
| 756 | + |
| 757 | + $this->artisan(Names::Install)->assertExitCode(0); |
| 758 | + |
| 759 | + $this->assertDatabaseCount($table, 0); |
| 760 | + $this->assertDatabaseCount($this->table, 0); |
| 761 | + $this->assertDatabaseOperationDoesntLike($this->table, 'custom'); |
| 762 | + $this->assertDatabaseOperationDoesntLike($this->table, 'invoke'); |
| 763 | + $this->assertDatabaseOperationDoesntLike($this->table, 'up_down'); |
| 764 | + $this->assertDatabaseOperationDoesntLike($table, 'custom', column: 'value'); |
| 765 | + $this->assertDatabaseOperationDoesntLike($table, 'invoke', column: 'value'); |
| 766 | + $this->assertDatabaseOperationDoesntLike($table, 'up_down', column: 'value'); |
| 767 | + |
| 768 | + $this->loadMigrationsFrom(__DIR__ . '/../fixtures/migrations_with_operations'); |
| 769 | + |
| 770 | + $this->assertDatabaseCount($table, 2); |
| 771 | + $this->assertDatabaseCount($this->table, 2); |
| 772 | + $this->assertDatabaseOperationDoesntLike($this->table, 'custom'); |
| 773 | + $this->assertDatabaseOperationHas($this->table, 'invoke'); |
| 774 | + $this->assertDatabaseOperationHas($this->table, 'up_down'); |
| 775 | + $this->assertDatabaseOperationDoesntLike($table, 'custom', column: 'value'); |
| 776 | + $this->assertDatabaseOperationHas($table, 'invoke', column: 'value'); |
| 777 | + $this->assertDatabaseOperationHas($table, 'up_down', column: 'value'); |
| 778 | + |
| 779 | + $this->artisan(RollbackCommand::class, [ |
| 780 | + '--path' => __DIR__ . '/../fixtures/migrations_with_operations', |
| 781 | + '--realpath' => true, |
| 782 | + ])->assertSuccessful(); |
| 783 | + |
| 784 | + $this->assertDatabaseCount($table, 1); |
| 785 | + $this->assertDatabaseCount($this->table, 0); |
| 786 | + $this->assertDatabaseOperationDoesntLike($this->table, 'custom'); |
| 787 | + $this->assertDatabaseOperationDoesntLike($this->table, 'invoke'); |
| 788 | + $this->assertDatabaseOperationDoesntLike($this->table, 'up_down'); |
| 789 | + $this->assertDatabaseOperationDoesntLike($table, 'custom', column: 'value'); |
| 790 | + $this->assertDatabaseOperationHas($table, 'invoke', column: 'value'); |
| 791 | + $this->assertDatabaseOperationDoesntLike($table, 'up_down', column: 'value'); |
| 792 | + } |
749 | 793 | } |
0 commit comments