Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@
<code><![CDATA[toPayload]]></code>
<code><![CDATA[toPayload]]></code>
</ImpureMethodCall>
<PossiblyNullReference>
<code><![CDATA[mergeWith]]></code>
</PossiblyNullReference>
<UnnecessaryVarAnnotation>
<code><![CDATA[SearchAttributeKey]]></code>
</UnnecessaryVarAnnotation>
Expand Down
4 changes: 2 additions & 2 deletions src/Activity/ActivityOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public function mergeWith(?MethodRetry $retry = null): self
{
$self = clone $this;

if ($retry !== null && $this->diff->isPresent($self, 'retryOptions')) {
$self->retryOptions = $this->retryOptions?->mergeWith($retry);
if ($retry !== null) {
$self->retryOptions = ($self->retryOptions ?? RetryOptions::new())->mergeWith($retry);
}

return $self;
Expand Down
4 changes: 2 additions & 2 deletions src/Activity/LocalActivityOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public function mergeWith(?MethodRetry $retry = null): self
{
$self = clone $this;

if ($retry !== null && $this->diff->isPresent($self, 'retryOptions')) {
$self->retryOptions = $this->retryOptions?->mergeWith($retry);
if ($retry !== null) {
$self->retryOptions = ($self->retryOptions ?? RetryOptions::new())->mergeWith($retry);
}

return $self;
Expand Down
4 changes: 2 additions & 2 deletions src/Client/WorkflowOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ public function mergeWith(?MethodRetry $retry = null, ?CronSchedule $cron = null
{
$self = clone $this;

if ($retry !== null && $self->diff->isPresent($self, 'retryOptions')) {
$self->retryOptions = $self->retryOptions->mergeWith($retry);
if ($retry !== null) {
$self->retryOptions = ($self->retryOptions ?? RetryOptions::new())->mergeWith($retry);
}

if ($cron !== null && $self->diff->isPresent($self, 'cronSchedule')) {
Expand Down
4 changes: 2 additions & 2 deletions src/Workflow/ChildWorkflowOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public function mergeWith(?MethodRetry $retry = null, ?CronSchedule $cron = null
{
$self = clone $this;

if ($retry !== null && $self->diff->isPresent($self, 'retryOptions')) {
$self->retryOptions = $self->retryOptions?->mergeWith($retry);
if ($retry !== null) {
$self->retryOptions = ($self->retryOptions ?? RetryOptions::new())->mergeWith($retry);
}

if ($cron !== null && $self->diff->isPresent($self, 'cronSchedule')) {
Expand Down
44 changes: 44 additions & 0 deletions tests/Unit/DTO/ActivityOptionsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Carbon\CarbonInterval;
use Temporal\Activity\ActivityCancellationType;
use Temporal\Activity\ActivityOptions;
use Temporal\Common\MethodRetry;
use Temporal\Common\RetryOptions;
use Temporal\Common\Uuid;

Expand Down Expand Up @@ -124,4 +125,47 @@ public function testRetryOptionsChangesNotMutateState(): void
RetryOptions::new()
));
}

public function testMergeWithMethodRetryFillsDefaultRetryOptions(): void
{
$dto = ActivityOptions::new()
->withRetryOptions(RetryOptions::new())
->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryCreatesRetryOptionsWhenNull(): void
{
$dto = ActivityOptions::new()->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertNotNull($dto->retryOptions);
$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryKeepsUserDefinedFields(): void
{
$methodRetry = new MethodRetry(maximumAttempts: 5, maximumInterval: 30);
$dto = ActivityOptions::new()
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(1))
->mergeWith($methodRetry);

$this->assertSame(1, $dto->retryOptions->maximumAttempts);
$this->assertSame($methodRetry->maximumInterval, $dto->retryOptions->maximumInterval);
}

public function testMergeWithNullRetryDoesNotChangeRetryOptions(): void
{
$retry = RetryOptions::new()->withMaximumAttempts(7);
$dto = ActivityOptions::new()->withRetryOptions($retry)->mergeWith(null);

$this->assertSame(7, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithDoesNotMutateState(): void
{
$dto = new ActivityOptions();

$this->assertNotSame($dto, $dto->mergeWith(new MethodRetry(maximumAttempts: 5)));
}
}
30 changes: 30 additions & 0 deletions tests/Unit/DTO/ChildWorkflowOptionsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Temporal\Tests\Unit\DTO;

use Temporal\Common\IdReusePolicy;
use Temporal\Common\MethodRetry;
use Temporal\Common\RetryOptions;
use Temporal\Workflow\ChildWorkflowCancellationType;
use Temporal\Workflow\ChildWorkflowOptions;
use Temporal\Workflow\ParentClosePolicy;
Expand Down Expand Up @@ -107,4 +109,32 @@ public function testChildWorkflowCancellationTypeChangesNotMutateStateUsingEnum(
));
$this->assertSame(ChildWorkflowCancellationType::TryCancel->value, $dto->cancellationType);
}

public function testMergeWithMethodRetryFillsDefaultRetryOptions(): void
{
$dto = ChildWorkflowOptions::new()
->withRetryOptions(RetryOptions::new())
->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryCreatesRetryOptionsWhenNull(): void
{
$dto = ChildWorkflowOptions::new()->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertNotNull($dto->retryOptions);
$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryKeepsUserDefinedFields(): void
{
$methodRetry = new MethodRetry(maximumAttempts: 5, maximumInterval: 30);
$dto = ChildWorkflowOptions::new()
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(1))
->mergeWith($methodRetry);

$this->assertSame(1, $dto->retryOptions->maximumAttempts);
$this->assertSame($methodRetry->maximumInterval, $dto->retryOptions->maximumInterval);
}
}
55 changes: 55 additions & 0 deletions tests/Unit/DTO/LocalActivityOptionsTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Unit\DTO;

use Temporal\Activity\LocalActivityOptions;
use Temporal\Common\MethodRetry;
use Temporal\Common\RetryOptions;

class LocalActivityOptionsTestCase extends AbstractDTOMarshalling
{
public function testMergeWithMethodRetryFillsDefaultRetryOptions(): void
{
$dto = LocalActivityOptions::new()
->withRetryOptions(RetryOptions::new())
->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryCreatesRetryOptionsWhenNull(): void
{
$dto = LocalActivityOptions::new()->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertNotNull($dto->retryOptions);
$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryKeepsUserDefinedFields(): void
{
$methodRetry = new MethodRetry(maximumAttempts: 5, maximumInterval: 30);
$dto = LocalActivityOptions::new()
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(1))
->mergeWith($methodRetry);

$this->assertSame(1, $dto->retryOptions->maximumAttempts);
$this->assertSame($methodRetry->maximumInterval, $dto->retryOptions->maximumInterval);
}

public function testMergeWithNullRetryDoesNotChangeRetryOptions(): void
{
$retry = RetryOptions::new()->withMaximumAttempts(7);
$dto = LocalActivityOptions::new()->withRetryOptions($retry)->mergeWith(null);

$this->assertSame(7, $dto->retryOptions->maximumAttempts);
}
}
29 changes: 29 additions & 0 deletions tests/Unit/DTO/WorkflowOptionsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Temporal\Api\Common\V1\SearchAttributes;
use Temporal\Client\WorkflowOptions;
use Temporal\Common\IdReusePolicy;
use Temporal\Common\MethodRetry;
use Temporal\Common\RetryOptions;
use Temporal\Common\TypedSearchAttributes;
use Temporal\Common\Uuid;
Expand Down Expand Up @@ -242,4 +243,32 @@ public function testSetTypedSearchAttributesCasting(): void
$this->assertInstanceOf(SearchAttributes::class, $result);
$this->assertCount(1, $result->getIndexedFields());
}

public function testMergeWithMethodRetryFillsDefaultRetryOptions(): void
{
$dto = WorkflowOptions::new()
->withRetryOptions(RetryOptions::new())
->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryCreatesRetryOptionsWhenNull(): void
{
$dto = WorkflowOptions::new()->mergeWith(new MethodRetry(maximumAttempts: 5));

$this->assertNotNull($dto->retryOptions);
$this->assertSame(5, $dto->retryOptions->maximumAttempts);
}

public function testMergeWithMethodRetryKeepsUserDefinedFields(): void
{
$methodRetry = new MethodRetry(maximumAttempts: 5, maximumInterval: 30);
$dto = WorkflowOptions::new()
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(1))
->mergeWith($methodRetry);

$this->assertSame(1, $dto->retryOptions->maximumAttempts);
$this->assertSame($methodRetry->maximumInterval, $dto->retryOptions->maximumInterval);
}
}