generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
166 additions
and
22 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
11 changes: 11 additions & 0 deletions
11
tests/Fixtures/WorkflowDiscovery/Activities/DemoActivityWithInterface.php
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,11 @@ | ||
<?php | ||
|
||
namespace Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Activities; | ||
|
||
class DemoActivityWithInterface implements DemoActivityInterface | ||
{ | ||
public function greet(string $name): string | ||
{ | ||
return sprintf('Hello %s', $name); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
tests/Fixtures/WorkflowDiscovery/Workflows/TesterWorkflow.php
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,58 @@ | ||
<?php | ||
|
||
namespace Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows; | ||
|
||
use Carbon\CarbonInterval; | ||
use Keepsuit\LaravelTemporal\Facade\Temporal; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Activities\DemoActivityInterface; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Activities\DemoActivityWithInterface; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Activities\DemoLocalActivity; | ||
use Temporal\Internal\Workflow\ActivityProxy; | ||
use Temporal\Workflow; | ||
use Temporal\Workflow\WorkflowInterface; | ||
use Temporal\Workflow\WorkflowMethod; | ||
|
||
#[WorkflowInterface] | ||
class TesterWorkflow | ||
{ | ||
/** | ||
* @var ActivityProxy<DemoActivityWithInterface> | ||
*/ | ||
protected ActivityProxy $activity; | ||
|
||
/** | ||
* @var ActivityProxy<DemoLocalActivity> | ||
*/ | ||
protected ActivityProxy $localActivity; | ||
|
||
public function __construct() | ||
{ | ||
$this->activity = Temporal::newActivity() | ||
->withStartToCloseTimeout(CarbonInterval::seconds(1)) | ||
->build(DemoActivityInterface::class); | ||
|
||
$this->localActivity = Temporal::newLocalActivity() | ||
->withStartToCloseTimeout(CarbonInterval::seconds(1)) | ||
->build(DemoLocalActivity::class); | ||
|
||
$this->childWorkflow = Temporal::newChildWorkflow() | ||
->withWorkflowRunTimeout(CarbonInterval::seconds(1)) | ||
->build(DemoWorkflow::class); | ||
} | ||
|
||
#[WorkflowMethod(name: 'tester')] | ||
#[Workflow\ReturnType('array')] | ||
public function tester(string $target): \Generator | ||
{ | ||
return match ($target) { | ||
'activity' => ['activity' => yield $this->activity->greet('John')], | ||
'local_activity' => ['local_activity' => yield $this->localActivity->greet('John')], | ||
'child' => ['child' => sprintf('(child) %s', yield $this->childWorkflow->greet('John'))], | ||
default => [ | ||
'activity' => yield $this->activity->greet('John'), | ||
'local_activity' => yield $this->localActivity->greet('John'), | ||
'child' => sprintf('(child) %s', yield $this->childWorkflow->greet('John')), | ||
] | ||
}; | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
|
||
use Carbon\CarbonInterval; | ||
use Keepsuit\LaravelTemporal\Facade\Temporal; | ||
use Keepsuit\LaravelTemporal\Testing\WithTemporal; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows\TesterWorkflow; | ||
use Temporal\Common\RetryOptions; | ||
|
||
uses(WithTemporal::class); | ||
|
||
beforeEach(function () { | ||
Temporal::fake(); | ||
}); | ||
|
||
it('execute workflow with activity', function () { | ||
$workflow = Temporal::newWorkflow() | ||
->withWorkflowRunTimeout(CarbonInterval::seconds(2)) | ||
->build(TesterWorkflow::class); | ||
|
||
$result = $workflow->tester('activity'); | ||
|
||
expect($result)->toBe(['activity' => 'Hello John']); | ||
}); | ||
|
||
it('execute workflow with local activity', function () { | ||
$workflow = Temporal::newWorkflow() | ||
->withWorkflowRunTimeout(CarbonInterval::seconds(2)) | ||
->build(TesterWorkflow::class); | ||
|
||
$result = $workflow->tester('local_activity'); | ||
|
||
expect($result)->toBe(['local_activity' => '(local) Hello John']); | ||
}); | ||
|
||
it('execute workflow with child', function () { | ||
$workflow = Temporal::newWorkflow() | ||
->withWorkflowRunTimeout(CarbonInterval::seconds(2)) | ||
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(2)) | ||
->build(TesterWorkflow::class); | ||
|
||
$result = $workflow->tester('child'); | ||
|
||
expect($result)->toBe(['child' => '(child) Hello John']); | ||
}); | ||
|
||
it('execute workflow full', function () { | ||
$workflow = Temporal::newWorkflow() | ||
->withWorkflowRunTimeout(CarbonInterval::seconds(2)) | ||
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(2)) | ||
->build(TesterWorkflow::class); | ||
|
||
$result = $workflow->tester('all'); | ||
|
||
expect($result)->toBe([ | ||
'activity' => 'Hello John', | ||
'local_activity' => '(local) Hello John', | ||
'child' => '(child) Hello John', | ||
]); | ||
}); |
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 |
---|---|---|
@@ -1,20 +1,22 @@ | ||
<?php | ||
|
||
use Keepsuit\LaravelTemporal\Support\DiscoverWorkflows; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows\DebugOptionsWorkflow; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows\ActivityOptionsWorkflow; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows\DemoWorkflow; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows\DemoWorkflowInterfaceOnly; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows\DemoWorkflowWithoutInterface; | ||
use Keepsuit\LaravelTemporal\Tests\Fixtures\WorkflowDiscovery\Workflows\TesterWorkflow; | ||
|
||
it('can discovery workflows', function () { | ||
$workflows = DiscoverWorkflows::within( | ||
__DIR__.'/../../Fixtures/WorkflowDiscovery/Workflows', | ||
); | ||
|
||
expect($workflows)->toBe([ | ||
DebugOptionsWorkflow::class, | ||
ActivityOptionsWorkflow::class, | ||
DemoWorkflow::class, | ||
DemoWorkflowInterfaceOnly::class, | ||
DemoWorkflowWithoutInterface::class, | ||
TesterWorkflow::class, | ||
]); | ||
}); |