Skip to content

Test Affordances#41

Merged
inxilpro merged 14 commits intomainfrom
testing-affordances
Dec 29, 2023
Merged

Test Affordances#41
inxilpro merged 14 commits intomainfrom
testing-affordances

Conversation

@DanielCoulbourne
Copy link
Copy Markdown
Contributor

@DanielCoulbourne DanielCoulbourne commented Dec 12, 2023

Adds Verbs::commitImmediately()

You can call Verbs::commitImmediately() in your tests to commit on every fire(). This is an ergonomic improvement for tests where calling Verbs::commit() after each event and testing the projections was a pain.

When app()->isRunningUnitTests() is false, calling Verbs::commitImmediately() will throw a RuntimeException. If you really know what you are doing, you can allow commitImmediately outside your tests by setting config('verbs.allow_commit_immediately_outside_tests') to true

Adds $event->verbs_should_commit_immediately

You can set the protected bool $verbs_should_commit_immediately property on any Event. This will cause Verbs to commit immediately when firing this event.

Adds State::factory() method and VerbsStateInitialized event.

This allows you to call:

BankAccountState::factory(
    data: ['balance' => 1337]
    id: $bank_account_id
);

or in the case of a singleton state:

ChurnState::factory(['churn' => 40]);

Calling these methods will fire (and immediately commit) a new VerbsStateInitialized event, which will fire onto the given state, identified by the id argument (if id is null, we assume it is a singleton) and return a copy of that state.

This is primarily designed for booting up states for testing, but it may also be useful in migrating non event-sourced codebases to Verbs, when there is a need to initiate a state for legacy data.

@DanielCoulbourne DanielCoulbourne changed the title WIP - Test Affordances Test Affordances Dec 18, 2023
inxilpro and others added 8 commits December 29, 2023 11:50
Co-Authored-By: Daniel Coulbourne <429010+DanielCoulbourne@users.noreply.github.com>
Co-Authored-By: Daniel Coulbourne <429010+DanielCoulbourne@users.noreply.github.com>
Co-Authored-By: Daniel Coulbourne <429010+DanielCoulbourne@users.noreply.github.com>
Co-Authored-By: Daniel Coulbourne <429010+DanielCoulbourne@users.noreply.github.com>
Co-Authored-By: Daniel Coulbourne <429010+DanielCoulbourne@users.noreply.github.com>
Co-Authored-By: Daniel Coulbourne <429010+DanielCoulbourne@users.noreply.github.com>
@inxilpro inxilpro marked this pull request as ready for review December 29, 2023 17:11
@inxilpro inxilpro merged commit 189f549 into main Dec 29, 2023
@DanielCoulbourne DanielCoulbourne deleted the testing-affordances branch December 29, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants