diff --git a/.github/workflows/run-test-suite.yml b/.github/workflows/run-test-suite.yml index dbd0d501..f1354cca 100644 --- a/.github/workflows/run-test-suite.yml +++ b/.github/workflows/run-test-suite.yml @@ -116,7 +116,7 @@ jobs: - name: Run tests with Temporal test server if: inputs.run-temporal-test-server == true run: ${{ format( - 'vendor/bin/phpunit --testsuite={0} --testdox --verbose --exclude {1}', + 'vendor/bin/phpunit --testsuite={0} --testdox --colors=always --exclude-group {1}', inputs.test-suite, contains(matrix.extensions-suffix, 'protobuf') && 'skip-on-test-server,skip-ext-protobuf' || 'skip-on-test-server' ) }} @@ -125,4 +125,4 @@ jobs: - name: Run tests without Temporal test server if: inputs.run-temporal-test-server == false - run: vendor/bin/phpunit --testsuite=${{ inputs.test-suite }} --testdox --verbose + run: vendor/bin/phpunit --testsuite=${{ inputs.test-suite }} --testdox --colors=always diff --git a/composer.json b/composer.json index 0b465a69..a5b3ba63 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ "illuminate/support": "^9.0", "jetbrains/phpstorm-attributes": "dev-master@dev", "laminas/laminas-code": "^4.0", - "phpunit/phpunit": "^9.5.21", + "phpunit/phpunit": "^10.5", "symfony/var-dumper": "^6.0 || ^7.0", "vimeo/psalm": "^4.30 || ^5.4" }, diff --git a/phpunit.xml b/phpunit.xml index 4f54f60f..75d277d0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,36 +3,31 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="tests/bootstrap.php" backupGlobals="false" - backupStaticAttributes="false" colors="true" - verbose="true" - convertErrorsToExceptions="true" - convertNoticesToExceptions="true" - convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" stopOnError="false" stderr="true" > - - - src - - - - - tests/Unit - - - tests/Feature - - - tests/Functional - - - - - - - + + + tests/Unit + + + tests/Feature + + + tests/Functional + + + + + + + + + + src + + diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 740f1798..81e1f337 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -921,7 +921,7 @@ \IteratorAggregate - + c entries[$id] ?? null]]> @@ -1159,9 +1159,6 @@ - - $process === null - pull @@ -1333,11 +1330,6 @@ $e - - - $process === null - - __call diff --git a/src/DataConverter/EncodedCollection.php b/src/DataConverter/EncodedCollection.php index fe020483..3ad3d7ae 100644 --- a/src/DataConverter/EncodedCollection.php +++ b/src/DataConverter/EncodedCollection.php @@ -24,7 +24,7 @@ * * @implements IteratorAggregate */ -class EncodedCollection implements IteratorAggregate +class EncodedCollection implements IteratorAggregate, Countable { /** * @var DataConverterInterface|null diff --git a/src/Internal/Declaration/Destroyable.php b/src/Internal/Declaration/Destroyable.php new file mode 100644 index 00000000..3ae2d954 --- /dev/null +++ b/src/Internal/Declaration/Destroyable.php @@ -0,0 +1,21 @@ + @@ -165,6 +165,14 @@ public function clearSignalQueue(): void $this->signalQueue->clear(); } + public function destroy(): void + { + $this->signalQueue->clear(); + $this->signalHandlers = []; + $this->queryHandlers = []; + unset($this->queryExecutor); + } + /** * Make a Closure from a callable. * diff --git a/src/Internal/Support/GarbageCollector.php b/src/Internal/Support/GarbageCollector.php new file mode 100644 index 00000000..1886ac44 --- /dev/null +++ b/src/Internal/Support/GarbageCollector.php @@ -0,0 +1,65 @@ + Number of ticks since last GC. */ + private int $counter = 0; + + /** + * @param positive-int $threshold Number of ticks before GC will be called. + * @param int<0, max> $timeout Timeout in seconds. + * @param positive-int|null $lastTime Start point for timeout. + */ + public function __construct( + private readonly int $threshold, + private readonly int $timeout, + ?int $lastTime = null, + ) { + $this->lastTime = $lastTime ?? \time(); + } + + /** + * Check if GC should be called. + */ + public function check(): bool + { + if (++$this->counter >= $this->threshold) { + return true; + } + + if (\time() - $this->lastTime > $this->timeout) { + return true; + } + + return false; + } + + /** + * Call GC. + */ + public function collect(): void + { + \gc_collect_cycles(); + + $this->lastTime = \time(); + $this->counter = 0; + } +} diff --git a/src/Internal/Transport/Router/DestroyWorkflow.php b/src/Internal/Transport/Router/DestroyWorkflow.php index 179b7e1e..8bcbbfca 100644 --- a/src/Internal/Transport/Router/DestroyWorkflow.php +++ b/src/Internal/Transport/Router/DestroyWorkflow.php @@ -14,15 +14,28 @@ use React\Promise\Deferred; use Temporal\DataConverter\EncodedValues; use Temporal\Exception\DestructMemorizedInstanceException; +use Temporal\Internal\Support\GarbageCollector; use Temporal\Internal\Workflow\Process\Process; +use Temporal\Internal\Workflow\ProcessCollection; +use Temporal\Worker\LoopInterface; use Temporal\Worker\Transport\Command\ServerRequestInterface; class DestroyWorkflow extends WorkflowProcessAwareRoute { - /** - * @var string - */ - private const ERROR_PROCESS_NOT_DEFINED = 'Unable to kill workflow because workflow process #%s was not found'; + /** Maximum number of ticks before GC call. */ + private const GC_THRESHOLD = 1000; + /** Interval between GC calls in seconds. */ + private const GC_TIMEOUT_SECONDS = 30; + + private GarbageCollector $gc; + + public function __construct( + ProcessCollection $running, + protected LoopInterface $loop + ) { + $this->gc = new GarbageCollector(self::GC_THRESHOLD, self::GC_TIMEOUT_SECONDS); + parent::__construct($running); + } /** * {@inheritDoc} @@ -32,8 +45,6 @@ public function handle(ServerRequestInterface $request, array $headers, Deferred $this->kill($request->getID()); $resolver->resolve(EncodedValues::fromValues([null])); - - \gc_collect_cycles(); } /** @@ -43,13 +54,21 @@ public function handle(ServerRequestInterface $request, array $headers, Deferred public function kill(string $runId): array { /** @var Process $process */ - $process = $this->running->find($runId); - if ($process === null) { - throw new \InvalidArgumentException(\sprintf(self::ERROR_PROCESS_NOT_DEFINED, $runId)); - } + $process = $this->running + ->pull($runId, "Unable to kill workflow because workflow process #$runId was not found"); - $this->running->pull($runId); $process->cancel(new DestructMemorizedInstanceException()); + $this->loop->once( + LoopInterface::ON_FINALLY, + function () use ($process) { + $process->destroy(); + + // Collect garbage if needed + if ($this->gc->check()) { + $this->gc->collect(); + } + }, + ); return []; } diff --git a/src/Internal/Transport/Router/WorkflowProcessAwareRoute.php b/src/Internal/Transport/Router/WorkflowProcessAwareRoute.php index 98950efe..85d6f2af 100644 --- a/src/Internal/Transport/Router/WorkflowProcessAwareRoute.php +++ b/src/Internal/Transport/Router/WorkflowProcessAwareRoute.php @@ -22,17 +22,12 @@ abstract class WorkflowProcessAwareRoute extends Route */ private const ERROR_PROCESS_NOT_FOUND = 'Workflow with the specified run identifier "%s" not found'; - /** - * @var RepositoryInterface - */ - protected RepositoryInterface $running; - /** * @param RepositoryInterface $running */ - public function __construct(RepositoryInterface $running) - { - $this->running = $running; + public function __construct( + protected RepositoryInterface $running + ) { } /** diff --git a/src/Internal/Workflow/Process/Scope.php b/src/Internal/Workflow/Process/Scope.php index 844e574a..bd1671f8 100644 --- a/src/Internal/Workflow/Process/Scope.php +++ b/src/Internal/Workflow/Process/Scope.php @@ -19,6 +19,7 @@ use Temporal\Exception\Failure\CanceledFailure; use Temporal\Exception\Failure\TemporalFailure; use Temporal\Exception\InvalidArgumentException; +use Temporal\Internal\Declaration\Destroyable; use Temporal\Internal\ServiceContainer; use Temporal\Internal\Transport\Request\Cancel; use Temporal\Internal\Workflow\ScopeContext; @@ -36,7 +37,7 @@ * @psalm-internal Temporal\Internal * @implements CancellationScopeInterface */ -class Scope implements CancellationScopeInterface +class Scope implements CancellationScopeInterface, Destroyable { /** * @var ServiceContainer @@ -245,8 +246,8 @@ public function cancel(\Throwable $reason = null): void foreach ($this->onCancel as $i => $handler) { $this->makeCurrent(); - $handler($reason); unset($this->onCancel[$i]); + $handler($reason); } } @@ -596,4 +597,11 @@ private function defer(\Closure $tick) return $listener; } + + public function destroy(): void + { + $this->scopeContext->destroy(); + $this->context->destroy(); + unset($this->coroutine); + } } diff --git a/src/Internal/Workflow/ProcessCollection.php b/src/Internal/Workflow/ProcessCollection.php index 7916ee0a..4006a932 100644 --- a/src/Internal/Workflow/ProcessCollection.php +++ b/src/Internal/Workflow/ProcessCollection.php @@ -20,10 +20,7 @@ */ class ProcessCollection extends ArrayRepository { - /** - * @var string - */ - private const ERROR_PROCESS_NOT_DEFINED = 'Unable to kill workflow because workflow process #%s was not found'; + private const ERROR_PROCESS_NOT_FOUND = 'Process #%s not found.'; public function __construct() { @@ -32,16 +29,14 @@ public function __construct() /** * @param string $runId + * @param non-empty-string|null $error Error message if the process was not found. * @return Process */ - public function pull(string $runId): Process + public function pull(string $runId, ?string $error = null): Process { - /** @var Process $process */ - $process = $this->find($runId); - - if ($process === null) { - throw new \InvalidArgumentException(\sprintf(self::ERROR_PROCESS_NOT_DEFINED, $runId)); - } + $process = $this->find($runId) ?? throw new \InvalidArgumentException( + $error ?? \sprintf(self::ERROR_PROCESS_NOT_FOUND, $runId), + ); $this->remove($runId); diff --git a/src/Internal/Workflow/ScopeContext.php b/src/Internal/Workflow/ScopeContext.php index ca093242..0c42b217 100644 --- a/src/Internal/Workflow/ScopeContext.php +++ b/src/Internal/Workflow/ScopeContext.php @@ -14,6 +14,7 @@ use React\Promise\Deferred; use React\Promise\PromiseInterface; use Temporal\Exception\Failure\CanceledFailure; +use Temporal\Internal\Declaration\Destroyable; use Temporal\Internal\Transport\CompletableResult; use Temporal\Internal\Workflow\Process\Scope; use Temporal\Worker\Transport\Command\RequestInterface; @@ -21,7 +22,7 @@ use Temporal\Workflow\ScopedContextInterface; use Temporal\Internal\Transport\Request\UpsertSearchAttributes; -class ScopeContext extends WorkflowContext implements ScopedContextInterface +class ScopeContext extends WorkflowContext implements ScopedContextInterface, Destroyable { private WorkflowContext $parent; private Scope $scope; @@ -145,4 +146,10 @@ public function upsertSearchAttributes(array $searchAttributes): void new UpsertSearchAttributes($searchAttributes) ); } + + public function destroy(): void + { + parent::destroy(); + unset($this->scope, $this->parent, $this->onRequest); + } } diff --git a/src/Internal/Workflow/WorkflowContext.php b/src/Internal/Workflow/WorkflowContext.php index a0b66d8e..7b6205cf 100644 --- a/src/Internal/Workflow/WorkflowContext.php +++ b/src/Internal/Workflow/WorkflowContext.php @@ -38,6 +38,7 @@ use Temporal\Interceptor\WorkflowOutboundCalls\UpsertSearchAttributesInput; use Temporal\Interceptor\WorkflowOutboundCallsInterceptor; use Temporal\Interceptor\WorkflowOutboundRequestInterceptor; +use Temporal\Internal\Declaration\Destroyable; use Temporal\Internal\Declaration\WorkflowInstanceInterface; use Temporal\Internal\Interceptor\HeaderCarrier; use Temporal\Internal\Interceptor\Pipeline; @@ -68,7 +69,7 @@ use function React\Promise\reject; use function React\Promise\resolve; -class WorkflowContext implements WorkflowContextInterface, HeaderCarrier +class WorkflowContext implements WorkflowContextInterface, HeaderCarrier, Destroyable { /** * Contains conditional groups that contains tuple of a condition callable and its promise @@ -85,18 +86,10 @@ class WorkflowContext implements WorkflowContextInterface, HeaderCarrier /** @var Pipeline */ private Pipeline $callsInterceptor; - /** - * WorkflowContext constructor. - * @param ServiceContainer $services - * @param ClientInterface $client - * @param WorkflowInstanceInterface $workflowInstance - * @param Input $input - * @param ValuesInterface|null $lastCompletionResult - */ public function __construct( protected ServiceContainer $services, protected ClientInterface $client, - protected WorkflowInstanceInterface $workflowInstance, + protected WorkflowInstanceInterface&Destroyable $workflowInstance, protected Input $input, protected ?ValuesInterface $lastCompletionResult = null ) { @@ -585,8 +578,8 @@ public function resolveConditions(): void foreach ($this->awaits as $awaitsGroupId => $awaitsGroup) { foreach ($awaitsGroup as $i => [$condition, $deferred]) { if ($condition()) { - $deferred->resolve(); unset($this->awaits[$awaitsGroupId][$i]); + $deferred->resolve(); $this->resolveConditionGroup($awaitsGroupId); } } @@ -699,4 +692,11 @@ protected function recordTrace(): void { $this->trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); } + + public function destroy(): void + { + $this->awaits = []; + $this->workflowInstance->destroy(); + unset($this->workflowInstance); + } } diff --git a/src/Worker/LoopInterface.php b/src/Worker/LoopInterface.php index e350c61b..ad50d90a 100644 --- a/src/Worker/LoopInterface.php +++ b/src/Worker/LoopInterface.php @@ -54,6 +54,12 @@ interface LoopInterface extends EventListenerInterface */ public const ON_CALLBACK = 'callback'; + /** Must be emitted at the end of each loop iteration after all other events. + * + * @var string + */ + public const ON_FINALLY = 'finally'; + /** * @return void */ diff --git a/src/Worker/Transport/Codec/ProtoCodec/Decoder.php b/src/Worker/Transport/Codec/ProtoCodec/Decoder.php index cc24d8eb..3653225f 100644 --- a/src/Worker/Transport/Codec/ProtoCodec/Decoder.php +++ b/src/Worker/Transport/Codec/ProtoCodec/Decoder.php @@ -18,16 +18,12 @@ use RoadRunner\Temporal\DTO\V1\Message; use Temporal\Worker\Transport\Command\FailureResponse; use Temporal\Worker\Transport\Command\FailureResponseInterface; -use Temporal\Worker\Transport\Command\RequestInterface; use Temporal\Worker\Transport\Command\ResponseInterface; use Temporal\Worker\Transport\Command\ServerRequest; use Temporal\Worker\Transport\Command\ServerRequestInterface; use Temporal\Worker\Transport\Command\SuccessResponse; use Temporal\Worker\Transport\Command\SuccessResponseInterface; -/** - * @codeCoverageIgnore tested via roadrunner-temporal repository. - */ class Decoder { /** diff --git a/src/Worker/Worker.php b/src/Worker/Worker.php index a862e1b7..6f3e5735 100644 --- a/src/Worker/Worker.php +++ b/src/Worker/Worker.php @@ -177,7 +177,7 @@ protected function createRouter(): RouterInterface $router->add(new Router\InvokeQuery($this->services->running, $this->services->loop)); $router->add(new Router\InvokeSignal($this->services->running)); $router->add(new Router\CancelWorkflow($this->services->running)); - $router->add(new Router\DestroyWorkflow($this->services->running)); + $router->add(new Router\DestroyWorkflow($this->services->running, $this->services->loop)); $router->add(new Router\StackTrace($this->services->running)); return $router; diff --git a/src/WorkerFactory.php b/src/WorkerFactory.php index 44c8fe0a..3db3f4ea 100644 --- a/src/WorkerFactory.php +++ b/src/WorkerFactory.php @@ -285,6 +285,7 @@ public function tick(): void $this->emit(LoopInterface::ON_CALLBACK); $this->emit(LoopInterface::ON_QUERY); $this->emit(LoopInterface::ON_TICK); + $this->emit(LoopInterface::ON_FINALLY); } /** diff --git a/tests/Feature/FeatureTestCase.php b/tests/Feature/AbstractFeature.php similarity index 86% rename from tests/Feature/FeatureTestCase.php rename to tests/Feature/AbstractFeature.php index b92aaf70..05ad53ec 100644 --- a/tests/Feature/FeatureTestCase.php +++ b/tests/Feature/AbstractFeature.php @@ -16,6 +16,6 @@ /** * @group feature */ -abstract class FeatureTestCase extends TestCase +abstract class AbstractFeature extends TestCase { } diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/AbstractFunctional.php similarity index 86% rename from tests/Functional/FunctionalTestCase.php rename to tests/Functional/AbstractFunctional.php index cea959ff..c477c3ba 100644 --- a/tests/Functional/FunctionalTestCase.php +++ b/tests/Functional/AbstractFunctional.php @@ -16,6 +16,6 @@ /** * @group functional */ -abstract class FunctionalTestCase extends TestCase +abstract class AbstractFunctional extends TestCase { } diff --git a/tests/Functional/ActivityInvocationCacheTestCase.php b/tests/Functional/ActivityInvocationCacheTestCase.php index 027a7895..eb1ffa5b 100644 --- a/tests/Functional/ActivityInvocationCacheTestCase.php +++ b/tests/Functional/ActivityInvocationCacheTestCase.php @@ -12,7 +12,7 @@ use Temporal\Worker\Transport\Command\ServerRequest; use Temporal\Worker\Transport\Command\ServerRequestInterface; -class ActivityInvocationCacheTestCase extends FunctionalTestCase +class ActivityInvocationCacheTestCase extends AbstractFunctional { private RoadRunnerActivityInvocationCache $cache; diff --git a/tests/Functional/Client/ClientTestCase.php b/tests/Functional/Client/AbstractClient.php similarity index 93% rename from tests/Functional/Client/ClientTestCase.php rename to tests/Functional/Client/AbstractClient.php index a17e0ab7..6342207e 100644 --- a/tests/Functional/Client/ClientTestCase.php +++ b/tests/Functional/Client/AbstractClient.php @@ -16,14 +16,13 @@ use Temporal\Api\Workflowservice\V1\GetWorkflowExecutionHistoryRequest; use Temporal\Client\GRPC\ServiceClient; use Temporal\Client\WorkflowClient; -use Temporal\Testing\WithoutTimeSkipping; -use Temporal\Tests\Functional\FunctionalTestCase; +use Temporal\Tests\Functional\AbstractFunctional; use Temporal\Workflow\WorkflowExecution; /** * @group client */ -abstract class ClientTestCase extends FunctionalTestCase +abstract class AbstractClient extends AbstractFunctional { /** * @param string $connection diff --git a/tests/Functional/Client/ActivityCompletionClientTestCase.php b/tests/Functional/Client/ActivityCompletionClientTestCase.php index 9cdab285..db1f1daf 100644 --- a/tests/Functional/Client/ActivityCompletionClientTestCase.php +++ b/tests/Functional/Client/ActivityCompletionClientTestCase.php @@ -23,7 +23,7 @@ * @group client * @group functional */ -class ActivityCompletionClientTestCase extends ClientTestCase +class ActivityCompletionClientTestCase extends AbstractClient { public function testCompleteAsyncActivityById() { diff --git a/tests/Functional/Client/AsyncClosureTestCase.php b/tests/Functional/Client/AsyncClosureTestCase.php index 749dd217..0eec1fff 100644 --- a/tests/Functional/Client/AsyncClosureTestCase.php +++ b/tests/Functional/Client/AsyncClosureTestCase.php @@ -19,7 +19,7 @@ * @group client * @group functional */ -class AsyncClosureTestCase extends ClientTestCase +class AsyncClosureTestCase extends AbstractClient { use WithoutTimeSkipping; diff --git a/tests/Functional/Client/AwaitTestCase.php b/tests/Functional/Client/AwaitTestCase.php index df6a177d..ff286d8c 100644 --- a/tests/Functional/Client/AwaitTestCase.php +++ b/tests/Functional/Client/AwaitTestCase.php @@ -28,7 +28,7 @@ * @group client * @group functional */ -class AwaitTestCase extends ClientTestCase +class AwaitTestCase extends AbstractClient { use WithoutTimeSkipping; diff --git a/tests/Functional/Client/DynamicObjectReturnWorkflowTestCase.php b/tests/Functional/Client/DynamicObjectReturnWorkflowTestCase.php index 753fe5c6..575bac10 100644 --- a/tests/Functional/Client/DynamicObjectReturnWorkflowTestCase.php +++ b/tests/Functional/Client/DynamicObjectReturnWorkflowTestCase.php @@ -10,7 +10,7 @@ * @group client * @group functional */ -final class DynamicObjectReturnWorkflowTestCase extends ClientTestCase +final class DynamicObjectReturnWorkflowTestCase extends AbstractClient { public function testWorkflow(): void { diff --git a/tests/Functional/Client/EnumTestCase.php b/tests/Functional/Client/EnumTestCase.php index 1cd716fe..05eaf7c8 100644 --- a/tests/Functional/Client/EnumTestCase.php +++ b/tests/Functional/Client/EnumTestCase.php @@ -22,7 +22,7 @@ * @group client * @group functional */ -class EnumTestCase extends ClientTestCase +class EnumTestCase extends AbstractClient { public function testSimpleEnum(): void { diff --git a/tests/Functional/Client/ExternalWorkflowTestCase.php b/tests/Functional/Client/ExternalWorkflowTestCase.php index d6a17250..0adc085c 100644 --- a/tests/Functional/Client/ExternalWorkflowTestCase.php +++ b/tests/Functional/Client/ExternalWorkflowTestCase.php @@ -18,7 +18,7 @@ use Temporal\Tests\Workflow\LoopSignallingWorkflow; use Temporal\Tests\Workflow\LoopWorkflow; -class ExternalWorkflowTestCase extends ClientTestCase +class ExternalWorkflowTestCase extends AbstractClient { use WithoutTimeSkipping; diff --git a/tests/Functional/Client/FailureTestCase.php b/tests/Functional/Client/FailureTestCase.php index 275dc893..229f976b 100644 --- a/tests/Functional/Client/FailureTestCase.php +++ b/tests/Functional/Client/FailureTestCase.php @@ -23,7 +23,7 @@ * @group client * @group functional */ -class FailureTestCase extends ClientTestCase +class FailureTestCase extends AbstractClient { public function testSimpleFailurePropagation() { diff --git a/tests/Functional/Client/SagaTestCase.php b/tests/Functional/Client/SagaTestCase.php index 3775ae4a..d76f7e43 100644 --- a/tests/Functional/Client/SagaTestCase.php +++ b/tests/Functional/Client/SagaTestCase.php @@ -19,7 +19,7 @@ * @group client * @group functional */ -class SagaTestCase extends ClientTestCase +class SagaTestCase extends AbstractClient { public function testGetResult() { diff --git a/tests/Functional/Client/ServiceClientTestCase.php b/tests/Functional/Client/ServiceClientTestCase.php index ea86b0da..7cfd950e 100644 --- a/tests/Functional/Client/ServiceClientTestCase.php +++ b/tests/Functional/Client/ServiceClientTestCase.php @@ -20,7 +20,7 @@ * @group client * @group functional */ -class ServiceClientTestCase extends ClientTestCase +class ServiceClientTestCase extends AbstractClient { public function testTimeoutException() { diff --git a/tests/Functional/Client/TypeArrayOfObjectsTestCase.php b/tests/Functional/Client/TypeArrayOfObjectsTestCase.php index 16fe2991..a08b7edd 100644 --- a/tests/Functional/Client/TypeArrayOfObjectsTestCase.php +++ b/tests/Functional/Client/TypeArrayOfObjectsTestCase.php @@ -19,7 +19,7 @@ * @group client * @group functional */ -class TypeArrayOfObjectsTestCase extends ClientTestCase +class TypeArrayOfObjectsTestCase extends AbstractClient { public function testArrayOfMessagesReceived(): void { diff --git a/tests/Functional/Client/TypedStubTestCase.php b/tests/Functional/Client/TypedStubTestCase.php index cfe166a6..3ae0b062 100644 --- a/tests/Functional/Client/TypedStubTestCase.php +++ b/tests/Functional/Client/TypedStubTestCase.php @@ -30,7 +30,7 @@ * @group client * @group functional */ -class TypedStubTestCase extends ClientTestCase +class TypedStubTestCase extends AbstractClient { public function testGetResult() { diff --git a/tests/Functional/Client/UntypedWorkflowStubTestCase.php b/tests/Functional/Client/UntypedWorkflowStubTestCase.php index 8822f1fa..fecf99f8 100644 --- a/tests/Functional/Client/UntypedWorkflowStubTestCase.php +++ b/tests/Functional/Client/UntypedWorkflowStubTestCase.php @@ -24,7 +24,7 @@ * @group client * @group functional */ -class UntypedWorkflowStubTestCase extends ClientTestCase +class UntypedWorkflowStubTestCase extends AbstractClient { public function testUntypedStartAndWaitResult() { diff --git a/tests/Functional/Client/UpsertSearchAttributesWorkflowTestCase.php b/tests/Functional/Client/UpsertSearchAttributesWorkflowTestCase.php index 74221b71..ea114585 100644 --- a/tests/Functional/Client/UpsertSearchAttributesWorkflowTestCase.php +++ b/tests/Functional/Client/UpsertSearchAttributesWorkflowTestCase.php @@ -8,19 +8,18 @@ * @group client * @group functional */ -class UpsertSearchAttributesWorkflowTestCase extends ClientTestCase +class UpsertSearchAttributesWorkflowTestCase extends AbstractClient { - // TODO: doesn't work on the new test server ¯\_(ツ)_/¯ - // public function testUpsertSearchAttributes() - // { - // $client = $this->createClient(); - // $workflow = $client->newUntypedWorkflowStub('UpsertSearchAttributesWorkflow'); - // - // $e = $client->start($workflow); - // - // $this->assertNotEmpty($e->getExecution()->getID()); - // $this->assertNotEmpty($e->getExecution()->getRunID()); - // - // $this->assertSame('done', $workflow->getResult()); - // } + public function testUpsertSearchAttributes() + { + $client = $this->createClient(); + $workflow = $client->newUntypedWorkflowStub('UpsertSearchAttributesWorkflow'); + + $e = $client->start($workflow); + + $this->assertNotEmpty($e->getExecution()->getID()); + $this->assertNotEmpty($e->getExecution()->getRunID()); + + $this->assertSame('done', $workflow->getResult()); + } } diff --git a/tests/Functional/Client/UuidTestCase.php b/tests/Functional/Client/UuidTestCase.php index 68671945..ac7ab79c 100644 --- a/tests/Functional/Client/UuidTestCase.php +++ b/tests/Functional/Client/UuidTestCase.php @@ -20,7 +20,7 @@ * @group client * @group functional */ -class UuidTestCase extends ClientTestCase +class UuidTestCase extends AbstractClient { public function testUuidPassedAndReturned(): void { diff --git a/tests/Functional/Interceptor/AbstractClient.php b/tests/Functional/Interceptor/AbstractClient.php index 719e497b..5853062b 100644 --- a/tests/Functional/Interceptor/AbstractClient.php +++ b/tests/Functional/Interceptor/AbstractClient.php @@ -14,13 +14,13 @@ use Temporal\Client\GRPC\ServiceClient; use Temporal\Client\WorkflowClient; use Temporal\Tests\Fixtures\PipelineProvider; -use Temporal\Tests\Functional\FunctionalTestCase; +use Temporal\Tests\Functional\AbstractFunctional; use Temporal\Tests\Interceptor\InterceptorCallsCounter; /** * @group client */ -abstract class AbstractClient extends FunctionalTestCase +abstract class AbstractClient extends AbstractFunctional { /** * @param string $connection diff --git a/tests/Functional/Interceptor/HeaderTestCase.php b/tests/Functional/Interceptor/HeaderTestCase.php index a0e98a9b..1a951220 100644 --- a/tests/Functional/Interceptor/HeaderTestCase.php +++ b/tests/Functional/Interceptor/HeaderTestCase.php @@ -12,7 +12,7 @@ namespace Temporal\Tests\Functional\Interceptor; use Temporal\Client\WorkflowOptions; -use Temporal\Tests\Functional\Client\ClientTestCase; +use Temporal\Tests\Functional\Client\AbstractClient; use Temporal\Tests\Workflow\Header\ChildedHeaderWorkflow; use Temporal\Tests\Workflow\Header\EmptyHeaderWorkflow; @@ -25,7 +25,7 @@ * @group workflow * @group functional */ -class HeaderTestCase extends ClientTestCase +class HeaderTestCase extends AbstractClient { public function testWorkflowEmptyHeader(): void { diff --git a/tests/Functional/WorkflowTestCase.php b/tests/Functional/WorkflowTestCase.php index 76ef50ca..b6295831 100644 --- a/tests/Functional/WorkflowTestCase.php +++ b/tests/Functional/WorkflowTestCase.php @@ -12,7 +12,6 @@ namespace Temporal\Tests\Functional; use Temporal\Common\Uuid; -use Temporal\Tests\Fixtures\CommandResetter; use Temporal\Tests\Fixtures\Splitter; use Temporal\Tests\Fixtures\WorkerMock; @@ -20,7 +19,7 @@ * @group workflow * @group functional */ -class WorkflowTestCase extends FunctionalTestCase +class WorkflowTestCase extends AbstractFunctional { public function setUp(): void { diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/AbstractUnit.php similarity index 87% rename from tests/Unit/UnitTestCase.php rename to tests/Unit/AbstractUnit.php index d3a7a275..beb1c7e9 100644 --- a/tests/Unit/UnitTestCase.php +++ b/tests/Unit/AbstractUnit.php @@ -16,6 +16,6 @@ /** * @group unit */ -abstract class UnitTestCase extends TestCase +abstract class AbstractUnit extends TestCase { } diff --git a/tests/Unit/Activity/ActivityPrototypeTestCase.php b/tests/Unit/Activity/ActivityPrototypeTestCase.php index c1e6adb6..b0bcc733 100644 --- a/tests/Unit/Activity/ActivityPrototypeTestCase.php +++ b/tests/Unit/Activity/ActivityPrototypeTestCase.php @@ -8,10 +8,10 @@ use Spiral\Attributes\AttributeReader; use Spiral\Attributes\Composite\SelectiveReader; use Temporal\Internal\Declaration\Reader\ActivityReader; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; use WeakReference; -final class ActivityPrototypeTestCase extends UnitTestCase +final class ActivityPrototypeTestCase extends AbstractUnit { private ActivityReader $activityReader; diff --git a/tests/Unit/Common/SdkVersionTestCase.php b/tests/Unit/Common/SdkVersionTestCase.php index 455b53d4..ddb62549 100644 --- a/tests/Unit/Common/SdkVersionTestCase.php +++ b/tests/Unit/Common/SdkVersionTestCase.php @@ -2,14 +2,13 @@ namespace Temporal\Tests\Unit\Common; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Temporal\Common\SdkVersion; class SdkVersionTestCase extends TestCase { - /** - * @dataProvider versionProvider - */ + #[DataProvider('versionProvider')] public function testVersionRegx(string $version, string $matched): void { $result = preg_match(SdkVersion::VERSION_REGX, $version, $matches); @@ -20,7 +19,7 @@ public function testVersionRegx(string $version, string $matched): void } } - public function versionProvider(): iterable + public static function versionProvider(): iterable { return [ ['1.2.3.0', '1.2.3'], diff --git a/tests/Unit/DTO/DTOMarshallingTestCase.php b/tests/Unit/DTO/AbstractDTOMarshalling.php similarity index 94% rename from tests/Unit/DTO/DTOMarshallingTestCase.php rename to tests/Unit/DTO/AbstractDTOMarshalling.php index 71a8900a..17a75b0c 100644 --- a/tests/Unit/DTO/DTOMarshallingTestCase.php +++ b/tests/Unit/DTO/AbstractDTOMarshalling.php @@ -17,7 +17,7 @@ use Temporal\Internal\Marshaller\MarshallerInterface; use Temporal\Internal\Marshaller\Type\DetectableTypeInterface; use Temporal\Internal\Marshaller\TypeFactory; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit @@ -25,7 +25,7 @@ * * @psalm-import-type CallableTypeMatcher from TypeFactory */ -abstract class DTOMarshallingTestCase extends UnitTestCase +abstract class AbstractDTOMarshalling extends AbstractUnit { /** * @var MarshallerInterface diff --git a/tests/Unit/DTO/ActivityInfoTestCase.php b/tests/Unit/DTO/ActivityInfoTestCase.php index 0cbac50a..e6f53d54 100644 --- a/tests/Unit/DTO/ActivityInfoTestCase.php +++ b/tests/Unit/DTO/ActivityInfoTestCase.php @@ -13,7 +13,7 @@ use Temporal\Activity\ActivityInfo; -class ActivityInfoTestCase extends DTOMarshallingTestCase +class ActivityInfoTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/ActivityOptionsTestCase.php b/tests/Unit/DTO/ActivityOptionsTestCase.php index 50662d43..d4e18f4d 100644 --- a/tests/Unit/DTO/ActivityOptionsTestCase.php +++ b/tests/Unit/DTO/ActivityOptionsTestCase.php @@ -17,7 +17,7 @@ use Temporal\Common\RetryOptions; use Temporal\Common\Uuid; -class ActivityOptionsTestCase extends DTOMarshallingTestCase +class ActivityOptionsTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/ActivityTypeTestCase.php b/tests/Unit/DTO/ActivityTypeTestCase.php index 1e0dffe3..e327cc36 100644 --- a/tests/Unit/DTO/ActivityTypeTestCase.php +++ b/tests/Unit/DTO/ActivityTypeTestCase.php @@ -13,7 +13,7 @@ use Temporal\Activity\ActivityType; -class ActivityTypeTestCase extends DTOMarshallingTestCase +class ActivityTypeTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/ChildWorkflowOptionsTestCase.php b/tests/Unit/DTO/ChildWorkflowOptionsTestCase.php index a5efc346..c1bca67f 100644 --- a/tests/Unit/DTO/ChildWorkflowOptionsTestCase.php +++ b/tests/Unit/DTO/ChildWorkflowOptionsTestCase.php @@ -14,7 +14,7 @@ use Temporal\Common\IdReusePolicy; use Temporal\Workflow\ChildWorkflowOptions; -class ChildWorkflowOptionsTestCase extends DTOMarshallingTestCase +class ChildWorkflowOptionsTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/ClientOptionsTestCase.php b/tests/Unit/DTO/ClientOptionsTestCase.php index 155d1f41..f9a66b1a 100644 --- a/tests/Unit/DTO/ClientOptionsTestCase.php +++ b/tests/Unit/DTO/ClientOptionsTestCase.php @@ -15,7 +15,7 @@ use Temporal\Client\ClientOptions; use Temporal\Common\Uuid; -class ClientOptionsTestCase extends DTOMarshallingTestCase +class ClientOptionsTestCase extends AbstractDTOMarshalling { public function testNamespaceChangesNotMutateState(): void { diff --git a/tests/Unit/DTO/ContinueAsNewOptionsTestCase.php b/tests/Unit/DTO/ContinueAsNewOptionsTestCase.php index 91d0a361..44a945c9 100644 --- a/tests/Unit/DTO/ContinueAsNewOptionsTestCase.php +++ b/tests/Unit/DTO/ContinueAsNewOptionsTestCase.php @@ -13,7 +13,7 @@ use Temporal\Workflow\ContinueAsNewOptions; -class ContinueAsNewOptionsTestCase extends DTOMarshallingTestCase +class ContinueAsNewOptionsTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/Readonly/ReadonlyPropertiesTestCase.php b/tests/Unit/DTO/Readonly/ReadonlyPropertiesTestCase.php index 7b31de58..5a2e3734 100644 --- a/tests/Unit/DTO/Readonly/ReadonlyPropertiesTestCase.php +++ b/tests/Unit/DTO/Readonly/ReadonlyPropertiesTestCase.php @@ -12,9 +12,9 @@ namespace Temporal\Tests\Unit\DTO\Readonly; use Temporal\DataConverter\DataConverter; -use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; +use Temporal\Tests\Unit\DTO\AbstractDTOMarshalling; -class ReadonlyPropertiesTestCase extends DTOMarshallingTestCase +class ReadonlyPropertiesTestCase extends AbstractDTOMarshalling { public function testMarshalling(): void { diff --git a/tests/Unit/DTO/RetryOptionsTestCase.php b/tests/Unit/DTO/RetryOptionsTestCase.php index f4fa4547..1b7ccb14 100644 --- a/tests/Unit/DTO/RetryOptionsTestCase.php +++ b/tests/Unit/DTO/RetryOptionsTestCase.php @@ -13,7 +13,7 @@ use Temporal\Common\RetryOptions; -class RetryOptionsTestCase extends DTOMarshallingTestCase +class RetryOptionsTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/Type/ArrayType/ArrayTestCase.php b/tests/Unit/DTO/Type/ArrayType/ArrayTestCase.php index a1d7c31c..af02d3ee 100644 --- a/tests/Unit/DTO/Type/ArrayType/ArrayTestCase.php +++ b/tests/Unit/DTO/Type/ArrayType/ArrayTestCase.php @@ -12,9 +12,9 @@ namespace Temporal\Tests\Unit\DTO\Type\ArrayType; use Temporal\Internal\Marshaller\Type\ArrayType; -use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; +use Temporal\Tests\Unit\DTO\AbstractDTOMarshalling; -class ArrayTestCase extends DTOMarshallingTestCase +class ArrayTestCase extends AbstractDTOMarshalling { public function testMarshalling(): void { diff --git a/tests/Unit/DTO/Type/DateIntervalType/DateIntervalTestCase.php b/tests/Unit/DTO/Type/DateIntervalType/DateIntervalTestCase.php index 15aa2f53..b6fbcad4 100644 --- a/tests/Unit/DTO/Type/DateIntervalType/DateIntervalTestCase.php +++ b/tests/Unit/DTO/Type/DateIntervalType/DateIntervalTestCase.php @@ -13,10 +13,10 @@ use DateInterval; use Temporal\Internal\Marshaller\Type\DateIntervalType; -use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; +use Temporal\Tests\Unit\DTO\AbstractDTOMarshalling; use Temporal\Tests\Unit\DTO\Type\DateIntervalType\Stub\DateIntervalDto; -class DateIntervalTestCase extends DTOMarshallingTestCase +class DateIntervalTestCase extends AbstractDTOMarshalling { public function testMarshalAndUnmarshalWithoutAttribute(): void { diff --git a/tests/Unit/DTO/Type/DateTimeType/DateTimeTestCase.php b/tests/Unit/DTO/Type/DateTimeType/DateTimeTestCase.php index ea2d02a1..fa8a65c8 100644 --- a/tests/Unit/DTO/Type/DateTimeType/DateTimeTestCase.php +++ b/tests/Unit/DTO/Type/DateTimeType/DateTimeTestCase.php @@ -16,10 +16,10 @@ use DateTime; use DateTimeImmutable; use Temporal\Internal\Marshaller\Type\DateTimeType; -use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; +use Temporal\Tests\Unit\DTO\AbstractDTOMarshalling; use Temporal\Tests\Unit\DTO\Type\DateTimeType\Stub\DateTimeDto; -class DateTimeTestCase extends DTOMarshallingTestCase +class DateTimeTestCase extends AbstractDTOMarshalling { public function testMarshal(): void { diff --git a/tests/Unit/DTO/Type/EnumType/EnumTestCase.php b/tests/Unit/DTO/Type/EnumType/EnumTestCase.php index b746bbc5..b0c9bd5b 100644 --- a/tests/Unit/DTO/Type/EnumType/EnumTestCase.php +++ b/tests/Unit/DTO/Type/EnumType/EnumTestCase.php @@ -13,12 +13,12 @@ use Error; use Temporal\Internal\Marshaller\Type\EnumType; -use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; +use Temporal\Tests\Unit\DTO\AbstractDTOMarshalling; use Temporal\Tests\Unit\DTO\Type\EnumType\Stub\EnumDto; use Temporal\Tests\Unit\DTO\Type\EnumType\Stub\ScalarEnum; use Temporal\Tests\Unit\DTO\Type\EnumType\Stub\SimpleEnum; -class EnumTestCase extends DTOMarshallingTestCase +class EnumTestCase extends AbstractDTOMarshalling { public function testMarshal(): void { diff --git a/tests/Unit/DTO/Type/ObjectType/ObjectTypeTestCase.php b/tests/Unit/DTO/Type/ObjectType/ObjectTypeTestCase.php index 5ff51be4..6f943f03 100644 --- a/tests/Unit/DTO/Type/ObjectType/ObjectTypeTestCase.php +++ b/tests/Unit/DTO/Type/ObjectType/ObjectTypeTestCase.php @@ -21,11 +21,11 @@ use Temporal\Tests\Unit\DTO\Type\ObjectType\Stub\NestedParent; use Temporal\Tests\Unit\DTO\Type\ObjectType\Stub\NullableProperty; use Temporal\Tests\Unit\DTO\Type\ObjectType\Stub\ParentDto; -use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; +use Temporal\Tests\Unit\DTO\AbstractDTOMarshalling; use Temporal\Tests\Unit\DTO\Type\ObjectType\Stub\ReadonlyProperty; use Temporal\Tests\Unit\DTO\Type\ObjectType\Stub\StdClassObjectProp; -final class ObjectTypeTestCase extends DTOMarshallingTestCase +final class ObjectTypeTestCase extends AbstractDTOMarshalling { public function testReflectionTypeMarshal(): void { diff --git a/tests/Unit/DTO/Type/UuidType/UuidTypeTestCase.php b/tests/Unit/DTO/Type/UuidType/UuidTypeTestCase.php index 59055fef..99f23d01 100644 --- a/tests/Unit/DTO/Type/UuidType/UuidTypeTestCase.php +++ b/tests/Unit/DTO/Type/UuidType/UuidTypeTestCase.php @@ -4,21 +4,20 @@ namespace Temporal\Tests\Unit\DTO\Type\UuidType; +use PHPUnit\Framework\Attributes\DataProvider; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; use ReflectionClass; use Temporal\Internal\Marshaller\MarshallingRule; use Temporal\Internal\Marshaller\Type\NullableType; use Temporal\Internal\Marshaller\Type\UuidType; -use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; +use Temporal\Tests\Unit\DTO\AbstractDTOMarshalling; use Temporal\Tests\Unit\DTO\Type\UuidType\Stub\UuidObjectProp; use Temporal\Tests\Unit\Internal\Marshaller\Fixture\PropertyType; -final class UuidTypeTestCase extends DTOMarshallingTestCase +final class UuidTypeTestCase extends AbstractDTOMarshalling { - /** - * @dataProvider matchDataProvider - */ + #[DataProvider('matchDataProvider')] public function testMatch(string $property, bool $expected): void { $this->assertSame( @@ -27,9 +26,7 @@ public function testMatch(string $property, bool $expected): void ); } - /** - * @dataProvider makeRuleDataProvider - */ + #[DataProvider('makeRuleDataProvider')] public function testMakeRule(string $property, mixed $expected): void { $this->assertEquals( diff --git a/tests/Unit/DTO/WorkerOptionsTestCase.php b/tests/Unit/DTO/WorkerOptionsTestCase.php index 8bc4b434..9fe27627 100644 --- a/tests/Unit/DTO/WorkerOptionsTestCase.php +++ b/tests/Unit/DTO/WorkerOptionsTestCase.php @@ -13,7 +13,7 @@ use Temporal\Worker\WorkerOptions; -class WorkerOptionsTestCase extends DTOMarshallingTestCase +class WorkerOptionsTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/WorkflowExecutionTestCase.php b/tests/Unit/DTO/WorkflowExecutionTestCase.php index 6e976561..66bb1f2d 100644 --- a/tests/Unit/DTO/WorkflowExecutionTestCase.php +++ b/tests/Unit/DTO/WorkflowExecutionTestCase.php @@ -15,7 +15,7 @@ use Temporal\Internal\Marshaller\ProtoToArrayConverter; use Temporal\Workflow\WorkflowExecution; -class WorkflowExecutionTestCase extends DTOMarshallingTestCase +class WorkflowExecutionTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/WorkflowInfoTestCase.php b/tests/Unit/DTO/WorkflowInfoTestCase.php index 50b2ca4d..61889f14 100644 --- a/tests/Unit/DTO/WorkflowInfoTestCase.php +++ b/tests/Unit/DTO/WorkflowInfoTestCase.php @@ -13,7 +13,7 @@ use Temporal\Workflow\WorkflowInfo; -class WorkflowInfoTestCase extends DTOMarshallingTestCase +class WorkflowInfoTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/WorkflowOptionsTestCase.php b/tests/Unit/DTO/WorkflowOptionsTestCase.php index 52abf2a8..820ed966 100644 --- a/tests/Unit/DTO/WorkflowOptionsTestCase.php +++ b/tests/Unit/DTO/WorkflowOptionsTestCase.php @@ -20,7 +20,7 @@ use Temporal\Common\Uuid; use Temporal\DataConverter\DataConverter; -class WorkflowOptionsTestCase extends DTOMarshallingTestCase +class WorkflowOptionsTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DTO/WorkflowTypeTestCase.php b/tests/Unit/DTO/WorkflowTypeTestCase.php index c69fdda6..241f3d73 100644 --- a/tests/Unit/DTO/WorkflowTypeTestCase.php +++ b/tests/Unit/DTO/WorkflowTypeTestCase.php @@ -13,7 +13,7 @@ use Temporal\Workflow\WorkflowType; -class WorkflowTypeTestCase extends DTOMarshallingTestCase +class WorkflowTypeTestCase extends AbstractDTOMarshalling { /** * @throws \ReflectionException diff --git a/tests/Unit/DataConverter/DataConverterTestCase.php b/tests/Unit/DataConverter/DataConverterTestCase.php index 032a7ee4..e857589e 100644 --- a/tests/Unit/DataConverter/DataConverterTestCase.php +++ b/tests/Unit/DataConverter/DataConverterTestCase.php @@ -11,22 +11,23 @@ namespace Temporal\Tests\Unit\DataConverter; +use PHPUnit\Framework\Attributes\DataProvider; use Temporal\DataConverter\DataConverter; use Temporal\DataConverter\DataConverterInterface; use Temporal\DataConverter\Type; use Temporal\Exception\DataConverterException; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit * @group data-converter */ -class DataConverterTestCase extends UnitTestCase +class DataConverterTestCase extends AbstractUnit { /** * @return array[] */ - public function typesDataProvider(): array + public static function typesDataProvider(): array { return [ // Any @@ -59,7 +60,7 @@ public function typesDataProvider(): array /** * @return array */ - public function negativeTypesDataProvider(): array + public static function negativeTypesDataProvider(): array { return [ Type::TYPE_OBJECT . ' => ' . Type::TYPE_STRING => [Type::TYPE_STRING, (object)['field' => 'value']], @@ -115,7 +116,7 @@ public function negativeTypesDataProvider(): array * @return array[] * @throws \Exception */ - public function nullableTypesDataProvider(): array + public static function nullableTypesDataProvider(): array { return [ Type::TYPE_ARRAY . ' => ' . Type::TYPE_VOID => [Type::TYPE_VOID, [1, 2, 3]], @@ -137,11 +138,10 @@ protected function create(): DataConverterInterface } /** - * @dataProvider typesDataProvider - * * @param string $type * @param mixed $value */ + #[DataProvider('typesDataProvider')] public function testPositiveConvert(string $type, $value): void { $converter = $this->create(); @@ -152,11 +152,10 @@ public function testPositiveConvert(string $type, $value): void } /** - * @dataProvider negativeTypesDataProvider - * * @param string $type * @param mixed $value */ + #[DataProvider('negativeTypesDataProvider')] public function testConvertErrors(string $type, $value): void { $this->expectException(DataConverterException::class); @@ -166,11 +165,10 @@ public function testConvertErrors(string $type, $value): void } /** - * @dataProvider nullableTypesDataProvider - * * @param string $type * @param mixed $value */ + #[DataProvider('nullableTypesDataProvider')] public function testNullableTypeCoercion(string $type, $value): void { $converter = $this->create(); diff --git a/tests/Unit/DataConverter/JsonConverterTestCase.php b/tests/Unit/DataConverter/JsonConverterTestCase.php index 663f00b0..6767ecb9 100644 --- a/tests/Unit/DataConverter/JsonConverterTestCase.php +++ b/tests/Unit/DataConverter/JsonConverterTestCase.php @@ -15,13 +15,13 @@ use Temporal\DataConverter\JsonConverter; use Temporal\DataConverter\PayloadConverterInterface; use Temporal\DataConverter\Type; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit * @group data-converter */ -class JsonConverterTestCase extends UnitTestCase +class JsonConverterTestCase extends AbstractUnit { protected function create(): PayloadConverterInterface { diff --git a/tests/Unit/DataConverter/ProtoConverterTestCase.php b/tests/Unit/DataConverter/ProtoConverterTestCase.php index e51a5c29..7da5a0d1 100644 --- a/tests/Unit/DataConverter/ProtoConverterTestCase.php +++ b/tests/Unit/DataConverter/ProtoConverterTestCase.php @@ -14,13 +14,13 @@ use Temporal\DataConverter\EncodingKeys; use Temporal\DataConverter\PayloadConverterInterface; use Temporal\DataConverter\ProtoConverter; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit * @group data-converter */ -class ProtoConverterTestCase extends UnitTestCase +class ProtoConverterTestCase extends AbstractUnit { protected function create(): PayloadConverterInterface { diff --git a/tests/Unit/DataConverter/ProtoJsonConverterTestCase.php b/tests/Unit/DataConverter/ProtoJsonConverterTestCase.php index 6f560c92..b9fd7b32 100644 --- a/tests/Unit/DataConverter/ProtoJsonConverterTestCase.php +++ b/tests/Unit/DataConverter/ProtoJsonConverterTestCase.php @@ -14,13 +14,13 @@ use Temporal\DataConverter\EncodingKeys; use Temporal\DataConverter\PayloadConverterInterface; use Temporal\DataConverter\ProtoJsonConverter; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit * @group data-converter */ -class ProtoJsonConverterTestCase extends UnitTestCase +class ProtoJsonConverterTestCase extends AbstractUnit { protected function create(): PayloadConverterInterface { diff --git a/tests/Unit/Declaration/DeclarationTestCase.php b/tests/Unit/Declaration/AbstractDeclaration.php similarity index 82% rename from tests/Unit/Declaration/DeclarationTestCase.php rename to tests/Unit/Declaration/AbstractDeclaration.php index 9f378426..4e7bc45e 100644 --- a/tests/Unit/Declaration/DeclarationTestCase.php +++ b/tests/Unit/Declaration/AbstractDeclaration.php @@ -15,18 +15,18 @@ use Spiral\Attributes\AttributeReader; use Temporal\Internal\Declaration\Reader\ActivityReader; use Temporal\Internal\Declaration\Reader\WorkflowReader; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit * @group declaration */ -abstract class DeclarationTestCase extends UnitTestCase +abstract class AbstractDeclaration extends AbstractUnit { /** * @return WorkflowReader[][] */ - public function workflowReaderDataProvider(): array + public static function workflowReaderDataProvider(): array { return [ AttributeReader::class => [new WorkflowReader(new AttributeReader())], @@ -37,7 +37,7 @@ public function workflowReaderDataProvider(): array /** * @return ActivityReader[][] */ - public function activityReaderDataProvider(): array + public static function activityReaderDataProvider(): array { return [ AttributeReader::class => [new ActivityReader(new AttributeReader())], diff --git a/tests/Unit/Declaration/ActivitiesNegativeDeclarationTestCase.php b/tests/Unit/Declaration/ActivitiesNegativeDeclarationTestCase.php index 4fb6a60c..b8cebe62 100644 --- a/tests/Unit/Declaration/ActivitiesNegativeDeclarationTestCase.php +++ b/tests/Unit/Declaration/ActivitiesNegativeDeclarationTestCase.php @@ -11,6 +11,8 @@ namespace Temporal\Tests\Unit\Declaration; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestDox; use Temporal\Internal\Declaration\Reader\ActivityReader; use Temporal\Tests\Unit\Declaration\Fixture\ActivityNamesDuplication; use Temporal\Tests\Unit\Declaration\Fixture\ActivityWithPrivateMethod; @@ -21,15 +23,14 @@ * @group unit * @group declaration */ -class ActivitiesNegativeDeclarationTestCase extends DeclarationTestCase +class ActivitiesNegativeDeclarationTestCase extends AbstractDeclaration { /** - * @testdox Checks for errors when reading activity class methods with the same name - * @dataProvider activityReaderDataProvider - * * @param ActivityReader $reader * @throws \ReflectionException */ + #[TestDox("Checks for errors when reading activity class methods with the same name")] + #[DataProvider('activityReaderDataProvider')] public function testNameConflict(ActivityReader $reader): void { $reflection = new \ReflectionMethod(ActivityNamesDuplication::class, 'a'); @@ -49,12 +50,11 @@ public function testNameConflict(ActivityReader $reader): void } /** - * @testdox Checks for errors when declaring a private method with an activity method attribute declaration - * @dataProvider activityReaderDataProvider - * * @param ActivityReader $reader * @throws \ReflectionException */ + #[TestDox("Checks for errors when declaring a private method with an activity method attribute declaration")] + #[DataProvider('activityReaderDataProvider')] public function testPrivateMethod(ActivityReader $reader): void { $this->expectException(\LogicException::class); @@ -70,12 +70,11 @@ public function testPrivateMethod(ActivityReader $reader): void } /** - * @testdox Checks for errors when declaring a protected method with an activity method attribute declaration - * @dataProvider activityReaderDataProvider - * * @param ActivityReader $reader * @throws \ReflectionException */ + #[TestDox("Checks for errors when declaring a protected method with an activity method attribute declaration")] + #[DataProvider('activityReaderDataProvider')] public function testProtectedMethod(ActivityReader $reader): void { $this->expectException(\LogicException::class); @@ -91,12 +90,11 @@ public function testProtectedMethod(ActivityReader $reader): void } /** - * @testdox Checks for errors when declaring a public static method with an activity method attribute declaration - * @dataProvider activityReaderDataProvider - * * @param ActivityReader $reader * @throws \ReflectionException */ + #[TestDox("Checks for errors when declaring a public static method with an activity method attribute declaration")] + #[DataProvider('activityReaderDataProvider')] public function testPublicStaticMethod(ActivityReader $reader): void { $this->expectException(\LogicException::class); diff --git a/tests/Unit/Declaration/ActivityDeclarationTestCase.php b/tests/Unit/Declaration/ActivityDeclarationTestCase.php index e5d82e14..2256c170 100644 --- a/tests/Unit/Declaration/ActivityDeclarationTestCase.php +++ b/tests/Unit/Declaration/ActivityDeclarationTestCase.php @@ -11,6 +11,8 @@ namespace Temporal\Tests\Unit\Declaration; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestDox; use Temporal\Internal\Declaration\Prototype\ActivityPrototype; use Temporal\Internal\Declaration\Reader\ActivityReader; use Temporal\Tests\Unit\Declaration\Fixture\ActivitiesWithPublicMethods; @@ -20,7 +22,7 @@ * @group unit * @group declaration */ -class ActivityDeclarationTestCase extends DeclarationTestCase +class ActivityDeclarationTestCase extends AbstractDeclaration { /** * @param array $prototypes @@ -32,12 +34,11 @@ private function arrayToActivityNames(array $prototypes): array } /** - * @testdox Reading activities (should return activity prototypes for all non-static public methods) - * @dataProvider activityReaderDataProvider - * * @param ActivityReader $reader * @throws \ReflectionException */ + #[TestDox("Reading activities (should return activity prototypes for all non-static public methods)")] + #[DataProvider('activityReaderDataProvider')] public function testActivitiesFromPublicNonStaticMethods(ActivityReader $reader): void { $prototypes = $reader->fromClass(ActivitiesWithPublicMethods::class); @@ -48,12 +49,11 @@ public function testActivitiesFromPublicNonStaticMethods(ActivityReader $reader) } /** - * @testdox - * @dataProvider activityReaderDataProvider - * * @param ActivityReader $reader * @throws \ReflectionException */ + #[TestDox('')] + #[DataProvider('activityReaderDataProvider')] public function testInheritedActivities(ActivityReader $reader): void { $prototypes = $reader->fromClass(ChildActivityMethods::class); diff --git a/tests/Unit/Declaration/WorkflowDeclarationTestCase.php b/tests/Unit/Declaration/WorkflowDeclarationTestCase.php index bdf423cb..3a4b2f1d 100644 --- a/tests/Unit/Declaration/WorkflowDeclarationTestCase.php +++ b/tests/Unit/Declaration/WorkflowDeclarationTestCase.php @@ -12,6 +12,8 @@ namespace Temporal\Tests\Unit\Declaration; use Carbon\CarbonInterval; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestDox; use Temporal\Common\CronSchedule; use Temporal\Internal\Declaration\Reader\WorkflowReader; use Temporal\Tests\Unit\Declaration\Fixture\SimpleWorkflow; @@ -28,15 +30,14 @@ * @group unit * @group declaration */ -class WorkflowDeclarationTestCase extends DeclarationTestCase +class WorkflowDeclarationTestCase extends AbstractDeclaration { /** - * @testdox Reading workflow without handler - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow without handler")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithoutHandler(WorkflowReader $reader): void { $prototype = $reader->fromClass(WorkflowWithoutHandler::class); @@ -45,12 +46,11 @@ public function testWorkflowWithoutHandler(WorkflowReader $reader): void } /** - * @testdox Reading workflow without cron attribute (cron prototype value should be null) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow without cron attribute (cron prototype value should be null)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithoutCron(WorkflowReader $reader): void { $prototype = $reader->fromClass(SimpleWorkflow::class); @@ -59,12 +59,11 @@ public function testWorkflowWithoutCron(WorkflowReader $reader): void } /** - * @testdox Reading workflow with cron attribute (cron prototype value should not be null) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow with cron attribute (cron prototype value should not be null)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithCron(WorkflowReader $reader): void { $prototype = $reader->fromClass(WorkflowWithCron::class); @@ -74,12 +73,11 @@ public function testWorkflowWithCron(WorkflowReader $reader): void } /** - * @testdox Reading workflow without method retry attribute (method retry prototype value should be null) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow without method retry attribute (method retry prototype value should be null)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithoutRetry(WorkflowReader $reader): void { $prototype = $reader->fromClass(SimpleWorkflow::class); @@ -88,12 +86,11 @@ public function testWorkflowWithoutRetry(WorkflowReader $reader): void } /** - * @testdox Reading workflow with method retry attribute (method retry prototype value should not be null) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow with method retry attribute (method retry prototype value should not be null)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithRetry(WorkflowReader $reader): void { $prototype = $reader->fromClass(WorkflowWithRetry::class); @@ -105,12 +102,11 @@ public function testWorkflowWithRetry(WorkflowReader $reader): void } /** - * @testdox Reading workflow with method retry and cron attributes (prototypes value should not be null) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow with method retry and cron attributes (prototypes value should not be null)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithCronAndRetry(WorkflowReader $reader): void { $prototype = $reader->fromClass(WorkflowWithCronAndRetry::class); @@ -125,12 +121,11 @@ public function testWorkflowWithCronAndRetry(WorkflowReader $reader): void } /** - * @testdox Reading workflow without query methods (query methods count equals 0) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow without query methods (query methods count equals 0)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithoutQueries(WorkflowReader $reader): void { $prototype = $reader->fromClass(SimpleWorkflow::class); @@ -139,12 +134,11 @@ public function testWorkflowWithoutQueries(WorkflowReader $reader): void } /** - * @testdox Reading workflow with query methods (query methods count not equals 0) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow with query methods (query methods count not equals 0)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithQueries(WorkflowReader $reader): void { $prototype = $reader->fromClass(WorkflowWithQueries::class); @@ -154,12 +148,11 @@ public function testWorkflowWithQueries(WorkflowReader $reader): void } /** - * @testdox Reading workflow without signal methods (signal methods count equals 0) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow without signal methods (signal methods count equals 0)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithoutSignals(WorkflowReader $reader): void { $prototype = $reader->fromClass(SimpleWorkflow::class); @@ -168,12 +161,11 @@ public function testWorkflowWithoutSignals(WorkflowReader $reader): void } /** - * @testdox Reading workflow with signal methods (signal methods count not equals 0) - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Reading workflow with signal methods (signal methods count not equals 0)")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithSignals(WorkflowReader $reader): void { $prototype = $reader->fromClass(WorkflowWithSignals::class); @@ -184,12 +176,11 @@ public function testWorkflowWithSignals(WorkflowReader $reader): void } /** - * @testdox Workflow should be named same as method name - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Workflow should be named same as method name")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowHandlerDefaultNaming(WorkflowReader $reader): void { $withoutName = $reader->fromClass(SimpleWorkflow::class); @@ -198,12 +189,11 @@ public function testWorkflowHandlerDefaultNaming(WorkflowReader $reader): void } /** - * @testdox Workflow should be named same as the name specified in the workflow method attribute - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Workflow should be named same as the name specified in the workflow method attribute")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowHandlerWithName(WorkflowReader $reader): void { $prototype = $reader->fromClass(WorkflowWithCustomName::class); diff --git a/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php b/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php index 95ef67f3..c96e627b 100644 --- a/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php +++ b/tests/Unit/Declaration/WorkflowNegativeDeclarationTestCase.php @@ -11,6 +11,8 @@ namespace Temporal\Tests\Unit\Declaration; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestDox; use Temporal\Exception\InstantiationException; use Temporal\Internal\Declaration\Instantiator\WorkflowInstantiator; use Temporal\Internal\Declaration\Reader\WorkflowReader; @@ -25,15 +27,14 @@ * @group unit * @group declaration */ -class WorkflowNegativeDeclarationTestCase extends DeclarationTestCase +class WorkflowNegativeDeclarationTestCase extends AbstractDeclaration { /** - * @testdox Validate errors while loading workflow without WorkflowInterface attribute - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Validate errors while loading workflow without WorkflowInterface attribute")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithoutInterfaceAttribute(WorkflowReader $reader): void { $this->expectException(\LogicException::class); @@ -49,12 +50,11 @@ public function testWorkflowWithoutInterfaceAttribute(WorkflowReader $reader): v } /** - * @testdox Workflow handlers duplication - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Workflow handlers duplication")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowMethodDuplication(WorkflowReader $reader): void { $this->expectException(\LogicException::class); @@ -63,12 +63,11 @@ public function testWorkflowMethodDuplication(WorkflowReader $reader): void } /** - * @testdox Workflow without handler instantiation - * @dataProvider workflowReaderDataProvider - * * @param WorkflowReader $reader * @throws \ReflectionException */ + #[TestDox("Workflow without handler instantiation")] + #[DataProvider('workflowReaderDataProvider')] public function testWorkflowWithoutHandlerInstantiation(WorkflowReader $reader): void { $this->expectException(InstantiationException::class); diff --git a/tests/Unit/Exception/FailureConverterTestCase.php b/tests/Unit/Exception/FailureConverterTestCase.php index 3c8acb70..8aa2a0a1 100644 --- a/tests/Unit/Exception/FailureConverterTestCase.php +++ b/tests/Unit/Exception/FailureConverterTestCase.php @@ -8,9 +8,9 @@ use Temporal\DataConverter\EncodedValues; use Temporal\Exception\Failure\ApplicationFailure; use Temporal\Exception\Failure\FailureConverter; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; -final class FailureConverterTestCase extends UnitTestCase +final class FailureConverterTestCase extends AbstractUnit { public function testApplicationFailureCanTransferData(): void { diff --git a/tests/Unit/Framework/WorkerMock.php b/tests/Unit/Framework/WorkerMock.php index cd6de11b..586740d7 100644 --- a/tests/Unit/Framework/WorkerMock.php +++ b/tests/Unit/Framework/WorkerMock.php @@ -66,7 +66,7 @@ private function createRouter(): RouterInterface $router = new Router(); $router->add(new Router\StartWorkflow($this->services)); $router->add(new Router\InvokeActivity($this->services, Goridge::create(), $this->interceptorProvider)); - $router->add(new Router\DestroyWorkflow($this->services->running)); + $router->add(new Router\DestroyWorkflow($this->services->running, $this->services->loop)); $router->add(new Router\InvokeSignal($this->services->running)); return $router; diff --git a/tests/Unit/Framework/WorkerTestCase.php b/tests/Unit/Framework/WorkerTestCase.php index 9d4b1648..63e2e51f 100644 --- a/tests/Unit/Framework/WorkerTestCase.php +++ b/tests/Unit/Framework/WorkerTestCase.php @@ -4,8 +4,7 @@ namespace Temporal\Tests\Unit\Framework; -use Temporal\Tests\Unit\UnitTestCase; -use Temporal\Tests\Workflow\SimpleWorkflow; +use Temporal\Tests\Unit\AbstractUnit; use Temporal\Worker\WorkerFactoryInterface; use Temporal\Worker\WorkerInterface; use Temporal\Workflow; @@ -16,7 +15,7 @@ /** * @internal */ -final class WorkerTestCase extends UnitTestCase +final class WorkerTestCase extends AbstractUnit { private WorkerFactoryInterface $factory; /** @var WorkerMock|WorkerInterface */ diff --git a/tests/Unit/Interceptor/HeaderTestCase.php b/tests/Unit/Interceptor/HeaderTestCase.php index 882a7348..cdbdac22 100644 --- a/tests/Unit/Interceptor/HeaderTestCase.php +++ b/tests/Unit/Interceptor/HeaderTestCase.php @@ -11,16 +11,17 @@ namespace Temporal\Tests\Unit\Interceptor; +use PHPUnit\Framework\Attributes\DataProvider; use Temporal\DataConverter\DataConverter; use Temporal\DataConverter\DataConverterInterface; use Temporal\Interceptor\Header; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit * @group interceptor */ -class HeaderTestCase extends UnitTestCase +class HeaderTestCase extends AbstractUnit { public function testToHeaderFromValuesWithoutConverterException(): void { @@ -62,9 +63,7 @@ public function testWithValueImmutability(): void $this->assertNotSame($collection, $source); } - /** - * @dataProvider fromValuesProvider() - */ + #[DataProvider('fromValuesProvider')] public function testFromValues(array $input, array $output): void { $collection = Header::fromValues($input); @@ -131,7 +130,7 @@ public function testHeaderFromValuesToProtoPackable(): void $this->assertSame('bar', $converter->fromPayload($collection->offsetGet('foo'), null)); } - public function fromValuesProvider(): iterable + public static function fromValuesProvider(): iterable { yield [ ['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'], diff --git a/tests/Unit/Internal/Client/WorkflowStarterTestCase.php b/tests/Unit/Internal/Client/WorkflowStarterTestCase.php index 734bdcd9..a5f689cf 100644 --- a/tests/Unit/Internal/Client/WorkflowStarterTestCase.php +++ b/tests/Unit/Internal/Client/WorkflowStarterTestCase.php @@ -4,6 +4,7 @@ namespace Temporal\Tests\Unit\Internal\Client; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Api\Workflowservice\V1\StartWorkflowExecutionRequest; use Temporal\Api\Workflowservice\V1\StartWorkflowExecutionResponse; @@ -17,8 +18,8 @@ /** * @internal * - * @covers \Temporal\Internal\Client\WorkflowStub */ +#[CoversClass(\Temporal\Internal\Client\WorkflowStub::class)] final class WorkflowStarterTestCase extends TestCase { private const NAMESPACE = 'test-namespace'; diff --git a/tests/Unit/Internal/Client/WorkflowStubTestCase.php b/tests/Unit/Internal/Client/WorkflowStubTestCase.php index aa398d76..a7ea75c9 100644 --- a/tests/Unit/Internal/Client/WorkflowStubTestCase.php +++ b/tests/Unit/Internal/Client/WorkflowStubTestCase.php @@ -4,6 +4,7 @@ namespace Temporal\Tests\Unit\Internal\Client; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Temporal\Api\Common\V1\Payload; @@ -27,9 +28,8 @@ /** * @internal - * - * @covers \Temporal\Internal\Client\WorkflowStub */ +#[CoversClass(\Temporal\Internal\Client\WorkflowStub::class)] final class WorkflowStubTestCase extends TestCase { private WorkflowStub $workflowStub; diff --git a/tests/Unit/Internal/Marshaller/MarshallerTestCase.php b/tests/Unit/Internal/Marshaller/MarshallerTestCase.php index 429615d3..43600aa0 100644 --- a/tests/Unit/Internal/Marshaller/MarshallerTestCase.php +++ b/tests/Unit/Internal/Marshaller/MarshallerTestCase.php @@ -4,6 +4,7 @@ namespace Temporal\Tests\Unit\Internal\Marshaller; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Ramsey\Uuid\Rfc4122\UuidV4; use Spiral\Attributes\AttributeReader; @@ -16,9 +17,8 @@ /** * @internal - * - * @covers \Temporal\Internal\Marshaller\Marshaller */ +#[CoversClass(\Temporal\Internal\Marshaller\Marshaller::class)] final class MarshallerTestCase extends TestCase { public function testNestedNullableObjectWasSerialized(): void diff --git a/tests/Unit/Internal/Support/GarbageCollectorTestCase.php b/tests/Unit/Internal/Support/GarbageCollectorTestCase.php new file mode 100644 index 00000000..2e69ffda --- /dev/null +++ b/tests/Unit/Internal/Support/GarbageCollectorTestCase.php @@ -0,0 +1,67 @@ +assertFalse($gc->check()); + } + + $this->assertSame($result, $gc->check()); + } + + public function testCheckOverticked(): void + { + $gc = new GarbageCollector(5, 3600); + + $this->assertFalse($gc->check()); + $this->assertFalse($gc->check()); + $this->assertFalse($gc->check()); + $this->assertFalse($gc->check()); + $this->assertTrue($gc->check()); + $this->assertTrue($gc->check()); + $this->assertTrue($gc->check()); + $this->assertTrue($gc->check()); + } + + public function testCheckTimeout(): void + { + $gc = new GarbageCollector(100, 2); + + $this->assertFalse($gc->check()); + } + + public function testCheckTriggerTimeout(): void + { + $gc = new GarbageCollector(100, 1, \time() - 2); + + $this->assertTrue($gc->check()); + } + + public static function provideCheck(): iterable + { + yield [1, 1, true]; + yield [2, 1, false]; + yield [3, 2, false]; + yield [10, 9, false]; + yield [10, 10, true]; + } +} diff --git a/tests/Unit/Protocol/ProtocolTestCase.php b/tests/Unit/Protocol/AbstractProtocol.php similarity index 76% rename from tests/Unit/Protocol/ProtocolTestCase.php rename to tests/Unit/Protocol/AbstractProtocol.php index 780af440..5dd14bd8 100644 --- a/tests/Unit/Protocol/ProtocolTestCase.php +++ b/tests/Unit/Protocol/AbstractProtocol.php @@ -11,12 +11,12 @@ namespace Temporal\Tests\Unit\Protocol; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group unit * @group protocol */ -abstract class ProtocolTestCase extends UnitTestCase +abstract class AbstractProtocol extends AbstractUnit { } diff --git a/tests/Unit/Protocol/DecodingCommandsTestCase.php b/tests/Unit/Protocol/DecodingCommandsTestCase.php index 8a9313ca..58006986 100644 --- a/tests/Unit/Protocol/DecodingCommandsTestCase.php +++ b/tests/Unit/Protocol/DecodingCommandsTestCase.php @@ -11,13 +11,15 @@ namespace Temporal\Tests\Unit\Protocol; +use PHPUnit\Framework\Attributes\Test; + /** * @group unit * @group protocol */ -class DecodingCommandsTestCase extends ProtocolTestCase +class DecodingCommandsTestCase extends AbstractProtocol { - /** @test */ + #[Test] public function todo(): void { $this->expectNotToPerformAssertions(); diff --git a/tests/Unit/Protocol/DecodingHeadersTestCase.php b/tests/Unit/Protocol/DecodingHeadersTestCase.php index 31c56a32..e1bf286b 100644 --- a/tests/Unit/Protocol/DecodingHeadersTestCase.php +++ b/tests/Unit/Protocol/DecodingHeadersTestCase.php @@ -11,13 +11,15 @@ namespace Temporal\Tests\Unit\Protocol; +use PHPUnit\Framework\Attributes\Test; + /** * @group unit * @group protocol */ -class DecodingHeadersTestCase extends ProtocolTestCase +class DecodingHeadersTestCase extends AbstractProtocol { - /** @test */ + #[Test] public function todo(): void { $this->expectNotToPerformAssertions(); diff --git a/tests/Unit/Protocol/EncodingTestCase.php b/tests/Unit/Protocol/EncodingTestCase.php index f59b3894..edb9c3ee 100644 --- a/tests/Unit/Protocol/EncodingTestCase.php +++ b/tests/Unit/Protocol/EncodingTestCase.php @@ -11,6 +11,7 @@ namespace Temporal\Tests\Unit\Protocol; +use PHPUnit\Framework\Attributes\Test; use Temporal\DataConverter\DataConverter; use Temporal\DataConverter\EncodedValues; @@ -18,9 +19,9 @@ * @group unit * @group protocol */ -class EncodingTestCase extends ProtocolTestCase +class EncodingTestCase extends AbstractProtocol { - /** @test */ + #[Test] public function nullValuesAreReturned(): void { $encodedValues = EncodedValues::fromValues([null, 'something'], new DataConverter()); diff --git a/tests/Unit/Router/InvokeActivityTestCase.php b/tests/Unit/Router/InvokeActivityTestCase.php index 55fd1380..8bd1b8c5 100644 --- a/tests/Unit/Router/InvokeActivityTestCase.php +++ b/tests/Unit/Router/InvokeActivityTestCase.php @@ -23,12 +23,12 @@ use Temporal\Internal\Transport\ClientInterface; use Temporal\Internal\Transport\Router\InvokeActivity; use Temporal\Tests\Unit\Framework\Requests\InvokeActivity as Request; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; use Temporal\Worker\Environment\EnvironmentInterface; use Temporal\Worker\LoopInterface; use Temporal\Worker\Transport\RPCConnectionInterface; -final class InvokeActivityTestCase extends UnitTestCase +final class InvokeActivityTestCase extends AbstractUnit { private ServiceContainer $services; private InvokeActivity $router; diff --git a/tests/Unit/Router/StartWorkflowTestCase.php b/tests/Unit/Router/StartWorkflowTestCase.php index c78e5761..df068592 100644 --- a/tests/Unit/Router/StartWorkflowTestCase.php +++ b/tests/Unit/Router/StartWorkflowTestCase.php @@ -15,6 +15,7 @@ use Temporal\DataConverter\EncodedValues; use Temporal\Exception\ExceptionInterceptorInterface; use Temporal\Interceptor\SimplePipelineProvider; +use Temporal\Internal\Declaration\Destroyable; use Temporal\Internal\Declaration\Reader\WorkflowReader; use Temporal\Internal\Declaration\WorkflowInstanceInterface; use Temporal\Internal\Marshaller\MarshallerInterface; @@ -26,13 +27,13 @@ use Temporal\Internal\Workflow\Input; use Temporal\Internal\Workflow\WorkflowContext; use Temporal\Tests\Unit\Framework\Requests\StartWorkflow as Request; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; use Temporal\Worker\Environment\EnvironmentInterface; use Temporal\Worker\LoopInterface; use Temporal\Workflow\WorkflowExecution; use Temporal\Workflow\WorkflowInfo; -final class StartWorkflowTestCase extends UnitTestCase +final class StartWorkflowTestCase extends AbstractUnit { private ServiceContainer $services; private StartWorkflow $router; @@ -59,7 +60,7 @@ protected function setUp(): void $this->workflowContext = new WorkflowContext( $this->services, $this->services->client, - $this->createMock(WorkflowInstanceInterface::class), + $this->createMockForIntersectionOfInterfaces([WorkflowInstanceInterface::class, Destroyable::class]), new Input(), EncodedValues::empty() ); diff --git a/tests/Unit/Schedule/Action/StartWorkflowActionTestCase.php b/tests/Unit/Schedule/Action/StartWorkflowActionTestCase.php index 6245c2c1..d586b043 100644 --- a/tests/Unit/Schedule/Action/StartWorkflowActionTestCase.php +++ b/tests/Unit/Schedule/Action/StartWorkflowActionTestCase.php @@ -4,6 +4,8 @@ namespace Schedule\Action; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Action\StartWorkflowAction; use Temporal\Common\IdReusePolicy as WorkflowIdReusePolicy; @@ -12,9 +14,7 @@ use Temporal\DataConverter\EncodedValues; use Temporal\Workflow\WorkflowType; -/** - * @covers \Temporal\Client\Schedule\Action\StartWorkflowAction - */ +#[CoversClass(\Temporal\Client\Schedule\Action\StartWorkflowAction::class)] class StartWorkflowActionTestCase extends TestCase { public function testWithWorkflowTypeString(): void @@ -71,9 +71,7 @@ public function testWithTaskQueue(): void $this->assertSame('task-queue', $new->taskQueue->name); } - /** - * @dataProvider provideInput - */ + #[DataProvider('provideInput')] public function testWithInput(mixed $input, array $expect, mixed $initInput = null, array $initExpect = []): void { $init = StartWorkflowAction::new('TestWorkflow'); @@ -116,9 +114,7 @@ public static function provideTimeouts(): iterable ]; } - /** - * @dataProvider provideTimeouts - */ + #[DataProvider('provideTimeouts')] public function testWithWorkflowExecutionTimeout( mixed $timeout, string $expect, @@ -135,9 +131,7 @@ public function testWithWorkflowExecutionTimeout( $this->assertSame($expect, $new->workflowExecutionTimeout->format('%y/%m/%d/%h/%i/%s')); } - /** - * @dataProvider provideTimeouts - */ + #[DataProvider('provideTimeouts')] public function testWithWorkflowRunTimeout( mixed $timeout, string $expect, @@ -154,9 +148,7 @@ public function testWithWorkflowRunTimeout( $this->assertSame($expect, $new->workflowRunTimeout->format('%y/%m/%d/%h/%i/%s')); } - /** - * @dataProvider provideTimeouts - */ + #[DataProvider('provideTimeouts')] public function testWithWorkflowTaskTimeout( mixed $timeout, string $expect, @@ -215,9 +207,7 @@ public static function provideEncodedValues(): iterable yield 'clear' => [[], [], ['foo' => 'bar'], ['foo' => 'bar']]; } - /** - * @dataProvider provideEncodedValues - */ + #[DataProvider('provideEncodedValues')] public function testWithMemo(mixed $values, array $expect, mixed $initValues = null, array $initExpect = []): void { $init = StartWorkflowAction::new('TestWorkflow'); @@ -232,9 +222,7 @@ public function testWithMemo(mixed $values, array $expect, mixed $initValues = n $this->assertSame($expect, $new->memo->getValues()); } - /** - * @dataProvider provideEncodedValues - */ + #[DataProvider('provideEncodedValues')] public function testWithSearchAttributes(mixed $values, array $expect, mixed $initValues = null, array $initExpect = []): void { $init = StartWorkflowAction::new('TestWorkflow'); diff --git a/tests/Unit/Schedule/BackfillPeriodTestCase.php b/tests/Unit/Schedule/BackfillPeriodTestCase.php index 6525bc8c..1e7bbd80 100644 --- a/tests/Unit/Schedule/BackfillPeriodTestCase.php +++ b/tests/Unit/Schedule/BackfillPeriodTestCase.php @@ -4,13 +4,12 @@ namespace Temporal\Tests\Unit\Schedule; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\BackfillPeriod; use Temporal\Client\Schedule\Policy\ScheduleOverlapPolicy; -/** - * @covers \Temporal\Client\Schedule\BackfillPeriod - */ +#[CoversClass(\Temporal\Client\Schedule\BackfillPeriod::class)] class BackfillPeriodTestCase extends TestCase { public function testCreateFromDatetimeImmutable(): void diff --git a/tests/Unit/Schedule/Mapper/WorkflowExecutionInfoMapperTestCase.php b/tests/Unit/Schedule/Mapper/WorkflowExecutionInfoMapperTestCase.php index 8ffb0535..0937beac 100644 --- a/tests/Unit/Schedule/Mapper/WorkflowExecutionInfoMapperTestCase.php +++ b/tests/Unit/Schedule/Mapper/WorkflowExecutionInfoMapperTestCase.php @@ -4,6 +4,7 @@ namespace Temporal\Tests\Unit\Schedule\Mapper; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Spiral\Attributes\AttributeReader; use Temporal\Api\Enums\V1\ScheduleOverlapPolicy; @@ -19,9 +20,7 @@ use Temporal\Internal\Marshaller\Mapper\AttributeMapperFactory; use Temporal\Internal\Marshaller\Marshaller; -/** - * @covers \Temporal\Internal\Mapper\ScheduleMapper - */ +#[CoversClass(\Temporal\Internal\Mapper\ScheduleMapper::class)] final class WorkflowExecutionInfoMapperTestCase extends TestCase { private DataConverterInterface $dataConverter; diff --git a/tests/Unit/Schedule/ScheduleClientTestCase.php b/tests/Unit/Schedule/ScheduleClientTestCase.php index 527a1cfe..53d431d3 100644 --- a/tests/Unit/Schedule/ScheduleClientTestCase.php +++ b/tests/Unit/Schedule/ScheduleClientTestCase.php @@ -5,6 +5,7 @@ namespace Temporal\Tests\Unit\Schedule; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Spiral\Attributes\AttributeReader; use Temporal\Api\Workflowservice\V1\CreateScheduleRequest; @@ -31,9 +32,7 @@ use Temporal\Internal\Marshaller\Marshaller; use Temporal\Internal\Marshaller\ProtoToArrayConverter; -/** - * @covers \Temporal\Client\ScheduleClient - */ +#[CoversClass(\Temporal\Client\ScheduleClient::class)] class ScheduleClientTestCase extends TestCase { public function testCreateSchedule(): void diff --git a/tests/Unit/Schedule/ScheduleHandleTestCase.php b/tests/Unit/Schedule/ScheduleHandleTestCase.php index b966833b..75837e46 100644 --- a/tests/Unit/Schedule/ScheduleHandleTestCase.php +++ b/tests/Unit/Schedule/ScheduleHandleTestCase.php @@ -4,6 +4,7 @@ namespace Temporal\Tests\Unit\Schedule; +use PHPUnit\Framework\Attributes\CoversClass; use Spiral\Attributes\AttributeReader; use Temporal\Api\Schedule\V1\BackfillRequest; use Temporal\Api\Workflowservice\V1\DeleteScheduleRequest; @@ -31,9 +32,7 @@ use Temporal\Internal\Marshaller\MarshallerInterface; use Temporal\Internal\Marshaller\ProtoToArrayConverter; -/** - * @covers \Temporal\Client\Schedule\ScheduleHandle - */ +#[CoversClass(\Temporal\Client\Schedule\ScheduleHandle::class)] class ScheduleHandleTestCase extends TestCase { public function testGetId(): void diff --git a/tests/Unit/Schedule/ScheduleOptionsTestCase.php b/tests/Unit/Schedule/ScheduleOptionsTestCase.php index d5a88530..923e75f6 100644 --- a/tests/Unit/Schedule/ScheduleOptionsTestCase.php +++ b/tests/Unit/Schedule/ScheduleOptionsTestCase.php @@ -4,15 +4,15 @@ namespace Schedule; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\BackfillPeriod; use Temporal\Client\Schedule\Policy\ScheduleOverlapPolicy; use Temporal\Client\Schedule\ScheduleOptions; use Temporal\DataConverter\EncodedCollection; -/** - * @covers \Temporal\Client\Schedule\ScheduleOptions - */ +#[CoversClass(\Temporal\Client\Schedule\ScheduleOptions::class)] class ScheduleOptionsTestCase extends TestCase { public function testWithNamespace(): void @@ -91,9 +91,7 @@ public static function provideEncodedValues(): iterable yield 'clear' => [[], [], ['foo' => 'bar'], ['foo' => 'bar']]; } - /** - * @dataProvider provideEncodedValues - */ + #[DataProvider('provideEncodedValues')] public function testWithMemo(mixed $values, array $expect, mixed $initValues = null, array $initExpect = []): void { $init = ScheduleOptions::new(); @@ -108,9 +106,7 @@ public function testWithMemo(mixed $values, array $expect, mixed $initValues = n $this->assertSame($expect, $new->memo->getValues()); } - /** - * @dataProvider provideEncodedValues - */ + #[DataProvider('provideEncodedValues')] public function testWithSearchAttributes(mixed $values, array $expect, mixed $initValues = null, array $initExpect = []): void { $init = ScheduleOptions::new(); diff --git a/tests/Unit/Schedule/ScheduleTestCase.php b/tests/Unit/Schedule/ScheduleTestCase.php index e0aa9326..b150245f 100644 --- a/tests/Unit/Schedule/ScheduleTestCase.php +++ b/tests/Unit/Schedule/ScheduleTestCase.php @@ -4,6 +4,7 @@ namespace Schedule; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Action\StartWorkflowAction; use Temporal\Client\Schedule\Policy\SchedulePolicies; @@ -11,9 +12,7 @@ use Temporal\Client\Schedule\Spec\ScheduleSpec; use Temporal\Client\Schedule\Spec\ScheduleState; -/** - * @covers \Temporal\Client\Schedule\Schedule - */ +#[CoversClass(\Temporal\Client\Schedule\Schedule::class)] class ScheduleTestCase extends TestCase { public function testWithAction(): void diff --git a/tests/Unit/Schedule/Spec/CalendarSpecTestCase.php b/tests/Unit/Schedule/Spec/CalendarSpecTestCase.php index 53092a41..132d658b 100644 --- a/tests/Unit/Schedule/Spec/CalendarSpecTestCase.php +++ b/tests/Unit/Schedule/Spec/CalendarSpecTestCase.php @@ -4,12 +4,11 @@ namespace Temporal\Tests\Unit\Schedule\Spec; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Spec\CalendarSpec; -/** - * @covers \Temporal\Client\Schedule\Spec\CalendarSpec - */ +#[CoversClass(\Temporal\Client\Schedule\Spec\CalendarSpec::class)] class CalendarSpecTestCase extends TestCase { public function testWithSecondString(): void diff --git a/tests/Unit/Schedule/Spec/IntervalSpecTestCase.php b/tests/Unit/Schedule/Spec/IntervalSpecTestCase.php index cfa039cd..d6cf4a68 100644 --- a/tests/Unit/Schedule/Spec/IntervalSpecTestCase.php +++ b/tests/Unit/Schedule/Spec/IntervalSpecTestCase.php @@ -4,12 +4,11 @@ namespace Temporal\Tests\Unit\Schedule\Spec; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Spec\IntervalSpec; -/** - * @covers \Temporal\Client\Schedule\Spec\IntervalSpec - */ +#[CoversClass(\Temporal\Client\Schedule\Spec\IntervalSpec::class)] class IntervalSpecTestCase extends TestCase { public function testWithIntervalInt(): void diff --git a/tests/Unit/Schedule/Spec/RangeTestCase.php b/tests/Unit/Schedule/Spec/RangeTestCase.php index 101b7288..57a5a81d 100644 --- a/tests/Unit/Schedule/Spec/RangeTestCase.php +++ b/tests/Unit/Schedule/Spec/RangeTestCase.php @@ -4,12 +4,11 @@ namespace Temporal\Tests\Unit\Schedule\Spec; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Spec\Range; -/** - * @covers \Temporal\Client\Schedule\Spec\Range - */ +#[CoversClass(\Temporal\Client\Schedule\Spec\Range::class)] class RangeTestCase extends TestCase { public function testWithStart(): void diff --git a/tests/Unit/Schedule/Spec/ScheduleSpecTestCase.php b/tests/Unit/Schedule/Spec/ScheduleSpecTestCase.php index eca27058..92c8f7b3 100644 --- a/tests/Unit/Schedule/Spec/ScheduleSpecTestCase.php +++ b/tests/Unit/Schedule/Spec/ScheduleSpecTestCase.php @@ -4,6 +4,8 @@ namespace Temporal\Tests\Unit\Schedule\Spec; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Spec\CalendarSpec; use Temporal\Client\Schedule\Spec\IntervalSpec; @@ -11,9 +13,7 @@ use Temporal\Client\Schedule\Spec\ScheduleSpec; use Temporal\Client\Schedule\Spec\StructuredCalendarSpec; -/** - * @covers \Temporal\Client\Schedule\Spec\ScheduleSpec - */ +#[CoversClass(\Temporal\Client\Schedule\Spec\ScheduleSpec::class)] class ScheduleSpecTestCase extends TestCase { public function testWithTimezoneName(): void @@ -38,9 +38,7 @@ public function testWithTimezoneData(): void $this->assertSame('+01:00', $new->timezoneData); } - /** - * @dataProvider provideStartEndTime - */ + #[DataProvider('provideStartEndTime')] public function testWithStartTime( mixed $withValue, ?string $expectedValue, @@ -57,9 +55,7 @@ public function testWithStartTime( $this->assertSame($expectedValue, $new->startTime?->format(\DateTimeInterface::ATOM)); } - /** - * @dataProvider provideStartEndTime - */ + #[DataProvider('provideStartEndTime')] public function testWithEndTime( mixed $withValue, ?string $expectedValue, @@ -83,9 +79,7 @@ public static function provideStartEndTime(): iterable yield 'unset' => [null, null, '2024-10-01T00:00:00Z', '2024-10-01T00:00:00+00:00']; } - /** - * @dataProvider provideJitter - */ + #[DataProvider('provideJitter')] public function testWithJitter( mixed $withValue, string $expectedValue, diff --git a/tests/Unit/Schedule/Spec/ScheduleStateTestCase.php b/tests/Unit/Schedule/Spec/ScheduleStateTestCase.php index 0c77b875..f8db316f 100644 --- a/tests/Unit/Schedule/Spec/ScheduleStateTestCase.php +++ b/tests/Unit/Schedule/Spec/ScheduleStateTestCase.php @@ -4,12 +4,11 @@ namespace Temporal\Tests\Unit\Schedule\Spec; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Spec\ScheduleState; -/** - * @covers \Temporal\Client\Schedule\Spec\ScheduleState - */ +#[CoversClass(\Temporal\Client\Schedule\Spec\ScheduleState::class)] class ScheduleStateTestCase extends TestCase { public function testWithNotes(): void diff --git a/tests/Unit/Schedule/Spec/StructuredCalendarSpecTestCase.php b/tests/Unit/Schedule/Spec/StructuredCalendarSpecTestCase.php index e21def20..7cedbc2d 100644 --- a/tests/Unit/Schedule/Spec/StructuredCalendarSpecTestCase.php +++ b/tests/Unit/Schedule/Spec/StructuredCalendarSpecTestCase.php @@ -4,13 +4,12 @@ namespace Temporal\Tests\Unit\Schedule\Spec; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Temporal\Client\Schedule\Spec\Range; use Temporal\Client\Schedule\Spec\StructuredCalendarSpec; -/** - * @covers \Temporal\Client\Schedule\Spec\StructuredCalendarSpec - */ +#[CoversClass(\Temporal\Client\Schedule\Spec\StructuredCalendarSpec::class)] class StructuredCalendarSpecTestCase extends TestCase { public function testWithSeconds(): void diff --git a/tests/Unit/Worker/WorkerTestCase.php b/tests/Unit/Worker/AbstractWorker.php similarity index 77% rename from tests/Unit/Worker/WorkerTestCase.php rename to tests/Unit/Worker/AbstractWorker.php index 16d56b51..fcbbfd18 100644 --- a/tests/Unit/Worker/WorkerTestCase.php +++ b/tests/Unit/Worker/AbstractWorker.php @@ -11,12 +11,12 @@ namespace Temporal\Tests\Unit\Worker; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group worker * @group unit */ -abstract class WorkerTestCase extends UnitTestCase +abstract class AbstractWorker extends AbstractUnit { } diff --git a/tests/Unit/Worker/AutowiringTestCase.php b/tests/Unit/Worker/AutowiringTestCase.php index 54d920d3..3b20607e 100644 --- a/tests/Unit/Worker/AutowiringTestCase.php +++ b/tests/Unit/Worker/AutowiringTestCase.php @@ -11,6 +11,8 @@ namespace Temporal\Tests\Unit\Worker; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestDox; use Temporal\DataConverter\DataConverter; use Temporal\DataConverter\JsonConverter; use Temporal\Internal\Declaration\Dispatcher\AutowiredPayloads; @@ -24,24 +26,26 @@ function global_function(): int * @group unit * @group worker */ -class AutowiringTestCase extends WorkerTestCase +class AutowiringTestCase extends AbstractWorker { public static function staticMethod(): int { return global_function(); } - public function reflectionDataProvider(): array + public static function reflectionDataProvider(): array { + $instance = (new \ReflectionClass(static::class))->newInstanceWithoutConstructor(); + return [ // Closure - 'closure' => [new \ReflectionFunction(fn() => $this->instanceMethod())], + 'closure' => [new \ReflectionFunction($instance->instanceMethod(...))], // Static Closure 'static closure' => [new \ReflectionFunction(static fn() => global_function())], // Instance Method - static::class . '->instanceMethod' => [new \ReflectionMethod($this, 'instanceMethod')], + static::class . '->instanceMethod' => [new \ReflectionMethod($instance, 'instanceMethod')], // Static Method static::class . '::staticMethod' => [new \ReflectionMethod(static::class . '::staticMethod')], @@ -51,16 +55,13 @@ public function reflectionDataProvider(): array ]; } - public function instanceMethod(): int + public static function instanceMethod(): int { return global_function(); } - /** - * @testdox Checks an attempt to create a new autowiring context from different callable types - * - * @dataProvider reflectionDataProvider - */ + #[DataProvider('reflectionDataProvider')] + #[TestDox("Checks an attempt to create a new autowiring context from different callable types")] public function testCreation(\ReflectionFunctionAbstract $fn): void { $this->expectNotToPerformAssertions(); @@ -68,11 +69,8 @@ public function testCreation(\ReflectionFunctionAbstract $fn): void new AutowiredPayloads($fn, new DataConverter()); } - /** - * @testdox Checks invocation with an object context or exception otherwise (if static context required) - * - * @dataProvider reflectionDataProvider - */ + #[TestDox("Checks invocation with an object context or exception otherwise (if static context required)")] + #[DataProvider('reflectionDataProvider')] public function testInstanceCallMethodInvocation(\ReflectionFunctionAbstract $fn): void { $handler = new AutowiredPayloads($fn, new DataConverter(new JsonConverter())); @@ -86,11 +84,8 @@ public function testInstanceCallMethodInvocation(\ReflectionFunctionAbstract $fn $this->assertSame(0xDEAD_BEEF, $handler->dispatch($this, [])); } - /** - * @testdox Checks invocation without an object context or exception otherwise (if object context required) - * - * @dataProvider reflectionDataProvider - */ + #[TestDox("Checks invocation without an object context or exception otherwise (if object context required)")] + #[DataProvider('reflectionDataProvider')] public function testStaticCallMethodInvocation(\ReflectionFunctionAbstract $fn): void { $handler = new AutowiredPayloads($fn, new DataConverter(new JsonConverter())); diff --git a/tests/Unit/Worker/Transport/RoadRunnerTestCase.php b/tests/Unit/Worker/Transport/RoadRunnerTestCase.php index 1a09dda3..71714a9b 100644 --- a/tests/Unit/Worker/Transport/RoadRunnerTestCase.php +++ b/tests/Unit/Worker/Transport/RoadRunnerTestCase.php @@ -8,14 +8,14 @@ use RoadRunner\VersionChecker\Version\InstalledInterface; use RoadRunner\VersionChecker\Version\RequiredInterface; use RoadRunner\VersionChecker\VersionChecker; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; use Temporal\Worker\Transport\RoadRunner; use Temporal\Worker\Transport\RoadRunnerVersionChecker; /** * @group unit */ -final class RoadRunnerTestCase extends UnitTestCase +final class RoadRunnerTestCase extends AbstractUnit { public function testCreateShouldCallVersionCheck(): void { diff --git a/tests/Unit/Worker/Transport/RoadRunnerVersionCheckerTestCase.php b/tests/Unit/Worker/Transport/RoadRunnerVersionCheckerTestCase.php index bb76b882..d42f59b3 100644 --- a/tests/Unit/Worker/Transport/RoadRunnerVersionCheckerTestCase.php +++ b/tests/Unit/Worker/Transport/RoadRunnerVersionCheckerTestCase.php @@ -9,13 +9,13 @@ use RoadRunner\VersionChecker\Version\InstalledInterface; use RoadRunner\VersionChecker\Version\RequiredInterface; use RoadRunner\VersionChecker\VersionChecker; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; use Temporal\Worker\Transport\RoadRunnerVersionChecker; /** * @group unit */ -final class RoadRunnerVersionCheckerTestCase extends UnitTestCase +final class RoadRunnerVersionCheckerTestCase extends AbstractUnit { public function testCheckSuccess(): void { diff --git a/tests/Unit/WorkerFactory/WorkerFactoryTestCase.php b/tests/Unit/WorkerFactory/AbstractWorkerFactory.php similarity index 76% rename from tests/Unit/WorkerFactory/WorkerFactoryTestCase.php rename to tests/Unit/WorkerFactory/AbstractWorkerFactory.php index d07bbfd5..5cc5477f 100644 --- a/tests/Unit/WorkerFactory/WorkerFactoryTestCase.php +++ b/tests/Unit/WorkerFactory/AbstractWorkerFactory.php @@ -11,12 +11,12 @@ namespace Temporal\Tests\Unit\WorkerFactory; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; /** * @group worker * @group unit */ -abstract class WorkerFactoryTestCase extends UnitTestCase +abstract class AbstractWorkerFactory extends AbstractUnit { } diff --git a/tests/Unit/WorkerFactory/CustomReaderTestCase.php b/tests/Unit/WorkerFactory/CustomReaderTestCase.php index a58b35fd..4ed474c7 100644 --- a/tests/Unit/WorkerFactory/CustomReaderTestCase.php +++ b/tests/Unit/WorkerFactory/CustomReaderTestCase.php @@ -15,7 +15,7 @@ use Temporal\Tests\Unit\Declaration\Fixture\CustomReaderWorkerFactory; use Temporal\Tests\Unit\Declaration\Fixture\UnannotatedClass; -class CustomReaderTestCase extends WorkerFactoryTestCase +class CustomReaderTestCase extends AbstractWorkerFactory { public function testCustomReader() { diff --git a/tests/Unit/WorkflowContext/AwaitWithTimeoutTestCase.php b/tests/Unit/WorkflowContext/AwaitWithTimeoutTestCase.php index 15ab8be1..30ef4348 100644 --- a/tests/Unit/WorkflowContext/AwaitWithTimeoutTestCase.php +++ b/tests/Unit/WorkflowContext/AwaitWithTimeoutTestCase.php @@ -6,7 +6,7 @@ use Temporal\Tests\Unit\Framework\WorkerFactoryMock; use Temporal\Tests\Unit\Framework\WorkerMock; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; use Temporal\Worker\WorkerFactoryInterface; use Temporal\Worker\WorkerInterface; use Temporal\Workflow; @@ -15,7 +15,7 @@ use function PHPUnit\Framework\assertFalse; use function PHPUnit\Framework\assertTrue; -final class AwaitWithTimeoutTestCase extends UnitTestCase +final class AwaitWithTimeoutTestCase extends AbstractUnit { private WorkerFactoryInterface $factory; /** @var WorkerMock|WorkerInterface */ diff --git a/tests/Unit/WorkflowContext/GetVersionTestCase.php b/tests/Unit/WorkflowContext/GetVersionTestCase.php index 316b6e05..6343e10c 100644 --- a/tests/Unit/WorkflowContext/GetVersionTestCase.php +++ b/tests/Unit/WorkflowContext/GetVersionTestCase.php @@ -6,13 +6,13 @@ use Temporal\Tests\Unit\Framework\WorkerFactoryMock; use Temporal\Tests\Unit\Framework\WorkerMock; -use Temporal\Tests\Unit\UnitTestCase; +use Temporal\Tests\Unit\AbstractUnit; use Temporal\Worker\WorkerFactoryInterface; use Temporal\Worker\WorkerInterface; use Temporal\Workflow; use Temporal\Workflow\WorkflowMethod; -final class GetVersionTestCase extends UnitTestCase +final class GetVersionTestCase extends AbstractUnit { private WorkerFactoryInterface $factory; /** @var WorkerMock|WorkerInterface */