-
-
Notifications
You must be signed in to change notification settings - Fork 98
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 #270 from zayedadel/feature-ignore-same-state
Added test to ensure same-state transition fails when not allowed
- Loading branch information
Showing
13 changed files
with
192 additions
and
5 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,8 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Attributes; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
class IgnoreSameState {} |
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
17 changes: 17 additions & 0 deletions
17
tests/Dummy/IgnoreSameStateModelState/IgnoreSameStateModelAttributeState.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,17 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState; | ||
|
||
use Spatie\ModelStates\Attributes\AllowTransition; | ||
use Spatie\ModelStates\Attributes\DefaultState; | ||
use Spatie\ModelStates\Attributes\IgnoreSameState; | ||
use Spatie\ModelStates\State; | ||
|
||
#[ | ||
DefaultState(IgnoreSameStateModelAttributeStateA::class), | ||
AllowTransition(IgnoreSameStateModelAttributeStateA::class, IgnoreSameStateModelAttributeStateB::class), | ||
IgnoreSameState | ||
] | ||
abstract class IgnoreSameStateModelAttributeState extends State | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/Dummy/IgnoreSameStateModelState/IgnoreSameStateModelAttributeStateA.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,8 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState; | ||
|
||
|
||
class IgnoreSameStateModelAttributeStateA extends IgnoreSameStateModelAttributeState | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/Dummy/IgnoreSameStateModelState/IgnoreSameStateModelAttributeStateB.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,7 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState; | ||
|
||
class IgnoreSameStateModelAttributeStateB extends IgnoreSameStateModelAttributeState | ||
{ | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/Dummy/IgnoreSameStateModelState/IgnoreSameStateModelState.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,17 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState; | ||
|
||
use Spatie\ModelStates\State; | ||
use Spatie\ModelStates\StateConfig; | ||
|
||
abstract class IgnoreSameStateModelState extends State | ||
{ | ||
public static function config(): StateConfig | ||
{ | ||
return parent::config() | ||
->ignoreSameState() | ||
->allowTransition(IgnoreSameStateModelStateA::class, IgnoreSameStateModelStateB::class) | ||
->default(IgnoreSameStateModelStateA::class); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/Dummy/IgnoreSameStateModelState/IgnoreSameStateModelStateA.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,7 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState; | ||
|
||
class IgnoreSameStateModelStateA extends IgnoreSameStateModelState | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/Dummy/IgnoreSameStateModelState/IgnoreSameStateModelStateB.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,7 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState; | ||
|
||
class IgnoreSameStateModelStateB extends IgnoreSameStateModelState | ||
{ | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy; | ||
|
||
use Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState\IgnoreSameStateModelState; | ||
|
||
class TestModelIgnoresSameState extends TestModel | ||
{ | ||
protected $casts = [ | ||
'state' => IgnoreSameStateModelState::class, | ||
]; | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace Spatie\ModelStates\Tests\Dummy; | ||
|
||
use Spatie\ModelStates\Tests\Dummy\IgnoreSameStateModelState\IgnoreSameStateModelAttributeState; | ||
|
||
class TestModelIgnoresSameStateByAttribute extends TestModel | ||
{ | ||
protected $casts = [ | ||
'state' => IgnoreSameStateModelAttributeState::class, | ||
]; | ||
} |
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