Skip to content

Commit

Permalink
Add test case with wf::timer and wf::await to confirm that `Workf…
Browse files Browse the repository at this point in the history
…lowContext::$timer` isn't necessary now
  • Loading branch information
roxblnfk committed Dec 16, 2022
1 parent 02dfb53 commit cb78de2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Fixtures/src/Workflow/TimerWayWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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;

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

#[Workflow\WorkflowInterface]
class TimerWayWorkflow
{
#[WorkflowMethod(name: 'TimerWayWorkflow')]
public function handler(): iterable
{
$timerResolved = false;

$timer = Workflow::timer(20)
->then(function () use (&$timerResolved) {
$timerResolved = true;
});

yield Workflow::await($timer, fn() => true);

return $timerResolved;
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/src/Workflow/TimerWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\SimpleActivity;

/**
* @see \Temporal\Tests\Functional\WorkflowTestCase::testTimer()
*/
#[Workflow\WorkflowInterface]
class TimerWorkflow
{
Expand Down
10 changes: 10 additions & 0 deletions tests/Functional/Client/AwaitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Temporal\Tests\Workflow\AggregatedWorkflow;
use Temporal\Tests\Workflow\LoopWithSignalCoroutinesWorkflow;
use Temporal\Tests\Workflow\LoopWorkflow;
use Temporal\Tests\Workflow\TimerWayWorkflow;
use Temporal\Tests\Workflow\WaitWorkflow;
use Temporal\Workflow\WorkflowStub;

Expand Down Expand Up @@ -189,4 +190,13 @@ public function testCancelAwait()
$this->assertInstanceOf(CanceledFailure::class, $e->getPrevious());
}
}

public function testTimer(): void
{
$client = $this->createClient();
$wait = $client->newWorkflowStub(TimerWayWorkflow::class);
$run = $client->start($wait);

$this->assertFalse($run->getResult());
}
}

0 comments on commit cb78de2

Please sign in to comment.