Skip to content

Commit

Permalink
Merge pull request #5 from rappasoft/develop
Browse files Browse the repository at this point in the history
v2.0.1
  • Loading branch information
rappasoft authored Feb 26, 2022
2 parents e396329 + 96398f4 commit bf9b14f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `laravel-patches` will be documented in this file.

## 2.0.1 - 2022-02-26

### Changed

- Fix table name in model - https://github.com/rappasoft/laravel-patches/pull/4

## 2.0.0 - 2022-02-21

### Added
Expand Down
10 changes: 10 additions & 0 deletions src/Models/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ class Patch extends Model
protected $casts = [
'log' => 'array',
];

/**
* Get the table associated with the model.
*
* @return string
*/
public function getTable()
{
return config('laravel-patches.table_name');
}
}
18 changes: 9 additions & 9 deletions tests/Commands/PatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public function it_runs_pending_patches()
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php')
);

$this->assertDatabaseCount('patches', 0);
$this->assertDatabaseCount(config('laravel-patches.table_name'), 0);

$this->artisan('patch')->run();

$this->assertDatabaseCount('patches', 1);
$this->assertDatabaseCount(config('laravel-patches.table_name'), 1);

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
'log' => json_encode(['Hello First!']),
Expand All @@ -37,7 +37,7 @@ public function it_increments_the_batch_number_normally()

$this->artisan('patch')->run();

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
]);
Expand All @@ -49,7 +49,7 @@ public function it_increments_the_batch_number_normally()

$this->artisan('patch')->run();

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'patch' => '2021_01_02_000000_my_second_patch',
'batch' => 2,
]);
Expand All @@ -70,13 +70,13 @@ public function multiple_patches_have_the_same_batch_if_run_at_the_same_time()

$this->artisan('patch')->run();

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'id' => 1,
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
]);

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'id' => 2,
'patch' => '2021_01_02_000000_my_second_patch',
'batch' => 1,
Expand All @@ -98,13 +98,13 @@ public function it_increments_the_batch_number_by_one_if_step_is_enabled()

$this->artisan('patch', ['--step' => true])->run();

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'id' => 1,
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
]);

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'id' => 2,
'patch' => '2021_01_02_000000_my_second_patch',
'batch' => 2,
Expand Down
22 changes: 11 additions & 11 deletions tests/Commands/RollbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ public function it_rollsback_a_patch()
file_get_contents(__DIR__.'/patches/2021_01_01_000000_my_first_patch.php')
);

$this->assertDatabaseCount('patches', 0);
$this->assertDatabaseCount(config('laravel-patches.table_name'), 0);

$this->artisan('patch')->run();

$this->assertDatabaseCount('patches', 1);
$this->assertDatabaseCount(config('laravel-patches.table_name'), 1);

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
]);

$this->artisan('patch:rollback')->run();

$this->assertDatabaseCount('patches', 0);
$this->assertDatabaseCount(config('laravel-patches.table_name'), 0);

$this->assertDatabaseMissing('patches', [
$this->assertDatabaseMissing(config('laravel-patches.table_name'), [
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
]);
Expand All @@ -56,11 +56,11 @@ public function it_rollsback_all_patches_of_the_previous_batch()

$this->artisan('patch')->run();

$this->assertDatabaseCount('patches', 2);
$this->assertDatabaseCount(config('laravel-patches.table_name'), 2);

$this->artisan('patch:rollback')->run();

$this->assertDatabaseCount('patches', 0);
$this->assertDatabaseCount(config('laravel-patches.table_name'), 0);
}

/** @test */
Expand All @@ -80,24 +80,24 @@ public function it_rollsback_the_correct_patches_with_step()

$this->artisan('patch')->run();

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
]);

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'patch' => '2021_01_02_000000_my_second_patch',
'batch' => 1,
]);

$this->artisan('patch:rollback', ['--step' => 1])->run();

$this->assertDatabaseHas('patches', [
$this->assertDatabaseHas(config('laravel-patches.table_name'), [
'patch' => '2021_01_01_000000_my_first_patch',
'batch' => 1,
]);

$this->assertDatabaseMissing('patches', [
$this->assertDatabaseMissing(config('laravel-patches.table_name'), [
'patch' => '2021_01_02_000000_my_second_patch',
'batch' => 1,
]);
Expand Down

0 comments on commit bf9b14f

Please sign in to comment.