Skip to content

Commit

Permalink
- more strict php tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed Jan 22, 2021
1 parent 2fc67c4 commit aa5f424
Show file tree
Hide file tree
Showing 41 changed files with 371 additions and 47 deletions.
3 changes: 2 additions & 1 deletion test/src/Workflow/ActivityStubWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ActivityStubWorkflow
{
#[WorkflowMethod(name: 'ActivityStubWorkflow')]
Expand Down Expand Up @@ -35,4 +36,4 @@ public function handler(

return $result;
}
}
}
30 changes: 30 additions & 0 deletions test/src/Workflow/AggregatedWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Temporal\Tests\Workflow;

use Temporal\Workflow;
use Temporal\Workflow\SignalMethod;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
class AggregatedWorkflow
{
private array $values = [];

#[SignalMethod]
public function addValue(
string $value
) {
$this->values[] = $value;
}

#[WorkflowMethod(name: 'AggregatedWorkflow')]
public function run(
int $count
) {
yield Workflow::await(fn() => count($this->values) === $count);

return $this->values;
}
}
28 changes: 28 additions & 0 deletions test/src/Workflow/AsyncActivityWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityCancellationType;
use Temporal\Activity\ActivityOptions;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\SimpleActivity;

#[Workflow\WorkflowInterface]
class AsyncActivityWorkflow
{
#[WorkflowMethod(name: 'AsyncActivityWorkflow')]
public function handler()
{
$simple = Workflow::newActivityStub(
SimpleActivity::class,
ActivityOptions::new()
->withStartToCloseTimeout(20)
->withCancellationType(ActivityCancellationType::WAIT_CANCELLATION_COMPLETED)
);

return yield $simple->external();
}
}
3 changes: 2 additions & 1 deletion test/src/Workflow/BinaryWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class BinaryWorkflow
{
#[WorkflowMethod(name: 'BinaryWorkflow')]
Expand All @@ -17,4 +18,4 @@ public function handler(

return yield Workflow::executeActivity('SimpleActivity.md5', [$input], $opts);
}
}
}
4 changes: 2 additions & 2 deletions test/src/Workflow/CancelSignalledChildWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Temporal\Tests\Workflow;

use React\Promise\Deferred;
use Temporal\Exception\CancellationException;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class CancelSignalledChildWorkflow
{
private array $status = [];
Expand Down Expand Up @@ -54,4 +54,4 @@ function () use ($simple, $waitSignalled) {
return 'cancelled ok';
}
}
}
}
13 changes: 8 additions & 5 deletions test/src/Workflow/CanceledHeartbeatWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@

namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityCancellationType;
use Temporal\Activity\ActivityOptions;
use Temporal\Common\RetryOptions;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\HeartBeatActivity;

#[Workflow\WorkflowInterface]
class CanceledHeartbeatWorkflow
{
#[WorkflowMethod(name: 'CanceledHeartbeatWorkflow')]
public function handler(
int $iterations
): iterable {
public function handler(): iterable
{
$act = Workflow::newActivityStub(
HeartBeatActivity::class,
ActivityOptions::new()->withStartToCloseTimeout(50)
ActivityOptions::new()
->withStartToCloseTimeout(50)
->withCancellationType(ActivityCancellationType::WAIT_CANCELLATION_COMPLETED)
->withHeartbeatTimeout(1)
);

return yield $act->slow('test');
Expand Down
4 changes: 2 additions & 2 deletions test/src/Workflow/CancelledMidflightWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityOptions;
use Temporal\Exception\CancellationException;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class CancelledMidflightWorkflow
{
private array $status = [];
Expand Down Expand Up @@ -44,4 +44,4 @@ function () {

return 'OK';
}
}
}
3 changes: 2 additions & 1 deletion test/src/Workflow/CancelledNestedWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class CancelledNestedWorkflow
{
private array $status = [];
Expand Down Expand Up @@ -68,4 +69,4 @@ function () {

return 'OK';
}
}
}
3 changes: 2 additions & 1 deletion test/src/Workflow/CancelledScopeWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\SimpleActivity;

#[Workflow\WorkflowInterface]
class CancelledScopeWorkflow
{
#[WorkflowMethod(name: 'CancelledScopeWorkflow')]
Expand Down Expand Up @@ -35,4 +36,4 @@ function () use (&$cancelled) {

return $cancelled;
}
}
}
6 changes: 4 additions & 2 deletions test/src/Workflow/CancelledSingleScopeWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\SimpleActivity;

#[Workflow\WorkflowInterface]
class CancelledSingleScopeWorkflow
{
private array $status = [];
Expand All @@ -23,7 +24,8 @@ public function handler()
{
$simple = Workflow::newActivityStub(
SimpleActivity::class,
ActivityOptions::new()->withStartToCloseTimeout(5)
ActivityOptions::new()
->withStartToCloseTimeout(5)
);

$this->status[] = 'start';
Expand All @@ -50,4 +52,4 @@ function () {

return 'OK';
}
}
}
3 changes: 2 additions & 1 deletion test/src/Workflow/CancelledWithCompensationWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class CancelledWithCompensationWorkflow
{
private array $status = [];
Expand Down Expand Up @@ -75,4 +76,4 @@ function () use ($simple) {
$this->status[] = 'result: ' . $result;
return $result;
}
}
}
3 changes: 2 additions & 1 deletion test/src/Workflow/CancelledWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class CancelledWorkflow
{
#[WorkflowMethod(name: 'CancelledWorkflow')]
Expand All @@ -27,4 +28,4 @@ public function handler()
return "CANCELLED";
}
}
}
}
1 change: 1 addition & 0 deletions test/src/Workflow/ChainedWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ChainedWorkflow
{
#[WorkflowMethod(name: 'ChainedWorkflow')]
Expand Down
3 changes: 2 additions & 1 deletion test/src/Workflow/ChildStubWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ChildStubWorkflow
{
#[WorkflowMethod(name: 'ChildStubWorkflow')]
Expand All @@ -26,4 +27,4 @@ public function handler(

return $result;
}
}
}
26 changes: 26 additions & 0 deletions test/src/Workflow/ComplexExceptionalWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityOptions;
use Temporal\Common\RetryOptions;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ComplexExceptionalWorkflow
{
#[WorkflowMethod(name: 'ComplexExceptionalWorkflow')]
public function handler()
{
$child = Workflow::newChildWorkflowStub(
ExceptionalActivityWorkflow::class,
Workflow\ChildWorkflowOptions::new()->withRetryOptions(
(new RetryOptions())->withMaximumAttempts(1)
)
);

return yield $child->handler();
}
}
5 changes: 3 additions & 2 deletions test/src/Workflow/ContinuableWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\SimpleActivity;

#[Workflow\WorkflowInterface]
class ContinuableWorkflow
{
#[WorkflowMethod(name: 'ContinuableWorkflow')]
Expand All @@ -32,6 +33,6 @@ public function handler(
yield $simple->echo((string)$generation);
}

return Workflow::newContinueAsNewStub(self::class)->handler(++$generation);
return Workflow::continueAsNew('ContinuableWorkflow', [++$generation]);
}
}
}
6 changes: 4 additions & 2 deletions test/src/Workflow/EmptyWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Temporal\Tests\Workflow;

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

#[Workflow\WorkflowInterface]
class EmptyWorkflow
{
#[WorkflowMethod(name: 'EmptyWorkflow')]
#[WorkflowMethod]
public function handler()
{
return 42;
}
}
}
25 changes: 25 additions & 0 deletions test/src/Workflow/ExceptionalActivityWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityOptions;
use Temporal\Common\RetryOptions;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ExceptionalActivityWorkflow
{
#[WorkflowMethod(name: 'ExceptionalActivityWorkflow')]
public function handler()
{
$simple = Workflow::newActivityStub(
SimpleActivity::class,
ActivityOptions::new()->withStartToCloseTimeout(5)
->withRetryOptions((new RetryOptions())->withMaximumAttempts(1))
);

return yield $simple->fail();
}
}
18 changes: 18 additions & 0 deletions test/src/Workflow/ExceptionalWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityOptions;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ExceptionalWorkflow
{
#[WorkflowMethod(name: 'ExceptionalWorkflow')]
public function handler()
{
throw new \RuntimeException("workflow error");
}
}
1 change: 1 addition & 0 deletions test/src/Workflow/FailedHeartbeatWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\HeartBeatActivity;

#[Workflow\WorkflowInterface]
class FailedHeartbeatWorkflow
{
#[WorkflowMethod(name: 'FailedHeartbeatWorkflow')]
Expand Down
Loading

0 comments on commit aa5f424

Please sign in to comment.