From cc65a086505930e81698593b2e7a1636db732f21 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 14 Jan 2025 02:30:14 +0400 Subject: [PATCH] Fix DeferredGenerator test --- src/Internal/Workflow/Process/Scope.php | 10 ++++---- .../Workflow/DeferredGeneratorTestCase.php | 24 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Internal/Workflow/Process/Scope.php b/src/Internal/Workflow/Process/Scope.php index 12fff64d..ad22dc09 100644 --- a/src/Internal/Workflow/Process/Scope.php +++ b/src/Internal/Workflow/Process/Scope.php @@ -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 @@ -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; @@ -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: diff --git a/tests/Unit/Workflow/DeferredGeneratorTestCase.php b/tests/Unit/Workflow/DeferredGeneratorTestCase.php index 48de00d5..b76811d7 100644 --- a/tests/Unit/Workflow/DeferredGeneratorTestCase.php +++ b/tests/Unit/Workflow/DeferredGeneratorTestCase.php @@ -81,7 +81,6 @@ public function testCompareReturn(): void [ 'current', 'key', 'current', 'key', 'valid', 'next', - 'getReturn', ], ); } @@ -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( @@ -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 $actions