Skip to content

Commit

Permalink
Fix DeferredGenerator test
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jan 13, 2025
1 parent 8d56faa commit cc65a08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
10 changes: 4 additions & 6 deletions src/Internal/Workflow/Process/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function start(\Closure $handler, ?ValuesInterface $values, bool $deferre
{
// Create a coroutine generator
$this->coroutine = DeferredGenerator::fromHandler($handler, $values ?? EncodedValues::empty())
// ->catch(tr(...));
->catch($this->onException(...));

$deferred
Expand Down Expand Up @@ -186,7 +187,8 @@ public function startSignal(callable $handler, ValuesInterface $values, string $
*/
public function attach(\Generator $generator): self
{
$this->coroutine = DeferredGenerator::fromGenerator($generator);
$this->coroutine = DeferredGenerator::fromGenerator($generator)
->catch($this->onException(...));

$this->next();
return $this;
Expand Down Expand Up @@ -418,11 +420,7 @@ protected function next(): void
break;

case $current instanceof \Generator:
try {
$this->nextPromise($this->createScope(false)->attach($current));
} catch (\Throwable $e) {
$this->coroutine->throw($e);
}
$this->nextPromise($this->createScope(false)->attach($current));
break;

default:
Expand Down
24 changes: 12 additions & 12 deletions tests/Unit/Workflow/DeferredGeneratorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function testCompareReturn(): void
[
'current', 'key', 'current', 'key', 'valid',
'next',
'getReturn',
],
);
}
Expand Down Expand Up @@ -137,17 +136,6 @@ public function testCompareEmptyThrowValid(): void
);
}

public function testCompareEmptyThrowGetReturn(): void
{
$this->compare(
fn() => (function () {
throw new \Exception('foo');
yield;
})(),
['getReturn', 'getReturn'],
);
}

public function testCompareEmptyThrowGetKey(): void
{
$this->compare(
Expand Down Expand Up @@ -214,6 +202,18 @@ public function testLazyOnGeneratorHandler(): void
$this->assertNull($lazy->current());
}

public function testGetResultFromNotStartedGenerator(): void
{
$closure = fn() => (function () {
yield 1;
});

$handler = DeferredGenerator::fromHandler($closure, EncodedValues::empty());

$this->expectException(\LogicException::class);
$handler->getReturn();
}

/**
* @param callable(): \Generator $generatorFactory
* @param iterable<Action|int, array{Action, mixed}> $actions
Expand Down

0 comments on commit cc65a08

Please sign in to comment.