Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function signalWithStart(SignalWithStartInput $input, callable $next): Wo
*
* @see WorkflowClientCallsInterceptor::updateWithStart()
*/
public function updateWithStart(UpdateWithStartInput $input, callable $next): UpdateHandle
public function updateWithStart(UpdateWithStartInput $input, callable $next): array

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you replace the array with UpdateWithStartOutput DTO?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, hopefully managed to cover all the relevant places for it.
Also that exception returning makes things messy, considered making separate properties for $handle and $exception, but then we would have nullable values and ugly checks for those

{
return $next($input);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Interceptor/WorkflowClientCallsInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public function signalWithStart(SignalWithStartInput $input, callable $next): Wo
* @param UpdateWithStartInput $input
* @param callable(UpdateWithStartInput): WorkflowExecution $next
*
* @return UpdateHandle
* @return array{WorkflowExecution, UpdateHandle|\Throwable}
*/
public function updateWithStart(UpdateWithStartInput $input, callable $next): UpdateHandle;
public function updateWithStart(UpdateWithStartInput $input, callable $next): array;

/**
* @param callable(GetResultInput): ?ValuesInterface $next
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixtures/src/Interceptor/InterceptorCallsCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
use Temporal\Interceptor\Trait\WorkflowOutboundRequestInterceptorTrait;
use Temporal\Interceptor\WorkflowClient\SignalWithStartInput;
use Temporal\Interceptor\WorkflowClient\StartInput;
use Temporal\Interceptor\WorkflowClient\UpdateWithStartInput;
use Temporal\Interceptor\WorkflowClientCallsInterceptor;
use Temporal\Interceptor\WorkflowInbound\SignalInput;
use Temporal\Interceptor\WorkflowInbound\UpdateInput;
use Temporal\Interceptor\WorkflowInbound\WorkflowInput;
use Temporal\Interceptor\WorkflowInboundCallsInterceptor;
use Temporal\Interceptor\WorkflowOutboundRequestInterceptor;
Expand Down Expand Up @@ -92,4 +94,15 @@ public function signalWithStart(SignalWithStartInput $input, callable $next): Wo
),
);
}

public function updateWithStart(UpdateWithStartInput $input, callable $next): array
{
return $next(
$input->with(
workflowStartInput: $input->workflowStartInput->with(
header: $this->increment($input->workflowStartInput->header, __FUNCTION__),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Temporal\Tests\Workflow\Interceptor;

use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class UpdateHeadersWorkflow
{
private ?array $headers = null;
private bool $updated = false;

#[WorkflowMethod(name: 'InterceptorUpdateHeadersWorkflow')]
public function handler(): mixed
{
yield Workflow::await(fn() => $this->updated);

$this->headers = \iterator_to_array(Workflow::getCurrentContext()->getHeader());

return $this->headers;
}

#[Workflow\UpdateMethod]
public function update(): void
{
$this->updated = true;
}

#[Workflow\QueryMethod]
public function headers(): mixed
{
return $this->headers;
}
}
27 changes: 27 additions & 0 deletions tests/Functional/Interceptor/InterceptorsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
namespace Temporal\Tests\Functional\Interceptor;

use Carbon\CarbonInterval;
use Temporal\Client\Update\LifecycleStage;
use Temporal\Client\Update\UpdateOptions;
use Temporal\Client\WorkflowOptions;
use Temporal\Testing\WithoutTimeSkipping;
use Temporal\Tests\Workflow\Interceptor\HeadersWorkflow;
use Temporal\Tests\Workflow\Interceptor\QueryHeadersWorkflow;
use Temporal\Tests\Workflow\Interceptor\SignalHeadersWorkflow;
use Temporal\Tests\Workflow\Interceptor\UpdateHeadersWorkflow;

/**
* @group client
Expand Down Expand Up @@ -111,6 +114,30 @@ public function testSignalWithStartMethod(): void
], (array)$run->getResult());
}

public function testUpdateWithStartMethod(): void
{
$client = $this->createClient();
$workflow = $client->newWorkflowStub(
UpdateHeadersWorkflow::class,
WorkflowOptions::new()
->withWorkflowExecutionTimeout(CarbonInterval::seconds(5)),
);

$run = $client->updateWithStart($workflow, 'update');

// Workflow header
$this->assertEquals([
/** @see \Temporal\Tests\Interceptor\InterceptorCallsCounter::updateWithStart() */
'updateWithStart' => '1',
/**
* Inherited from handler run
*
* @see \Temporal\Tests\Interceptor\InterceptorCallsCounter::execute()
*/
'execute' => '1',
], $workflow->headers());
}

// todo: rewrite tests because there is no header in query call
// todo: add test about dynamic query
// public function testQueryMethod(): void
Expand Down