-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rappasoft/develop
Develop
- Loading branch information
Showing
10 changed files
with
365 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelPatches\Tests\Commands; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use InvalidArgumentException; | ||
use Rappasoft\LaravelPatches\Tests\TestCase; | ||
|
||
class PatchMakeTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_makes_a_patch_file() | ||
{ | ||
$this->artisan('make:patch', ['name' => 'new_patch'])->run(); | ||
|
||
$this->assertDirectoryExists(database_path('patches')); | ||
$this->assertEquals(1, collect(File::files(database_path('patches')))->count()); | ||
} | ||
|
||
/** @test */ | ||
public function it_prepopulates_the_patch_with_the_stub_file() | ||
{ | ||
$this->artisan('make:patch', ['name' => 'new_patch'])->run(); | ||
|
||
foreach (glob(database_path('patches').'/*') as $file) { | ||
$this->assertTrue(filesize($file) > 0); | ||
} | ||
} | ||
|
||
/** @test */ | ||
public function it_doesnt_make_two_patches_with_the_same_name() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
|
||
$this->artisan('make:patch', ['name' => 'new_patch'])->run(); | ||
$this->artisan('make:patch', ['name' => 'new_patch'])->run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelPatches\Tests\Commands; | ||
|
||
use Rappasoft\LaravelPatches\Tests\TestCase; | ||
|
||
class PatchTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_runs_pending_patches() | ||
{ | ||
file_put_contents( | ||
database_path('patches/2021_01_01_000000_my_first_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php') | ||
); | ||
|
||
$this->assertDatabaseCount('patches', 0); | ||
|
||
$this->artisan('patch')->run(); | ||
|
||
$this->assertDatabaseCount('patches', 1); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
'log' => json_encode(['Hello First!']), | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_increments_the_batch_number_normally() | ||
{ | ||
file_put_contents( | ||
database_path('patches/2021_01_01_000000_my_first_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php') | ||
); | ||
|
||
$this->artisan('patch')->run(); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
]); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_02_000000_my_second_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_02_000000_my_second_patch.php') | ||
); | ||
|
||
$this->artisan('patch')->run(); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'patch' => '2021_01_02_000000_my_second_patch', | ||
'batch' => 2, | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function multiple_patches_have_the_same_batch_if_run_at_the_same_time() | ||
{ | ||
file_put_contents( | ||
database_path('patches/2021_01_01_000000_my_first_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php') | ||
); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_02_000000_my_second_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_02_000000_my_second_patch.php') | ||
); | ||
|
||
$this->artisan('patch')->run(); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'id' => 1, | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
]); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'id' => 2, | ||
'patch' => '2021_01_02_000000_my_second_patch', | ||
'batch' => 1, | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_increments_the_batch_number_by_one_if_step_is_enabled() | ||
{ | ||
file_put_contents( | ||
database_path('patches/2021_01_01_000000_my_first_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php') | ||
); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_02_000000_my_second_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_02_000000_my_second_patch.php') | ||
); | ||
|
||
$this->artisan('patch', ['--step' => true])->run(); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'id' => 1, | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
]); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'id' => 2, | ||
'patch' => '2021_01_02_000000_my_second_patch', | ||
'batch' => 2, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelPatches\Tests\Commands; | ||
|
||
use Illuminate\Support\Facades\Log; | ||
use Rappasoft\LaravelPatches\Tests\TestCase; | ||
|
||
class RollbackTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_rollsback_a_patch() | ||
{ | ||
Log::shouldReceive('info')->with('Goodbye First'); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_01_000000_my_first_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php') | ||
); | ||
|
||
$this->assertDatabaseCount('patches', 0); | ||
|
||
$this->artisan('patch')->run(); | ||
|
||
$this->assertDatabaseCount('patches', 1); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
]); | ||
|
||
$this->artisan('patch:rollback')->run(); | ||
|
||
$this->assertDatabaseCount('patches', 0); | ||
|
||
$this->assertDatabaseMissing('patches', [ | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_rollsback_all_patches_of_the_previous_batch() | ||
{ | ||
Log::shouldReceive('info')->with('Goodbye First'); | ||
Log::shouldReceive('info')->with('Goodbye Second'); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_01_000000_my_first_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php') | ||
); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_02_000000_my_second_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_02_000000_my_second_patch.php') | ||
); | ||
|
||
$this->artisan('patch')->run(); | ||
|
||
$this->assertDatabaseCount('patches', 2); | ||
|
||
$this->artisan('patch:rollback')->run(); | ||
|
||
$this->assertDatabaseCount('patches', 0); | ||
} | ||
|
||
/** @test */ | ||
public function it_rollsback_the_correct_patches_with_step() | ||
{ | ||
Log::shouldReceive('info')->once(); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_01_000000_my_first_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php') | ||
); | ||
|
||
file_put_contents( | ||
database_path('patches/2021_01_02_000000_my_second_patch.php'), | ||
file_get_contents(__DIR__.'/patches/2021_01_02_000000_my_second_patch.php') | ||
); | ||
|
||
$this->artisan('patch')->run(); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
]); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'patch' => '2021_01_02_000000_my_second_patch', | ||
'batch' => 1, | ||
]); | ||
|
||
$this->artisan('patch:rollback', ['--step' => 1])->run(); | ||
|
||
$this->assertDatabaseHas('patches', [ | ||
'patch' => '2021_01_01_000000_my_first_patch', | ||
'batch' => 1, | ||
]); | ||
|
||
$this->assertDatabaseMissing('patches', [ | ||
'patch' => '2021_01_02_000000_my_second_patch', | ||
'batch' => 1, | ||
]); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Commands/patches/2021_01_01_000000_my_first_patch.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use Rappasoft\LaravelPatches\Patch; | ||
|
||
class MyFirstPatch extends Patch | ||
{ | ||
/** | ||
* Run the patch. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
$this->log('Hello First!'); | ||
} | ||
|
||
/** | ||
* Reverse the patch. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
\Log::info('Goodbye First'); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Commands/patches/2021_01_02_000000_my_second_patch.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use Rappasoft\LaravelPatches\Patch; | ||
|
||
class MySecondPatch extends Patch | ||
{ | ||
/** | ||
* Run the patch. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
$this->log('Hello Second!'); | ||
} | ||
|
||
/** | ||
* Reverse the patch. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
\Log::info('Goodbye Second'); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Commands/patches/2021_01_03_000000_my_third_patch.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use Rappasoft\LaravelPatches\Patch; | ||
|
||
class MyThirdPatch extends Patch | ||
{ | ||
/** | ||
* Run the patch. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
$this->log('Hello Third!'); | ||
} | ||
|
||
/** | ||
* Reverse the patch. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
\Log::info('Goodbye Third'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.