Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions tests/Feature/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ public function testCompletedDelay(): void

$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('workflow_activity_other', $workflow->output());
$this->assertSame([TestActivity::class, TestOtherActivity::class, Signal::class], $workflow->logs()
->pluck('class')
->sort()
->values()
->toArray());
$this->assertSame(
[TestActivity::class, TestOtherActivity::class, TestWorkflow::class, Signal::class],
$workflow->logs()
->pluck('class')
->sort()
->values()
->toArray()
);
}

public function testTestSignalExceptionWorkflowEarly(): void
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/TestActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Tests\Fixtures;

use AssertionError;
use Illuminate\Contracts\Foundation\Application;
use Workflow\Activity;

class TestActivity extends Activity
{
public function execute(Application $app)
{
assert($app->runningInConsole());
if (! $app->runningInConsole()) {
throw new AssertionError('Test activities must run in console.');
}

return 'activity';
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/TestAsyncWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Fixtures;

use AssertionError;
use Illuminate\Contracts\Foundation\Application;
use Workflow\Workflow;
use function Workflow\{activity, async};
Expand All @@ -13,7 +14,9 @@ final class TestAsyncWorkflow extends Workflow
public function execute()
{
$results = yield async(static function (Application $app) {
assert($app->runningInConsole());
if (! $app->runningInConsole()) {
throw new AssertionError('Test workflows must run in console.');
}

$otherResult = yield activity(TestOtherActivity::class, 'other');

Expand Down
13 changes: 10 additions & 3 deletions tests/Fixtures/TestBadConnectionWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Fixtures;

use AssertionError;
use Illuminate\Contracts\Foundation\Application;
use Workflow\QueryMethod;
use Workflow\SignalMethod;
Expand Down Expand Up @@ -32,16 +33,22 @@ public function isCanceled(): bool

public function execute(Application $app, $shouldAssert = false)
{
assert($app->runningInConsole());
if (! $app->runningInConsole()) {
throw new AssertionError('Test workflows must run in console.');
}

if ($shouldAssert) {
assert(yield sideEffect(fn (): bool => ! $this->canceled));
if (! (yield sideEffect(fn (): bool => ! $this->canceled))) {
throw new AssertionError('Workflow should not be canceled before the first activity.');
}
}

$otherResult = yield activity(TestOtherActivity::class, 'other');

if ($shouldAssert) {
assert(yield sideEffect(fn (): bool => ! $this->canceled));
if (! (yield sideEffect(fn (): bool => ! $this->canceled))) {
throw new AssertionError('Workflow should not be canceled before awaiting the signal.');
}
}

yield await(fn (): bool => $this->canceled);
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/TestOtherActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Tests\Fixtures;

use AssertionError;
use Illuminate\Contracts\Foundation\Application;
use Workflow\Activity;

final class TestOtherActivity extends Activity
{
public function execute(Application $app, $string)
{
assert($app->runningInConsole());
if (! $app->runningInConsole()) {
throw new AssertionError('Test activities must run in console.');
}

return $string;
}
Expand Down
13 changes: 10 additions & 3 deletions tests/Fixtures/TestWebhookWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Fixtures;

use AssertionError;
use Illuminate\Contracts\Foundation\Application;
use Workflow\QueryMethod;
use Workflow\SignalMethod;
Expand Down Expand Up @@ -35,16 +36,22 @@ public function isCanceled(): bool

public function execute(Application $app, $shouldAssert = false)
{
assert($app->runningInConsole());
if (! $app->runningInConsole()) {
throw new AssertionError('Test workflows must run in console.');
}

if ($shouldAssert) {
assert(yield sideEffect(fn (): bool => ! $this->canceled));
if (! (yield sideEffect(fn (): bool => ! $this->canceled))) {
throw new AssertionError('Workflow should not be canceled before the first activity.');
}
}

$otherResult = yield activity(TestOtherActivity::class, 'other');

if ($shouldAssert) {
assert(yield sideEffect(fn (): bool => ! $this->canceled));
if (! (yield sideEffect(fn (): bool => ! $this->canceled))) {
throw new AssertionError('Workflow should not be canceled before awaiting the signal.');
}
}

yield await(fn (): bool => $this->canceled);
Expand Down
9 changes: 7 additions & 2 deletions tests/Fixtures/TestWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Fixtures;

use AssertionError;
use Illuminate\Contracts\Foundation\Application;
use Workflow\QueryMethod;
use Workflow\SignalMethod;
Expand Down Expand Up @@ -35,10 +36,14 @@ public function isCanceled(): bool

public function execute(Application $app, $shouldAssert = false)
{
assert($app->runningInConsole());
if (! $app->runningInConsole()) {
throw new AssertionError('Test workflows must run in console.');
}

if ($shouldAssert) {
assert(yield sideEffect(fn (): bool => ! $this->canceled));
if (! (yield sideEffect(fn (): bool => ! $this->canceled))) {
throw new AssertionError('Workflow should not be canceled before the first activity.');
}
}

$otherResult = yield activity(TestOtherActivity::class, 'other');
Expand Down
Loading