-
Notifications
You must be signed in to change notification settings - Fork 53
fix: throw correct exception from Activity and Workflow contexts #687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xepozz
wants to merge
7
commits into
master
Choose a base branch
from
contextless-error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e25711f
fix: throw correct exception from Activity and Workflow contexts
xepozz 550d089
fix: psalm
xepozz 7cd347f
Merge branch 'master' into contextless-error
xepozz d3afb8e
Merge branch 'master' into contextless-error
xepozz eece355
Merge branch 'master' into contextless-error
xepozz 538b6d1
Merge branch 'master' into contextless-error
xepozz c83f554
Merge branch 'master' into contextless-error
xepozz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,66 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Temporal\Tests\Unit\Internal\Support; | ||
|
|
||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
| use PHPUnit\Framework\Attributes\Test; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Temporal\Activity; | ||
| use Temporal\Exception\OutOfContextException; | ||
|
|
||
| class ActivityFacadeTest extends TestCase | ||
| { | ||
| /** | ||
| * @return iterable<string, array{callable}> | ||
| */ | ||
| public static function outOfContextMethods(): iterable | ||
| { | ||
| yield 'getCurrentContext' => [ | ||
| static fn() => Activity::getCurrentContext(), | ||
| ]; | ||
|
|
||
| yield 'getInfo' => [ | ||
| static fn() => Activity::getInfo(), | ||
| ]; | ||
|
|
||
| yield 'getInput' => [ | ||
| static fn() => Activity::getInput(), | ||
| ]; | ||
|
|
||
| yield 'hasHeartbeatDetails' => [ | ||
| static fn() => Activity::hasHeartbeatDetails(), | ||
| ]; | ||
|
|
||
| yield 'getHeartbeatDetails' => [ | ||
| static fn() => Activity::getHeartbeatDetails(), | ||
| ]; | ||
|
|
||
| yield 'getCancellationDetails' => [ | ||
| static fn() => Activity::getCancellationDetails(), | ||
| ]; | ||
|
|
||
| yield 'doNotCompleteOnReturn' => [ | ||
| static fn() => Activity::doNotCompleteOnReturn(), | ||
| ]; | ||
|
|
||
| yield 'heartbeat' => [ | ||
| static fn() => Activity::heartbeat('test'), | ||
| ]; | ||
|
|
||
| yield 'getInstance' => [ | ||
| static fn() => Activity::getInstance(), | ||
| ]; | ||
| } | ||
|
|
||
| #[Test] | ||
| #[DataProvider('outOfContextMethods')] | ||
| public function throwsOutOfContextException(callable $method): void | ||
| { | ||
| $this->expectException(OutOfContextException::class); | ||
| $this->expectExceptionMessage('The Activity facade can only be used in the context of an activity execution.'); | ||
|
|
||
| $method(); | ||
| } | ||
| } |
This file contains hidden or 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,193 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Temporal\Tests\Unit\Internal\Support; | ||
|
|
||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
| use PHPUnit\Framework\Attributes\Test; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Temporal\Exception\OutOfContextException; | ||
| use Temporal\Workflow; | ||
|
|
||
| class WorkflowFacadeTest extends TestCase | ||
| { | ||
| /** | ||
| * @return iterable<string, array{callable, string}> | ||
| */ | ||
| public static function outOfContextMethods(): iterable | ||
| { | ||
| yield 'getCurrentContext' => [ | ||
| static fn() => Workflow::getCurrentContext(), | ||
| ]; | ||
|
|
||
| yield 'now' => [ | ||
| static fn() => Workflow::now(), | ||
| ]; | ||
|
|
||
| yield 'getInfo' => [ | ||
| static fn() => Workflow::getInfo(), | ||
| ]; | ||
|
|
||
| yield 'getInput' => [ | ||
| static fn() => Workflow::getInput(), | ||
| ]; | ||
|
|
||
| yield 'await' => [ | ||
| static fn() => Workflow::await(static fn() => true), | ||
| ]; | ||
|
|
||
| yield 'awaitWithTimeout' => [ | ||
| static fn() => Workflow::awaitWithTimeout(1, static fn() => true), | ||
| ]; | ||
|
|
||
| yield 'isReplaying' => [ | ||
| static fn() => Workflow::isReplaying(), | ||
| ]; | ||
|
|
||
| yield 'getVersion' => [ | ||
| static fn() => Workflow::getVersion('test', Workflow::DEFAULT_VERSION, 1), | ||
| ]; | ||
|
|
||
| yield 'timer' => [ | ||
| static fn() => Workflow::timer(1), | ||
| ]; | ||
|
|
||
| yield 'executeChildWorkflow' => [ | ||
| static fn() => Workflow::executeChildWorkflow('Test'), | ||
| ]; | ||
|
|
||
| yield 'newChildWorkflowStub' => [ | ||
| static fn() => Workflow::newChildWorkflowStub(\stdClass::class), | ||
| ]; | ||
|
|
||
| yield 'newExternalWorkflowStub' => [ | ||
| static fn() => Workflow::newExternalWorkflowStub('test', new Workflow\WorkflowExecution()), | ||
| ]; | ||
|
|
||
| yield 'continueAsNew' => [ | ||
| static fn() => Workflow::continueAsNew(''), | ||
| ]; | ||
|
|
||
| yield 'async' => [ | ||
| static fn() => Workflow::async(static fn() => yield), | ||
| ]; | ||
|
|
||
| yield 'asyncDetached' => [ | ||
| static fn() => Workflow::asyncDetached(static fn() => yield), | ||
| ]; | ||
|
|
||
| yield 'newActivityStub' => [ | ||
| static fn() => Workflow::newActivityStub(\stdClass::class), | ||
| ]; | ||
|
|
||
| yield 'newUntypedActivityStub' => [ | ||
| static fn() => Workflow::newUntypedActivityStub(), | ||
| ]; | ||
|
|
||
| yield 'executeActivity' => [ | ||
| static fn() => Workflow::executeActivity('test'), | ||
| ]; | ||
|
|
||
| yield 'getStackTrace' => [ | ||
| static fn() => Workflow::getStackTrace(), | ||
| ]; | ||
|
|
||
| yield 'allHandlersFinished' => [ | ||
| static fn() => Workflow::allHandlersFinished(), | ||
| ]; | ||
|
|
||
| yield 'upsertMemo' => [ | ||
| static fn() => Workflow::upsertMemo(['key' => 'value']), | ||
| ]; | ||
|
|
||
| yield 'upsertSearchAttributes' => [ | ||
| static fn() => Workflow::upsertSearchAttributes(['key' => 'value']), | ||
| ]; | ||
|
|
||
| yield 'uuid' => [ | ||
| static fn() => Workflow::uuid(), | ||
| ]; | ||
|
|
||
| yield 'uuid4' => [ | ||
| static fn() => Workflow::uuid4(), | ||
| ]; | ||
|
|
||
| yield 'uuid7' => [ | ||
| static fn() => Workflow::uuid7(), | ||
| ]; | ||
|
|
||
| yield 'runLocked' => [ | ||
| static fn() => Workflow::runLocked(new \Temporal\Workflow\Mutex('test'), static fn() => yield), | ||
| ]; | ||
|
|
||
| yield 'getLogger' => [ | ||
| static fn() => Workflow::getLogger(), | ||
| ]; | ||
| yield 'getInstance' => [ | ||
| static fn() => Workflow::getInstance(), | ||
| ]; | ||
|
|
||
| yield 'getUpdateContext' => [ | ||
| static fn() => Workflow::getUpdateContext(), | ||
| ]; | ||
|
|
||
| yield 'getLastCompletionResult' => [ | ||
| static fn() => Workflow::getLastCompletionResult(), | ||
| ]; | ||
|
|
||
| yield 'registerQuery' => [ | ||
| static fn() => Workflow::registerQuery('test', static fn() => null), | ||
| ]; | ||
|
|
||
| yield 'registerSignal' => [ | ||
| static fn() => Workflow::registerSignal('test', static fn() => null), | ||
| ]; | ||
|
|
||
| yield 'registerDynamicSignal' => [ | ||
| static fn() => Workflow::registerDynamicSignal(static fn() => null), | ||
| ]; | ||
|
|
||
| yield 'registerDynamicQuery' => [ | ||
| static fn() => Workflow::registerDynamicQuery(static fn() => null), | ||
| ]; | ||
|
|
||
| yield 'registerDynamicUpdate' => [ | ||
| static fn() => Workflow::registerDynamicUpdate(static fn() => null), | ||
| ]; | ||
|
|
||
| yield 'registerUpdate' => [ | ||
| static fn() => Workflow::registerUpdate('test', static fn() => null), | ||
| ]; | ||
|
|
||
| yield 'sideEffect' => [ | ||
| static fn() => Workflow::sideEffect(static fn() => null), | ||
| ]; | ||
|
|
||
| yield 'newContinueAsNewStub' => [ | ||
| static fn() => Workflow::newContinueAsNewStub(\stdClass::class), | ||
| ]; | ||
|
|
||
| yield 'newUntypedChildWorkflowStub' => [ | ||
| static fn() => Workflow::newUntypedChildWorkflowStub('test'), | ||
| ]; | ||
|
|
||
| yield 'newUntypedExternalWorkflowStub' => [ | ||
| static fn() => Workflow::newUntypedExternalWorkflowStub(new Workflow\WorkflowExecution()), | ||
| ]; | ||
|
|
||
| yield 'upsertTypedSearchAttributes' => [ | ||
| static fn() => Workflow::upsertTypedSearchAttributes(), | ||
| ]; | ||
| } | ||
|
|
||
| #[Test] | ||
| #[DataProvider('outOfContextMethods')] | ||
| public function throwsOutOfContextException(callable $method): void | ||
| { | ||
| $this->expectException(OutOfContextException::class); | ||
| $this->expectExceptionMessage('The Workflow facade can be used only inside workflow code.'); | ||
|
|
||
| $method(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we did not have existing one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It uses in different tests to test workflow, but there's no any to test
Temporal\Workflowitself