Skip to content

Commit

Permalink
Use static keyword in WorkflowException::withoutMessage method (#189)
Browse files Browse the repository at this point in the history
::withoutMessage method is used in classes which extends WorkflowException
  • Loading branch information
eriklotin authored Jun 13, 2022
1 parent 4a7e963 commit dd7f3ee
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Exception/Client/WorkflowException.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public static function withoutMessage(
string $workflowType = null,
\Throwable $previous = null
): WorkflowException {
return new self(null, $execution, $workflowType, $previous);
return new static(null, $execution, $workflowType, $previous);
}
}
72 changes: 72 additions & 0 deletions tests/Unit/Internal/Client/WorkflowStubTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Unit\Internal\Client;

use Temporal\Client\ClientOptions;
use Temporal\Client\GRPC\ServiceClientInterface;
use Temporal\Client\GRPC\StatusCode;
use Temporal\DataConverter\DataConverterInterface;
use Temporal\Exception\Client\ServiceClientException;
use Temporal\Exception\Client\WorkflowNotFoundException;
use Temporal\Exception\Client\WorkflowServiceException;
use Temporal\Internal\Client\WorkflowStub;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Temporal\Workflow\WorkflowExecution;

/**
* @internal
*
* @covers \Temporal\Internal\Client\WorkflowStub
*/
final class WorkflowStubTest extends TestCase
{
private WorkflowStub $workflowStub;
/** @var MockObject|ServiceClientInterface */
private $serviceClient;

protected function setUp(): void
{
$this->serviceClient = $this->createMock(ServiceClientInterface::class);
$this->workflowStub = new WorkflowStub(
$this->serviceClient,
new ClientOptions(),
$this->createMock(DataConverterInterface::class),
);
$this->workflowStub->setExecution(new WorkflowExecution());
}

public function testSignalThrowsWorkflowNotFoundException(): void
{
$status = new \stdClass();
$status->details = 'status details';
$status->code = StatusCode::NOT_FOUND;
$serviceClientException = new ServiceClientException($status);
$this->serviceClient
->expects(static::once())
->method('SignalWorkflowExecution')
->willThrowException($serviceClientException);

static::expectException(WorkflowNotFoundException::class);

$this->workflowStub->signal('signalName');
}

public function testSignalThrowsWorkflowServiceException(): void
{
$status = new \stdClass();
$status->details = 'status details';
$status->code = StatusCode::INTERNAL;
$serviceClientException = new ServiceClientException($status);
$this->serviceClient
->expects(static::once())
->method('SignalWorkflowExecution')
->willThrowException($serviceClientException);

static::expectException(WorkflowServiceException::class);

$this->workflowStub->signal('signalName');
}
}

0 comments on commit dd7f3ee

Please sign in to comment.