From fca29a183a90c55b3c691e59b3246607a993c3af Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 1 Oct 2024 14:33:53 +0400 Subject: [PATCH 1/7] Fix `Scope::start()` signature --- src/Internal/Workflow/Process/Process.php | 2 +- src/Internal/Workflow/Process/Scope.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Internal/Workflow/Process/Process.php b/src/Internal/Workflow/Process/Process.php index 7b15a9dc..bbf30e9a 100644 --- a/src/Internal/Workflow/Process/Process.php +++ b/src/Internal/Workflow/Process/Process.php @@ -174,7 +174,7 @@ function (\Throwable $e): void { /** * @param \Closure(ValuesInterface): mixed $handler */ - public function start(\Closure $handler, ValuesInterface $values = null, bool $deferred): void + public function start(\Closure $handler, ?ValuesInterface $values, bool $deferred): void { try { $this->makeCurrent(); diff --git a/src/Internal/Workflow/Process/Scope.php b/src/Internal/Workflow/Process/Scope.php index 6fb02234..f36f2aef 100644 --- a/src/Internal/Workflow/Process/Scope.php +++ b/src/Internal/Workflow/Process/Scope.php @@ -136,7 +136,7 @@ public function getContext(): WorkflowContext /** * @param \Closure(ValuesInterface): mixed $handler */ - public function start(\Closure $handler, ValuesInterface $values = null, bool $deferred): void + public function start(\Closure $handler, ?ValuesInterface $values, bool $deferred): void { // Create a coroutine generator $this->coroutine = $this->call($handler, $values ?? EncodedValues::empty()); From 9d84a9d7275dfdf3abaf157a5b2c609e311d53ac Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 2 Oct 2024 00:00:32 +0400 Subject: [PATCH 2/7] Fix support for abstract workflow classes detection --- src/Internal/Declaration/Graph/ClassNode.php | 43 +++++++++++++------ .../Instantiator/WorkflowInstantiator.php | 2 +- .../Declaration/Reader/WorkflowReader.php | 27 ++++++------ .../Inheritance/BaseWorkflowWithHandler.php | 23 ++++++++++ .../Inheritance/ExtendingWorkflow.php | 20 +++++++++ tests/Functional/worker.php | 7 ++- .../Inheritance/BaseWorkflowWithHandler.php | 23 ++++++++++ .../Fixture/Inheritance/ExtendingWorkflow.php | 20 +++++++++ .../WorkflowDeclarationTestCase.php | 18 ++++++++ .../WorkflowNegativeDeclarationTestCase.php | 1 - 10 files changed, 154 insertions(+), 30 deletions(-) create mode 100644 tests/Fixtures/src/Workflow/Inheritance/BaseWorkflowWithHandler.php create mode 100644 tests/Fixtures/src/Workflow/Inheritance/ExtendingWorkflow.php create mode 100644 tests/Unit/Declaration/Fixture/Inheritance/BaseWorkflowWithHandler.php create mode 100644 tests/Unit/Declaration/Fixture/Inheritance/ExtendingWorkflow.php diff --git a/src/Internal/Declaration/Graph/ClassNode.php b/src/Internal/Declaration/Graph/ClassNode.php index edeea1ab..122e1b92 100644 --- a/src/Internal/Declaration/Graph/ClassNode.php +++ b/src/Internal/Declaration/Graph/ClassNode.php @@ -11,13 +11,10 @@ namespace Temporal\Internal\Declaration\Graph; +use Temporal\Tests\Workflow\Inheritance\ExtendingWorkflow; + final class ClassNode implements NodeInterface { - /** - * @var \ReflectionClass - */ - private \ReflectionClass $class; - /** * @var array|null */ @@ -26,17 +23,36 @@ final class ClassNode implements NodeInterface /** * @param \ReflectionClass $class */ - public function __construct(\ReflectionClass $class) + public function __construct( + private \ReflectionClass $class, + ) {} + + public function getReflection(): \ReflectionClass { - $this->class = $class; + return $this->class; } /** - * @return \ReflectionClass + * Get all methods from the class and its parents without duplicates. + * + * @param int|null $flags + * @return array + * + * @throws \ReflectionException */ - public function getReflection(): \ReflectionClass - { - return $this->class; + public function getAllMethods(?int $flags = null): array { + /** @var array $result */ + $result = []; + + foreach ($this->getInheritance() as $classes) { + foreach ($classes as $class) { + foreach ($class->getReflection()->getMethods($flags) as $method) { + $result[$method->getName()] ??= $method; + } + } + } + + return $result; } /** @@ -50,8 +66,9 @@ public function count(): int } /** - * @param string $name - * @param bool $reverse + * Get a method with all the declared classes. + * + * @param non-empty-string $name * @return \Traversable * @throws \ReflectionException */ diff --git a/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php b/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php index e26c6084..1ab1ff7e 100644 --- a/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php +++ b/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php @@ -53,6 +53,6 @@ protected function getInstance(PrototypeInterface $prototype): object $prototype->getID(), )); - return $handler->getDeclaringClass()->newInstanceWithoutConstructor(); + return $prototype->getClass()->newInstanceWithoutConstructor(); } } diff --git a/src/Internal/Declaration/Reader/WorkflowReader.php b/src/Internal/Declaration/Reader/WorkflowReader.php index 1b5557ff..bc1e581f 100644 --- a/src/Internal/Declaration/Reader/WorkflowReader.php +++ b/src/Internal/Declaration/Reader/WorkflowReader.php @@ -107,9 +107,7 @@ public function fromObject(object $object): WorkflowPrototype */ protected function getWorkflowPrototypes(ClassNode $graph): \Traversable { - $class = $graph->getReflection(); - - foreach ($class->getMethods() as $reflection) { + foreach ($graph->getAllMethods() as $reflection) { if (!$this->isValidMethod($reflection)) { continue; } @@ -335,7 +333,7 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo // // - #[WorkflowInterface] // - $interface = $this->reader->firstClassMetadata($ctx->getReflection(), WorkflowInterface::class); + $interface = $this->reader->firstClassMetadata($graph->getReflection(), WorkflowInterface::class); // In case if ($interface === null) { @@ -343,7 +341,7 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo } if ($prototype === null) { - $prototype = $this->findProto($handler, $method); + $prototype = $this->findProto($handler, $method, $graph->getReflection()); } if ($prototype !== null && $retry !== null) { @@ -371,15 +369,16 @@ private function getDefaultPrototype(ClassNode $graph): WorkflowPrototype } /** - * @param \ReflectionMethod $handler - * @param \ReflectionMethod $ctx + * @param \ReflectionMethod $handler First method in the inheritance chain + * @param \ReflectionMethod $ctx Current method in the inheritance chain + * @param \ReflectionClass $class Prototype class * @return WorkflowPrototype|null */ - private function findProto(\ReflectionMethod $handler, \ReflectionMethod $ctx): ?WorkflowPrototype - { - $reflection = $ctx->getDeclaringClass(); - - // + private function findProto( + \ReflectionMethod $handler, + \ReflectionMethod $ctx, + \ReflectionClass $class, + ): ?WorkflowPrototype { // The name of the workflow handler must be generated based // method's name which can be redefined using #[WorkflowMethod] // attribute. @@ -418,8 +417,8 @@ private function findProto(\ReflectionMethod $handler, \ReflectionMethod $ctx): ); } - $name = $info->name ?? $reflection->getShortName(); + $name = $info->name ?? $class->getShortName(); - return new WorkflowPrototype($name, $handler, $reflection); + return new WorkflowPrototype($name, $handler, $class); } } diff --git a/tests/Fixtures/src/Workflow/Inheritance/BaseWorkflowWithHandler.php b/tests/Fixtures/src/Workflow/Inheritance/BaseWorkflowWithHandler.php new file mode 100644 index 00000000..4f3deb31 --- /dev/null +++ b/tests/Fixtures/src/Workflow/Inheritance/BaseWorkflowWithHandler.php @@ -0,0 +1,23 @@ +isAbstract()) { + continue; + } + \array_walk( $workers, static fn (WorkerInterface $worker) => $worker->registerWorkflowTypes($class), diff --git a/tests/Unit/Declaration/Fixture/Inheritance/BaseWorkflowWithHandler.php b/tests/Unit/Declaration/Fixture/Inheritance/BaseWorkflowWithHandler.php new file mode 100644 index 00000000..a878bb48 --- /dev/null +++ b/tests/Unit/Declaration/Fixture/Inheritance/BaseWorkflowWithHandler.php @@ -0,0 +1,23 @@ +assertSame('ExampleWorkflowName', $prototype->getID()); } + + public function testHierarchicalWorkflow(): void + { + $instantiator = new WorkflowInstantiator(new \Temporal\Interceptor\SimplePipelineProvider()); + + $instance = $instantiator->instantiate( + new WorkflowPrototype( + 'extending', + new \ReflectionMethod(ExtendingWorkflow::class, 'handler'), + new \ReflectionClass(ExtendingWorkflow::class), + ), + ); + + $this->assertInstanceOf(ExtendingWorkflow::class, $instance->getContext()); + } } diff --git a/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php b/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php index c96e627b..a28fde97 100644 --- a/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php +++ b/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php @@ -21,7 +21,6 @@ use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithMultipleMethods; use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithoutHandler; use Temporal\Workflow\WorkflowInterface; -use Temporal\Workflow\WorkflowMethod; /** * @group unit From 770472e7be4fb3681314c1e200b847c16681e5eb Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 2 Oct 2024 01:19:40 +0400 Subject: [PATCH 3/7] Fix WorkflowInterface attribute detection in case of interfaces --- .../Declaration/Reader/WorkflowReader.php | 20 ++++++++++++++++--- tests/Functional/Client/AwaitTestCase.php | 2 +- .../Client/UntypedWorkflowStubTestCase.php | 2 +- tests/Functional/SimpleWorkflowTestCase.php | 8 ++++++++ .../WorkflowDeclarationTestCase.php | 10 ++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Internal/Declaration/Reader/WorkflowReader.php b/src/Internal/Declaration/Reader/WorkflowReader.php index bc1e581f..b3e874af 100644 --- a/src/Internal/Declaration/Reader/WorkflowReader.php +++ b/src/Internal/Declaration/Reader/WorkflowReader.php @@ -333,15 +333,29 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo // // - #[WorkflowInterface] // - $interface = $this->reader->firstClassMetadata($graph->getReflection(), WorkflowInterface::class); + /** @var \ReflectionClass|null $context */ + $context = null; + foreach ($graph->getIterator() as $edges) { + foreach ($edges as $node) { + $interface = $this->reader->firstClassMetadata( + $context = $node->getReflection(), + WorkflowInterface::class, + ); + + if ($interface !== null) { + break 2; + } + } + } // In case if ($interface === null) { continue; } + \assert($context !== null); if ($prototype === null) { - $prototype = $this->findProto($handler, $method, $graph->getReflection()); + $prototype = $this->findProto($handler, $method, $context); } if ($prototype !== null && $retry !== null) { @@ -371,7 +385,7 @@ private function getDefaultPrototype(ClassNode $graph): WorkflowPrototype /** * @param \ReflectionMethod $handler First method in the inheritance chain * @param \ReflectionMethod $ctx Current method in the inheritance chain - * @param \ReflectionClass $class Prototype class + * @param \ReflectionClass $class Class or Interface with #[WorkflowInterface] attribute * @return WorkflowPrototype|null */ private function findProto( diff --git a/tests/Functional/Client/AwaitTestCase.php b/tests/Functional/Client/AwaitTestCase.php index ff286d8c..212be6ab 100644 --- a/tests/Functional/Client/AwaitTestCase.php +++ b/tests/Functional/Client/AwaitTestCase.php @@ -63,7 +63,7 @@ public function testAggregated(): void 'test3', 'test4' ], - $run->getResult(Type::TYPE_ARRAY) + $run->getResult(Type::TYPE_ARRAY, 3) ); } diff --git a/tests/Functional/Client/UntypedWorkflowStubTestCase.php b/tests/Functional/Client/UntypedWorkflowStubTestCase.php index dd6b5d20..3d53d3c8 100644 --- a/tests/Functional/Client/UntypedWorkflowStubTestCase.php +++ b/tests/Functional/Client/UntypedWorkflowStubTestCase.php @@ -264,7 +264,7 @@ public function testSignalRunningWorkflowWithInheritedSignal() $signaller = $client->newUntypedRunningWorkflowStub($workflowId, $workflowRunId); $signaller->signal('addValue', 'test1'); - $result = $workflowRun->getResult(); + $result = $workflowRun->getResult(10); $this->assertEquals(['test1'], $result); } } diff --git a/tests/Functional/SimpleWorkflowTestCase.php b/tests/Functional/SimpleWorkflowTestCase.php index 1d974722..6a112d49 100644 --- a/tests/Functional/SimpleWorkflowTestCase.php +++ b/tests/Functional/SimpleWorkflowTestCase.php @@ -10,6 +10,7 @@ use Temporal\Client\WorkflowOptions; use Temporal\Testing\ActivityMocker; use Temporal\Tests\TestCase; +use Temporal\Tests\Workflow\Inheritance\ExtendingWorkflow; use Temporal\Tests\Workflow\SimpleWorkflow; use Temporal\Tests\Workflow\YieldGeneratorWorkflow; use Temporal\Tests\Workflow\YieldScalarsWorkflow; @@ -119,6 +120,13 @@ public function testYieldGenerator(): void $this->assertSame('bar', $run->getResult()); } + public function testWorkflowMethodInAbstractParent(): void + { + $workflow = $this->workflowClient->newWorkflowStub(ExtendingWorkflow::class); + $run = $this->workflowClient->start($workflow); + $this->assertNull($run->getResult(5)); + } + private function assertContainsEvent(WorkflowExecution $execution, int $event): void { $history = $this->workflowClient->getWorkflowHistory( diff --git a/tests/Unit/Declaration/WorkflowDeclarationTestCase.php b/tests/Unit/Declaration/WorkflowDeclarationTestCase.php index 62d8bba3..ba6f0107 100644 --- a/tests/Unit/Declaration/WorkflowDeclarationTestCase.php +++ b/tests/Unit/Declaration/WorkflowDeclarationTestCase.php @@ -14,6 +14,7 @@ use Carbon\CarbonInterval; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\TestDox; +use Spiral\Attributes\AttributeReader; use Temporal\Common\CronSchedule; use Temporal\Internal\Declaration\Instantiator\WorkflowInstantiator; use Temporal\Internal\Declaration\Prototype\WorkflowPrototype; @@ -216,4 +217,13 @@ public function testHierarchicalWorkflow(): void $this->assertInstanceOf(ExtendingWorkflow::class, $instance->getContext()); } + + public function testWorkflowWithInterface(): void + { + $reader = new WorkflowReader(new AttributeReader()); + + $result = $reader->fromClass(\Temporal\Tests\Workflow\AggregatedWorkflowImpl::class); + + $this->assertSame('AggregatedWorkflow', $result->getID()); + } } From 56f1b1155d325cb793aca9645499d96f18f15b01 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 2 Oct 2024 01:47:41 +0400 Subject: [PATCH 4/7] Fix mixing interfaces and implementations on workflow prototype building --- .../Declaration/Reader/WorkflowReader.php | 8 +++++--- .../Client/UntypedWorkflowStubTestCase.php | 1 - .../Declaration/WorkflowDeclarationTestCase.php | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Internal/Declaration/Reader/WorkflowReader.php b/src/Internal/Declaration/Reader/WorkflowReader.php index b3e874af..356791e3 100644 --- a/src/Internal/Declaration/Reader/WorkflowReader.php +++ b/src/Internal/Declaration/Reader/WorkflowReader.php @@ -355,7 +355,7 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo \assert($context !== null); if ($prototype === null) { - $prototype = $this->findProto($handler, $method, $context); + $prototype = $this->findProto($handler, $method, $context, $graph->getReflection()); } if ($prototype !== null && $retry !== null) { @@ -385,12 +385,14 @@ private function getDefaultPrototype(ClassNode $graph): WorkflowPrototype /** * @param \ReflectionMethod $handler First method in the inheritance chain * @param \ReflectionMethod $ctx Current method in the inheritance chain - * @param \ReflectionClass $class Class or Interface with #[WorkflowInterface] attribute + * @param \ReflectionClass $interface Class or Interface with #[WorkflowInterface] attribute + * @param \ReflectionClass $class Target class * @return WorkflowPrototype|null */ private function findProto( \ReflectionMethod $handler, \ReflectionMethod $ctx, + \ReflectionClass $interface, \ReflectionClass $class, ): ?WorkflowPrototype { // The name of the workflow handler must be generated based @@ -431,7 +433,7 @@ private function findProto( ); } - $name = $info->name ?? $class->getShortName(); + $name = $info->name ?? $interface->getShortName(); return new WorkflowPrototype($name, $handler, $class); } diff --git a/tests/Functional/Client/UntypedWorkflowStubTestCase.php b/tests/Functional/Client/UntypedWorkflowStubTestCase.php index 3d53d3c8..1a38f923 100644 --- a/tests/Functional/Client/UntypedWorkflowStubTestCase.php +++ b/tests/Functional/Client/UntypedWorkflowStubTestCase.php @@ -18,7 +18,6 @@ use Temporal\Exception\Failure\TerminatedFailure; use Temporal\Exception\IllegalStateException; use Temporal\Exception\InvalidArgumentException; -use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithoutHandler; use Temporal\Workflow\WorkflowExecutionStatus; /** diff --git a/tests/Unit/Declaration/WorkflowDeclarationTestCase.php b/tests/Unit/Declaration/WorkflowDeclarationTestCase.php index ba6f0107..8d434b0f 100644 --- a/tests/Unit/Declaration/WorkflowDeclarationTestCase.php +++ b/tests/Unit/Declaration/WorkflowDeclarationTestCase.php @@ -24,11 +24,11 @@ use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithCron; use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithCronAndRetry; use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithCustomName; -use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithInterface; use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithoutHandler; use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithQueries; use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithRetry; use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithSignals; +use Temporal\Tests\Workflow\AggregatedWorkflowImpl; /** * @group unit @@ -222,8 +222,20 @@ public function testWorkflowWithInterface(): void { $reader = new WorkflowReader(new AttributeReader()); - $result = $reader->fromClass(\Temporal\Tests\Workflow\AggregatedWorkflowImpl::class); + $result = $reader->fromClass(AggregatedWorkflowImpl::class); $this->assertSame('AggregatedWorkflow', $result->getID()); } + + public function testInstantiateWorkflowWithInterface(): void + { + $instantiator = new WorkflowInstantiator(new \Temporal\Interceptor\SimplePipelineProvider()); + $reader = new WorkflowReader(new AttributeReader()); + $prototype = $reader->fromClass(AggregatedWorkflowImpl::class); + + $instance = $instantiator->instantiate($prototype); + + $this->assertInstanceOf(AggregatedWorkflowImpl::class, $instance->getContext()); + $this->assertSame('AggregatedWorkflow', $prototype->getID()); + } } From 335180fdacd20d9c00d13103cf09b9119eeecfb9 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 1 Oct 2024 18:50:59 +0400 Subject: [PATCH 5/7] Add test with Workflow::getTypedInput --- .../Extra/Workflow/InitMethodTest.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/Acceptance/Extra/Workflow/InitMethodTest.php diff --git a/tests/Acceptance/Extra/Workflow/InitMethodTest.php b/tests/Acceptance/Extra/Workflow/InitMethodTest.php new file mode 100644 index 00000000..aead8057 --- /dev/null +++ b/tests/Acceptance/Extra/Workflow/InitMethodTest.php @@ -0,0 +1,52 @@ +assertTrue($stub->getResult(5)); + } +} + +#[WorkflowInterface] +class TestWorkflow +{ + private array $initInput; + + public function __construct() { + $this->initInput = Workflow::getTypedInput(); + } + + #[WorkflowMethod(name: "Extra_Workflow_InitMethod")] + public function handle(Input $input) + { + return $this->initInput === \func_get_args(); + } +} + +class Input +{ + public function __construct( + public string $name, + public int $age, + ) {} +} From befe4cd1a3d8a41427fcfc61fa19d50c728a6be0 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 2 Oct 2024 02:01:45 +0400 Subject: [PATCH 6/7] Fix timeouts in tests; fix psalm issues --- src/Internal/Declaration/Graph/ClassNode.php | 2 +- .../Instantiator/WorkflowInstantiator.php | 2 +- .../Declaration/Reader/WorkflowReader.php | 4 +- .../Extra/Workflow/InitMethodTest.php | 52 ------------------- .../Client/UntypedWorkflowStubTestCase.php | 2 +- tests/Functional/SimpleWorkflowTestCase.php | 2 +- 6 files changed, 6 insertions(+), 58 deletions(-) delete mode 100644 tests/Acceptance/Extra/Workflow/InitMethodTest.php diff --git a/src/Internal/Declaration/Graph/ClassNode.php b/src/Internal/Declaration/Graph/ClassNode.php index 122e1b92..19256b8f 100644 --- a/src/Internal/Declaration/Graph/ClassNode.php +++ b/src/Internal/Declaration/Graph/ClassNode.php @@ -35,7 +35,7 @@ public function getReflection(): \ReflectionClass /** * Get all methods from the class and its parents without duplicates. * - * @param int|null $flags + * @param int<0, 119>|null $flags * @return array * * @throws \ReflectionException diff --git a/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php b/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php index 1ab1ff7e..c6ac7785 100644 --- a/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php +++ b/src/Internal/Declaration/Instantiator/WorkflowInstantiator.php @@ -48,7 +48,7 @@ public function instantiate(PrototypeInterface $prototype): WorkflowInstance */ protected function getInstance(PrototypeInterface $prototype): object { - $handler = $prototype->getHandler() ?? throw new InstantiationException(\sprintf( + $prototype->getHandler() ?? throw new InstantiationException(\sprintf( 'Unable to instantiate workflow "%s" without handler method', $prototype->getID(), )); diff --git a/src/Internal/Declaration/Reader/WorkflowReader.php b/src/Internal/Declaration/Reader/WorkflowReader.php index 356791e3..5b8183f6 100644 --- a/src/Internal/Declaration/Reader/WorkflowReader.php +++ b/src/Internal/Declaration/Reader/WorkflowReader.php @@ -303,7 +303,7 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo // $contextualRetry = $previousRetry; - foreach ($group as $ctx => $method) { + foreach ($group as $method) { /** @var MethodRetry $retry */ $retry = $this->reader->firstFunctionMetadata($method, MethodRetry::class); @@ -334,7 +334,7 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo // - #[WorkflowInterface] // /** @var \ReflectionClass|null $context */ - $context = null; + $interface = $context = null; foreach ($graph->getIterator() as $edges) { foreach ($edges as $node) { $interface = $this->reader->firstClassMetadata( diff --git a/tests/Acceptance/Extra/Workflow/InitMethodTest.php b/tests/Acceptance/Extra/Workflow/InitMethodTest.php deleted file mode 100644 index aead8057..00000000 --- a/tests/Acceptance/Extra/Workflow/InitMethodTest.php +++ /dev/null @@ -1,52 +0,0 @@ -assertTrue($stub->getResult(5)); - } -} - -#[WorkflowInterface] -class TestWorkflow -{ - private array $initInput; - - public function __construct() { - $this->initInput = Workflow::getTypedInput(); - } - - #[WorkflowMethod(name: "Extra_Workflow_InitMethod")] - public function handle(Input $input) - { - return $this->initInput === \func_get_args(); - } -} - -class Input -{ - public function __construct( - public string $name, - public int $age, - ) {} -} diff --git a/tests/Functional/Client/UntypedWorkflowStubTestCase.php b/tests/Functional/Client/UntypedWorkflowStubTestCase.php index 1a38f923..f1188e09 100644 --- a/tests/Functional/Client/UntypedWorkflowStubTestCase.php +++ b/tests/Functional/Client/UntypedWorkflowStubTestCase.php @@ -263,7 +263,7 @@ public function testSignalRunningWorkflowWithInheritedSignal() $signaller = $client->newUntypedRunningWorkflowStub($workflowId, $workflowRunId); $signaller->signal('addValue', 'test1'); - $result = $workflowRun->getResult(10); + $result = $workflowRun->getResult(timeout: 10); $this->assertEquals(['test1'], $result); } } diff --git a/tests/Functional/SimpleWorkflowTestCase.php b/tests/Functional/SimpleWorkflowTestCase.php index 6a112d49..5e6fb958 100644 --- a/tests/Functional/SimpleWorkflowTestCase.php +++ b/tests/Functional/SimpleWorkflowTestCase.php @@ -124,7 +124,7 @@ public function testWorkflowMethodInAbstractParent(): void { $workflow = $this->workflowClient->newWorkflowStub(ExtendingWorkflow::class); $run = $this->workflowClient->start($workflow); - $this->assertNull($run->getResult(5)); + $this->assertNull($run->getResult(timeout: 5)); } private function assertContainsEvent(WorkflowExecution $execution, int $event): void From 057e2616c0849975c8fdf02859523ffff9b0467e Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 2 Oct 2024 19:53:54 +0400 Subject: [PATCH 7/7] Remove unnecessary parameter in ClassNode::getAllMethods --- src/Internal/Declaration/Graph/ClassNode.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Internal/Declaration/Graph/ClassNode.php b/src/Internal/Declaration/Graph/ClassNode.php index 19256b8f..ff86cf0a 100644 --- a/src/Internal/Declaration/Graph/ClassNode.php +++ b/src/Internal/Declaration/Graph/ClassNode.php @@ -35,18 +35,17 @@ public function getReflection(): \ReflectionClass /** * Get all methods from the class and its parents without duplicates. * - * @param int<0, 119>|null $flags * @return array * * @throws \ReflectionException */ - public function getAllMethods(?int $flags = null): array { + public function getAllMethods(): array { /** @var array $result */ $result = []; foreach ($this->getInheritance() as $classes) { foreach ($classes as $class) { - foreach ($class->getReflection()->getMethods($flags) as $method) { + foreach ($class->getReflection()->getMethods() as $method) { $result[$method->getName()] ??= $method; } }