Skip to content

Commit

Permalink
Fix Harness ThrowOnExecute test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jan 13, 2025
1 parent 862ae25 commit 8d56faa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/Internal/Workflow/Process/DeferredGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function send(mixed $value): mixed
*/
public function getReturn(): mixed
{
// $this->start();
$this->finished or throw new \LogicException('Cannot get return value of a generator that was not finished.');
try {
return $this->generator->getReturn();
} catch (\Throwable $e) {
Expand Down Expand Up @@ -149,7 +149,8 @@ public function valid(): bool
{
$this->start();
try {
return $this->generator->valid();
$result = $this->generator->valid() or $this->finished = true;
return $result;
} catch (\Throwable $e) {
$this->handleException($e);
}
Expand Down Expand Up @@ -218,9 +219,9 @@ private function handleException(\Throwable $e): never
{
$this->finished and throw $e;
$this->finished = true;
foreach ($this->catchers as $catch) {
foreach ($this->catchers as $catcher) {
try {
$catch($e);
$catcher($e);
} catch (\Throwable) {
// Do nothing.
}
Expand Down
10 changes: 5 additions & 5 deletions src/Internal/Workflow/Process/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,13 @@ protected function next(): void
begin:
$this->context->resolveConditions();

if (!$this->coroutine->valid()) {
try {
try {
if (!$this->coroutine->valid()) {
$this->onResult($this->coroutine->getReturn());
} catch (\Throwable) {
$this->onResult(null);
return;
}

} catch (\Throwable) {
$this->onResult(null);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Acceptance/Extra/Update/UpdateWithStartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function failWithBadUpdateName(
try {
$stub->getResult(timeout: 1);
$this->fail('Workflow must fail');
} catch (WorkflowFailedException $e) {
} catch (WorkflowFailedException) {
$this->assertTrue(true);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Acceptance/Harness/ChildWorkflow/ThrowOnExecuteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ThrowOnExecuteTest extends TestCase
public static function throwExceptionOnInit(#[Stub('Harness_ChildWorkflow_ThrowsOnExecute')]WorkflowStubInterface $stub): void
{
try {
$stub->getResult(timeout: 10);
$stub->getResult();
throw new \Exception('Expected exception');
} catch (WorkflowFailedException $e) {
self::assertSame('Harness_ChildWorkflow_ThrowsOnExecute', $e->getWorkflowType());
Expand All @@ -48,7 +48,7 @@ public static function throwExceptionAfterInit(
WorkflowStubInterface $stub,
): void {
try {
$stub->getResult(timeout: 10);
$stub->getResult();
throw new \Exception('Expected exception');
} catch (WorkflowFailedException $e) {
self::assertSame('Harness_ChildWorkflow_ThrowsOnExecute', $e->getWorkflowType());
Expand Down

0 comments on commit 8d56faa

Please sign in to comment.