-
Notifications
You must be signed in to change notification settings - Fork 38
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 #32 from hirethunk/handle-stateless-events
Better handling of "stateless" events and singleton states
- Loading branch information
Showing
9 changed files
with
118 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Thunk\Verbs\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
class StateIsNotSingletonException extends RuntimeException | ||
{ | ||
public function __construct(string $type) | ||
{ | ||
parent::__construct("Expected '{$type}' to be a singleton, but found multiple states."); | ||
} | ||
} |
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
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,60 @@ | ||
<?php | ||
|
||
use Thunk\Verbs\Event; | ||
use Thunk\Verbs\Facades\Verbs; | ||
|
||
it('can store and replay events that have no state', function () { | ||
|
||
$GLOBALS['stateless_test_log'] = []; | ||
|
||
StatelessEventOne::fire(label: 'First event'); | ||
StatelessEventTwo::fire(label: 'Second event'); | ||
StatelessEventOne::fire(label: 'Third event'); | ||
StatelessEventTwo::fire(label: 'Fourth event'); | ||
|
||
expect($GLOBALS['stateless_test_log'])->toBeEmpty(); | ||
|
||
Verbs::commit(); | ||
|
||
expect($GLOBALS['stateless_test_log'])->toBe([ | ||
'[1] First event', | ||
'[2] Second event', | ||
'[1] Third event', | ||
'[2] Fourth event', | ||
]); | ||
|
||
$GLOBALS['stateless_test_log'] = []; | ||
|
||
Verbs::replay(); | ||
|
||
expect($GLOBALS['stateless_test_log'])->toBe([ | ||
'[1] First event', | ||
'[2] Second event', | ||
'[1] Third event', | ||
'[2] Fourth event', | ||
]); | ||
}); | ||
|
||
class StatelessEventOne extends Event | ||
{ | ||
public function __construct(public string $label) | ||
{ | ||
} | ||
|
||
public function handle() | ||
{ | ||
$GLOBALS['stateless_test_log'][] = "[1] {$this->label}"; | ||
} | ||
} | ||
|
||
class StatelessEventTwo extends Event | ||
{ | ||
public function __construct(public string $label) | ||
{ | ||
} | ||
|
||
public function handle() | ||
{ | ||
$GLOBALS['stateless_test_log'][] = "[2] {$this->label}"; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.