-
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.
Merge branch 'main' into hook-class-hierarchy
- Loading branch information
Showing
10 changed files
with
203 additions
and
9 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
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,32 @@ | ||
<?php | ||
|
||
use Thunk\Verbs\Attributes\Hooks\On; | ||
use Thunk\Verbs\Event; | ||
use Thunk\Verbs\Lifecycle\Dispatcher; | ||
use Thunk\Verbs\Lifecycle\Phase; | ||
|
||
it('can modify props on events in the Boot phase', function () { | ||
app(Dispatcher::class)->register(new BootHookTestListener); | ||
|
||
$e = BootHookTestEvent::fire( | ||
album: 'Tha Carter 2' | ||
); | ||
|
||
expect($e)->name->toBe('Lil Wayne'); | ||
}); | ||
|
||
class BootHookTestEvent extends Event | ||
{ | ||
public string $name; | ||
|
||
public string $album; | ||
} | ||
|
||
class BootHookTestListener | ||
{ | ||
#[On(Phase::Boot)] | ||
public function setNameToLilWayne(BootHookTestEvent $event) | ||
{ | ||
$event->name = 'Lil Wayne'; | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
use Illuminate\Support\Str; | ||
use Thunk\Verbs\Event; | ||
use Thunk\Verbs\Lifecycle\StateManager; | ||
use Thunk\Verbs\State; | ||
use Thunk\Verbs\Support\IdManager; | ||
|
||
use function Pest\Laravel\artisan; | ||
|
||
beforeEach(function () { | ||
// This is necessary because our Orchestra setup migrates the database | ||
// before our tests run, so we need to re-run our migrations | ||
config()->set('verbs.id_type', 'uuid'); | ||
app()->instance(IdManager::class, new IdManager('uuid')); | ||
Facade::clearResolvedInstance(IdManager::class); | ||
artisan('migrate:fresh'); | ||
}); | ||
|
||
afterAll(function () { | ||
// This just resets the migrations back to how the were before this test suite | ||
config()->set('verbs.id_type', 'snowflake'); | ||
app()->instance(IdManager::class, new IdManager('snowflake')); | ||
Facade::clearResolvedInstance(IdManager::class); | ||
artisan('migrate:fresh'); | ||
}); | ||
|
||
it('supports using uuids as state ids', function () { | ||
$uuid = (string) Str::orderedUuid(); | ||
|
||
$state = UuidState::load($uuid); | ||
|
||
UuidEvent::commit( | ||
state: $state, | ||
); | ||
|
||
expect($state) | ||
->id->toBe($uuid) | ||
->event_was_applied->toBeTrue(); | ||
}); | ||
|
||
it('loads states correctly using uuids when the snapshots table has been removed', function () { | ||
$uuid = (string) Str::orderedUuid(); | ||
|
||
$state = UuidState::load($uuid); | ||
|
||
UuidEvent::commit( | ||
state: $state, | ||
); | ||
|
||
app(StateManager::class)->reset(include_storage: true); | ||
|
||
$state = UuidState::load($uuid); | ||
|
||
expect($state) | ||
->id->toBe($uuid) | ||
->event_was_applied->toBeTrue(); | ||
}); | ||
|
||
class UuidState extends State | ||
{ | ||
public bool $event_was_applied = false; | ||
} | ||
|
||
class UuidEvent extends Event | ||
{ | ||
public UuidState $state; | ||
|
||
public function apply() | ||
{ | ||
$this->state->event_was_applied = true; | ||
} | ||
} |
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