Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"google/common-protos": "^4.9",
"google/protobuf": "^4.31.1",
"grpc/grpc": "^1.57",
"internal/promise": "^2.12",
"internal/promise": "^2.12 || ^3.4",
"nesbot/carbon": "^2.72.6 || ^3.8.4",
"psr/log": "^2.0 || ^3.0.2",
"ramsey/uuid": "^4.7.6",
Expand All @@ -49,7 +49,10 @@
"GPBMetadata\\Temporal\\Api\\Testservice\\": "testing/api/testservice/GPBMetadata/Temporal/Api/Testservice",
"Temporal\\Testing\\": "testing/src",
"Temporal\\": "src"
}
},
"files": [
"src/include.php"
]
},
"require-dev": {
"buggregator/trap": "^1.13.0",
Expand All @@ -60,7 +63,7 @@
"jetbrains/phpstorm-attributes": "dev-master",
"laminas/laminas-code": "^4.16",
"phpunit/phpunit": "10.5.45",
"spiral/code-style": "~2.2.2",
"spiral/code-style": "~2.3.0",
"spiral/core": "^3.14.9",
"ta-tikoma/phpunit-architecture-test": "^0.8.5",
"vimeo/psalm": "^5.26.1 || ^6.2"
Expand Down
24 changes: 9 additions & 15 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,15 +1019,10 @@
</UndefinedInterfaceMethod>
</file>
<file src="src/Internal/Transport/CompletableResult.php">
<PossiblyNullArgument>
<InvalidArgument>
<code><![CDATA[$this->wrapContext($onFulfilledOrRejected)]]></code>
<code><![CDATA[$this->wrapContext($onRejected)]]></code>
</PossiblyNullArgument>
<UndefinedInterfaceMethod>
<code><![CDATA[cancel]]></code>
<code><![CDATA[catch]]></code>
<code><![CDATA[finally]]></code>
</UndefinedInterfaceMethod>
<code><![CDATA[$this->wrapContext($onFulfilledOrRejected)]]></code>
</InvalidArgument>
</file>
<file src="src/Internal/Transport/Router/DestroyWorkflow.php">
<UndefinedInterfaceMethod>
Expand Down Expand Up @@ -1056,9 +1051,6 @@
<code><![CDATA[$request->getOptions()['name']]]></code>
<code><![CDATA[$request->getOptions()['updateId']]]></code>
</PossiblyUndefinedStringArrayOffset>
<UndefinedInterfaceMethod>
<code><![CDATA[cancel]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Internal/Transport/Router/StackTrace.php">
<ArgumentTypeCoercion>
Expand Down Expand Up @@ -1167,14 +1159,11 @@
<InvalidArgument>
<code><![CDATA[$onFulfilled]]></code>
<code><![CDATA[$onRejected]]></code>
<code><![CDATA[$resolver->resolve(...)]]></code>
</InvalidArgument>
<PropertyNotSetInConstructor>
<code><![CDATA[$coroutine]]></code>
</PropertyNotSetInConstructor>
<UndefinedInterfaceMethod>
<code><![CDATA[catch]]></code>
<code><![CDATA[finally]]></code>
</UndefinedInterfaceMethod>
<UnusedClosureParam>
<code><![CDATA[$e]]></code>
</UnusedClosureParam>
Expand Down Expand Up @@ -1249,6 +1238,11 @@
<file src="src/Promise.php">
<InvalidArgument>
<code><![CDATA[$reasons]]></code>
<code><![CDATA[$resolve]]></code>
<code><![CDATA[$values]]></code>
<code><![CDATA[$values]]></code>
<code><![CDATA[[]]]></code>
<code><![CDATA[[]]]></code>
</InvalidArgument>
<InvalidOperand>
<code><![CDATA[$promisesOrValues]]></code>
Expand Down
20 changes: 20 additions & 0 deletions src/Internal/Promise/RejectedValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Temporal\Internal\Promise;

/**
* An exception that wraps a rejected value.
*
* @see \Temporal\Promise::reject()
* @internal
*/
final class RejectedValue extends \Exception
{
public function __construct(
public mixed $value,
) {
parent::__construct();
}
}
8 changes: 4 additions & 4 deletions src/Internal/Workflow/WorkflowContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public function upsertMemo(array $values): void
$this->callsInterceptor->with(
function (UpsertMemoInput $input): PromiseInterface {
if ($input->memo === []) {
return resolve();
return resolve(null);
}

$result = $this->request(new UpsertMemo($input->memo), false, false);
Expand Down Expand Up @@ -546,7 +546,7 @@ public function upsertSearchAttributes(array $searchAttributes): void
$this->callsInterceptor->with(
function (UpsertSearchAttributesInput $input): PromiseInterface {
if ($input->searchAttributes === []) {
return resolve();
return resolve(null);
}

$result = $this->request(new UpsertSearchAttributes($input->searchAttributes), false, false);
Expand Down Expand Up @@ -574,7 +574,7 @@ public function upsertTypedSearchAttributes(SearchAttributeUpdate ...$updates):
$this->callsInterceptor->with(
function (UpsertTypedSearchAttributesInput $input): PromiseInterface {
if ($input->updates === []) {
return resolve();
return resolve(null);
}

$result = $this->request(new UpsertTypedSearchAttributes($input->updates), false, false);
Expand Down Expand Up @@ -648,7 +648,7 @@ public function resolveConditions(): void
foreach ($awaitsGroup as $i => [$condition, $deferred]) {
if ($condition()) {
unset($this->awaits[$awaitsGroupId][$i]);
$deferred->resolve();
$deferred->resolve(null);
$this->resolveConditionGroup($awaitsGroupId);
}
}
Expand Down
29 changes: 12 additions & 17 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use React\Promise\PromiseInterface;
use Temporal\Internal\Promise\CancellationQueue;
use Temporal\Internal\Promise\Reasons;
use Temporal\Internal\Promise\RejectedValue;

use function React\Promise\race;
use function React\Promise\reject;
Expand All @@ -36,7 +37,7 @@ final class Promise
*/
public static function all(iterable $promises): PromiseInterface
{
return self::map($promises, static fn($val): mixed => $val);
return self::map($promises, static fn(mixed $val): mixed => $val);
}

/**
Expand Down Expand Up @@ -205,10 +206,9 @@ static function (mixed $mapped) use ($i, &$values, &$toResolve, $resolve): void
*
* @param iterable<int, PromiseInterface|mixed> $promises
* @param callable(mixed $current, mixed $carry, int $current, positive-int $items): mixed $reduce
* @param mixed $initial
* @psalm-param PromiseReduceCallback $reduce
*/
public static function reduce(iterable $promises, callable $reduce, $initial = null): PromiseInterface
public static function reduce(iterable $promises, callable $reduce, mixed $initial = null): PromiseInterface
{
$cancellationQueue = new CancellationQueue();
$cancellationQueue->enqueue($promises);
Expand Down Expand Up @@ -273,32 +273,27 @@ static function (iterable $array) use (
*
* If `$promiseOrValue` is a promise, it will be returned as is.
*
* @param null|mixed $promiseOrValue
* @template T
* @param PromiseInterface<T>|T $promiseOrValue
* @return PromiseInterface<T>
*/
public static function resolve($promiseOrValue = null): PromiseInterface
public static function resolve(mixed $promiseOrValue = null): PromiseInterface
{
return resolve($promiseOrValue);
}

/**
* Creates a rejected promise for the supplied `$promiseOrValue`.
*
* If `$promiseOrValue` is a value, it will be the rejection value of the
* returned promise.
*
* If `$promiseOrValue` is a promise, its completion value will be the rejected
* value of the returned promise.
*
* This can be useful in situations where you need to reject a promise without
* throwing an exception. For example, it allows you to propagate a rejection with
* the value of another promise.
* If `$reason` is not a `\Throwable`, the returned promise will be
* fulfilled with that value instead.
*
* @param null|mixed $promiseOrValue
* @param \Throwable $reason
* @return PromiseInterface<never>
*/
public static function reject($promiseOrValue = null): PromiseInterface
public static function reject(mixed $reason): PromiseInterface
{
return reject($promiseOrValue);
return reject($reason instanceof \Throwable ? $reason : new RejectedValue($reason));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/include.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Temporal;

use function React\Promise\set_rejection_handler;

if (\function_exists('\React\Promise\set_rejection_handler')) {
set_rejection_handler(null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function () use ($simple, $waitSignaled) {

yield $simple->add(8);
$this->status[] = 'child signaled';
$waitSignaled->resolve();
$waitSignaled->resolve(null);

return yield $call;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Functional/.rr.silent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ temporal:

logs:
mode: none
# file_logger_options:
# log_output: "test-feature.log"
# channels:
# activities:
# mode: none

kv:
test:
Expand Down
34 changes: 17 additions & 17 deletions tests/Functional/SimpleWorkflowTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ final class SimpleWorkflowTestCase extends TestCase
private WorkflowClient $workflowClient;
private ActivityMocker $activityMocks;

protected function setUp(): void
{
$this->workflowClient = new WorkflowClient(
ServiceClient::create('localhost:7233')
);
$this->activityMocks = new ActivityMocker();

parent::setUp();
}

protected function tearDown(): void
{
$this->activityMocks->clear();
parent::tearDown();
}

public function testWorkflowReturnsUpperCasedInput(): void
{
$this->activityMocks->expectCompletion('SimpleActivity.echo', 'world');
Expand Down Expand Up @@ -81,7 +65,7 @@ public function testLocalActivity(): void
$workflow = $this->workflowClient
->newWorkflowStub(
\Temporal\Tests\Workflow\LocalActivityWorkflow::class,
WorkflowOptions::new()->withWorkflowRunTimeout('10 seconds')
WorkflowOptions::new()->withWorkflowRunTimeout('10 seconds'),
);
$run = $this->workflowClient->start($workflow);

Expand Down Expand Up @@ -127,6 +111,22 @@ public function testWorkflowMethodInAbstractParent(): void
$this->assertNull($run->getResult(timeout: 5));
}

protected function setUp(): void
{
$this->workflowClient = new WorkflowClient(
ServiceClient::create('localhost:7233'),
);
$this->activityMocks = new ActivityMocker();

parent::setUp();
}

protected function tearDown(): void
{
$this->activityMocks->clear();
parent::tearDown();
}

private function assertContainsEvent(WorkflowExecution $execution, int $event): void
{
$history = $this->workflowClient->getWorkflowHistory(
Expand Down
Loading