-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ensure the strategy can be set to always * test: ensure the strategy can be set to always * feat: ensure the strategy can be set to on create * test: ensure the strategy can be set to on create * feat: ensure the strategy can be set to on update * test: ensure the strategy can be set to on update * feat: ensure the strategy can be set to never * test: ensure the strategy can be set to never * refactor: move commands tests to a different folder * refactor: set last value equal to the max value in the sequence * refactor: group withoutSequencing tests * refactor: rename tests * refactor: rename test classes * feat: add strategy config variable * test: ensure strategy set to always works on create * test: ensure strategy set to always works on delete * test: ensure strategy set to always works on update * feat: do nothing if strategy is set to never * test: ensure strategy set to never works on create * feat: ensure it does update the sequence on delete if strategy is set to never * test: ensure strategy set to never works on delete * feat: ensure strategy set to never works on update * test: ensure strategy set to never works on update * refactor: move strategy check to another method * feat: ensure strategy set on_create and on_update work * test: ensure strategy set on_create and on_update work * feat: ensure on_create and on_update disable sequencing for delete operations * test: ensure on_create and on_update disable sequencing for delete operations * refactor: accept array of strategies as param * docs: add docblock * fix: rename test class * refactor: rename test method * refactor: remove comparison negation * test: change null assertion to equal * feat: ensure the next value is greater than the max * refactor: rename method * docs: add comments to config file * docs: update README * docs: update README * fix: group class name uppercase
- Loading branch information
Showing
16 changed files
with
384 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
* The name of the table column that determines the sequence value. | ||
*/ | ||
'column_name' => 'position', | ||
|
||
/* | ||
* The value sequences should start at. | ||
*/ | ||
'initial_value' => 1, | ||
|
||
/* | ||
* Determines when models should be sequenced. | ||
* Possible values: always|never|on_create|on_update | ||
*/ | ||
'strategy' => 'always', | ||
]; |
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,11 @@ | ||
<?php | ||
|
||
namespace Gurgentil\LaravelEloquentSequencer; | ||
|
||
class SequencingStrategy | ||
{ | ||
const ALWAYS = 'always'; | ||
const ON_CREATE = 'on_create'; | ||
const ON_UPDATE = 'on_update'; | ||
const NEVER = 'never'; | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
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,33 @@ | ||
<?php | ||
|
||
namespace Gurgentil\LaravelEloquentSequencer\Tests\Unit; | ||
|
||
use Gurgentil\LaravelEloquentSequencer\SequencingStrategy; | ||
use Gurgentil\LaravelEloquentSequencer\Tests\TestCase; | ||
|
||
class SequencingStrategyTest extends TestCase | ||
{ | ||
/** @test **/ | ||
public function it_can_be_set_to_always() | ||
{ | ||
$this->assertEquals('always', SequencingStrategy::ALWAYS); | ||
} | ||
|
||
/** @test **/ | ||
public function it_can_be_set_to_on_create() | ||
{ | ||
$this->assertEquals('on_create', SequencingStrategy::ON_CREATE); | ||
} | ||
|
||
/** @test **/ | ||
public function it_can_be_set_to_on_update() | ||
{ | ||
$this->assertEquals('on_update', SequencingStrategy::ON_UPDATE); | ||
} | ||
|
||
/** @test **/ | ||
public function it_can_be_set_to_never() | ||
{ | ||
$this->assertEquals('never', SequencingStrategy::NEVER); | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
namespace Gurgentil\LaravelEloquentSequencer\Tests\Unit; | ||
|
||
use Facades\Gurgentil\LaravelEloquentSequencer\Tests\Factories\Factory; | ||
use Gurgentil\LaravelEloquentSequencer\SequencingStrategy; | ||
use Gurgentil\LaravelEloquentSequencer\Tests\TestCase; | ||
|
||
class StrategyAlwaysTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @group Strategy | ||
*/ | ||
public function strategy_set_to_always_works_on_create() | ||
{ | ||
config(['eloquentsequencer.strategy' => SequencingStrategy::ALWAYS]); | ||
|
||
$group = Factory::of('Group')->create(); | ||
|
||
$firstItem = Factory::of('Item')->create(['group_id' => $group->id]); | ||
|
||
$this->assertEquals(1, $firstItem->refresh()->position); | ||
} | ||
|
||
/** | ||
* @test | ||
* @group Strategy | ||
*/ | ||
public function strategy_set_to_always_works_on_update() | ||
{ | ||
$group = Factory::of('group')->create(); | ||
|
||
$firstItem = Factory::of('item')->create(['group_id' => $group->id]); | ||
$secondItem = Factory::of('item')->create(['group_id' => $group->id]); | ||
|
||
config(['eloquentsequencer.strategy' => SequencingStrategy::ALWAYS]); | ||
|
||
$secondItem->update(['position' => 1]); | ||
|
||
$this->assertEquals(2, $firstItem->refresh()->position); | ||
$this->assertEquals(1, $secondItem->refresh()->position); | ||
} | ||
|
||
/** | ||
* @test | ||
* @group Strategy | ||
*/ | ||
public function strategy_set_to_always_works_on_delete() | ||
{ | ||
$group = Factory::of('Group')->create(); | ||
|
||
$firstItem = Factory::of('Item')->create(['group_id' => $group->id]); | ||
$secondItem = Factory::of('Item')->create(['group_id' => $group->id]); | ||
|
||
config(['eloquentsequencer.strategy' => SequencingStrategy::ALWAYS]); | ||
|
||
$firstItem->delete(); | ||
|
||
$this->assertEquals(1, $secondItem->refresh()->position); | ||
} | ||
} |
Oops, something went wrong.