-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow StateId attribute to set an alias when using a single state (#102)
* failing test * Fix styling * Update StateAliasTest.php * Get to green! * Fix styling --------- Co-authored-by: jdiddydave <[email protected]> Co-authored-by: Chris Morrell <[email protected]>
- Loading branch information
1 parent
dd1daf5
commit 22e3b09
Showing
3 changed files
with
37 additions
and
2 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,35 @@ | ||
<?php | ||
|
||
use Thunk\Verbs\Attributes\Autodiscovery\AppliesToState; | ||
use Thunk\Verbs\Attributes\Autodiscovery\StateId; | ||
use Thunk\Verbs\Event; | ||
use Thunk\Verbs\Facades\Verbs; | ||
use Thunk\Verbs\State; | ||
|
||
test('stateid attribute allows setting an alias for a state collection with a single state', function () { | ||
$event = StateAliasTestEvent::fire(bar: 1, baz: 2); | ||
|
||
Verbs::commit(); | ||
|
||
$state_collection = $event->states(); | ||
|
||
expect($state_collection->aliasNames())->not->toContain('bar') | ||
->and($state_collection->aliasNames())->not->toContain('baz') | ||
->and($state_collection->aliasNames())->toContain('foo') | ||
->and($state_collection->aliasNames())->toContain('hello'); | ||
}); | ||
|
||
class StateAliasTestState extends State | ||
{ | ||
} | ||
|
||
#[AppliesToState(StateAliasTestState::class, id: 'baz', alias: 'hello')] | ||
class StateAliasTestEvent extends Event | ||
{ | ||
public function __construct( | ||
#[StateId(StateAliasTestState::class, 'foo')] | ||
public int $bar, | ||
public int $baz, | ||
) { | ||
} | ||
} |