Skip to content

Commit 7102166

Browse files
committed
refactor: streamline context handling in Process and DynamicUpdateTest
1 parent 27a4c8b commit 7102166

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/Internal/Workflow/Process/Process.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public function initAndStart(
188188
$handler = $instance->getHandler();
189189
$instance = $context->getWorkflowInstance();
190190
$arguments = null;
191+
$values = [];
191192

192193
try {
193194
// Initialize workflow instance
@@ -205,14 +206,13 @@ public function initAndStart(
205206
$context->getHeader(),
206207
),
207208
);
208-
Workflow::setCurrentContext($context);
209-
210-
$instance->init($values);
211-
} else {
212-
Workflow::setCurrentContext($context);
213-
$instance->init();
214209
}
215210

211+
// Workflow::setCurrentContext($context);
212+
$this->setContext($context);
213+
$this->makeCurrent();
214+
$instance->init($values);
215+
216216
$context->setReadonly(false);
217217

218218
// Execute
@@ -240,8 +240,8 @@ function (WorkflowInput $input) use ($context, $arguments, $handler, $deferred):
240240
$context->isReplaying(),
241241
));
242242
} catch (\Throwable $e) {
243-
/** @psalm-suppress RedundantPropertyInitializationCheck */
244-
isset($this->context) or $this->setContext($context->setReadonly(false));
243+
isset($this->context) or $this->setContext($context);
244+
$context->setReadonly(false);
245245
$this->complete($e);
246246
} finally {
247247
Workflow::setCurrentContext(null);

tests/Acceptance/Extra/Update/DynamicUpdateTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,24 @@ class TestWorkflow
6666
private array $result = [];
6767
private bool $exit = false;
6868

69-
#[WorkflowMethod(name: "Extra_Update_DynamicUpdate")]
70-
public function handle()
71-
{
72-
// Register update methods
69+
public function __construct() {
70+
// Register update methods in constructor
7371
Workflow::registerUpdate(self::UPDATE_METHOD, function () {
7472
// Also Update context is tested
7573
$id = Workflow::getUpdateContext()->getUpdateId();
7674
return $this->result[self::UPDATE_METHOD] = $id;
7775
});
76+
}
77+
78+
#[WorkflowMethod(name: "Extra_Update_DynamicUpdate")]
79+
public function handle()
80+
{
7881
// Update method with validation
7982
Workflow::registerUpdate(
8083
self::UPDATE_METHOD_WV,
8184
fn(int $value): int => $value,
8285
fn(int $value) => $value > 0 or throw new \InvalidArgumentException('Value must be positive'),
8386
);
84-
8587
yield Workflow::await(fn() => $this->exit);
8688
return $this->result;
8789
}

0 commit comments

Comments
 (0)