diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index caae9bdb0..72cf1a4bf 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -14,14 +14,6 @@ jobs: fail-fast: false test-command: composer test:unit -# feature: -# name: Feature Testing -# uses: ./.github/workflows/run-test-suite.yml -# with: -# fail-fast: true -# test-command: composer test:feat -# test-timeout: 20 - functional: name: Functional Testing uses: ./.github/workflows/run-test-suite.yml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 044038070..a982abbf3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,9 +27,6 @@ tests/Unit - - tests/Feature - tests/Functional diff --git a/tests/Feature/AbstractFeature.php b/tests/Feature/AbstractFeature.php deleted file mode 100644 index 05ad53ec4..000000000 --- a/tests/Feature/AbstractFeature.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ - public array $requests = []; - - /** - * @var ClientInterface - */ - protected ClientInterface $parent; - - /** - * @param ClientInterface $parent - */ - public function __construct(ClientInterface $parent) - { - $this->parent = $parent; - } - - /** - * @param RequestInterface $request - * @return PromiseInterface - */ - public function request(RequestInterface $request, ?WorkflowContextInterface $context = null): PromiseInterface - { - return $this->requests[$request->getID()] = $this->parent->request($request) - ->then($this->onFulfilled($request), $this->onRejected($request)); - } - - public function send(CommandInterface $request): void - { - $this->parent->send($request); - } - - /** - * {@inheritDoc} - */ - public function fetchUnresolvedRequests(): array - { - try { - return $this->requests; - } finally { - $this->requests = []; - } - } - - /** - * @return \Traversable - */ - public function getIterator(): \Traversable - { - return new \ArrayIterator($this->requests); - } - - /** - * @return int - */ - public function count(): int - { - return \count($this->requests); - } - - public function isQueued(CommandInterface $command): bool - { - return $this->parent->isQueued($command); - } - - public function cancel(CommandInterface $command): void - { - $this->parent->cancel($command); - } - - public function reject(CommandInterface $command, \Throwable $reason): void - { - $this->parent->reject($command, $reason); - } - - public function dispatch(CommandInterface $response): void - { - $this->parent->dispatch($response); - } - - public function fork(): ClientInterface - { - return $this->parent->fork(); - } - - /** - * @param RequestInterface $request - * @return \Closure - */ - private function onFulfilled(RequestInterface $request): \Closure - { - return function ($response) use ($request) { - unset($this->requests[$request->getID()]); - - return $response; - }; - } - - /** - * @param RequestInterface $request - * @return \Closure - * @psalm-suppress UnusedClosureParam - */ - private function onRejected(RequestInterface $request): \Closure - { - return function (\Throwable $error) use ($request): void { - unset($this->requests[$request->getID()]); - - throw $error; - }; - } -} diff --git a/tests/Feature/Testing/TestingClient.php b/tests/Feature/Testing/TestingClient.php deleted file mode 100644 index 6f58ac2d6..000000000 --- a/tests/Feature/Testing/TestingClient.php +++ /dev/null @@ -1,81 +0,0 @@ -queue = $queue ?? new TestingQueue(); - - parent::__construct(new Client($this->queue)); - } - - /** - * @param RequestInterface $request - * @param mixed|null $payload - * @return TestingSuccessResponse - */ - public function success(RequestInterface $request, $payload = null): TestingSuccessResponse - { - $response = new SuccessClientResponse($request->getID(), $payload); - - $this->parent->dispatch($response); - - return new TestingSuccessResponse($response); - } - - /** - * @param RequestInterface $request - * @param \Throwable $error - * @return TestingFailureResponse - */ - public function error(RequestInterface $request, \Throwable $error): TestingFailureResponse - { - $response = FailureResponse::fromException($error, $request->getID()); - - $this->parent->dispatch($response); - - return new TestingFailureResponse($response); - } - - /** - * {@inheritDoc} - */ - public function request(RequestInterface $request, ?WorkflowContextInterface $context = null): PromiseInterface - { - if (!$request instanceof TestingRequest) { - $request = new TestingRequest($request); - } - - return parent::request($request, $context); - } -} diff --git a/tests/Feature/Testing/TestingCommand.php b/tests/Feature/Testing/TestingCommand.php deleted file mode 100644 index 6eee24056..000000000 --- a/tests/Feature/Testing/TestingCommand.php +++ /dev/null @@ -1,62 +0,0 @@ -command = $command; - } - - /** - * @return T - */ - public function getCommand(): CommandInterface - { - return $this->command; - } - - /** - * {@inheritDoc} - */ - public function getID(): int - { - return $this->command->getID(); - } - - /** - * @param int $expected - * @param string $message - * @return $this - */ - public function assertId(int $expected, string $message = ''): self - { - Assert::assertSame($expected, $this->getID(), $message); - - return $this; - } -} diff --git a/tests/Feature/Testing/TestingEnvironment.php b/tests/Feature/Testing/TestingEnvironment.php deleted file mode 100644 index b8cbd6aa0..000000000 --- a/tests/Feature/Testing/TestingEnvironment.php +++ /dev/null @@ -1,63 +0,0 @@ -zone = $zone; - - return $this; - } - - /** - * @param CarbonInterface $tickTime - * @return TestingEnvironment - */ - public function setTickTime(CarbonInterface $tickTime): self - { - $this->tickTime = $tickTime; - - return $this; - } - - /** - * @param string|null $runId - * @return TestingEnvironment - */ - public function setRunId(?string $runId): self - { - $this->runId = $runId; - - return $this; - } - - /** - * @param bool $isReplaying - * @return TestingEnvironment - */ - public function setIsReplaying(bool $isReplaying): self - { - $this->isReplaying = $isReplaying; - - return $this; - } -} diff --git a/tests/Feature/Testing/TestingFailureResponse.php b/tests/Feature/Testing/TestingFailureResponse.php deleted file mode 100644 index daad3dbdb..000000000 --- a/tests/Feature/Testing/TestingFailureResponse.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class TestingFailureResponse extends TestingCommand implements FailureResponseInterface -{ - /** - * @param FailureResponseInterface $response - */ - public function __construct(FailureResponseInterface $response) - { - parent::__construct($response); - } - - /** - * {@inheritDoc} - */ - public function getCode(): int - { - return $this->command->getCode(); - } - - /** - * {@inheritDoc} - */ - public function getMessage(): string - { - return $this->command->getMessage(); - } - - /** - * {@inheritDoc} - */ - public function getData() - { - return $this->command->getData(); - } - - /** - * {@inheritDoc} - */ - public function toException(string $class = \LogicException::class): \Throwable - { - return $this->command->toException($class); - } -} diff --git a/tests/Feature/Testing/TestingLoop.php b/tests/Feature/Testing/TestingLoop.php deleted file mode 100644 index 6436c4d12..000000000 --- a/tests/Feature/Testing/TestingLoop.php +++ /dev/null @@ -1,38 +0,0 @@ -emit(LoopInterface::ON_TICK); - } - - /** - * @return int - */ - public function run(): int - { - $this->tick(); - - return 0; - } -} diff --git a/tests/Feature/Testing/TestingMarshaller.php b/tests/Feature/Testing/TestingMarshaller.php deleted file mode 100644 index 219ff8934..000000000 --- a/tests/Feature/Testing/TestingMarshaller.php +++ /dev/null @@ -1,49 +0,0 @@ - - */ -class TestingMarshaller implements MarshallerInterface -{ - /** - * @var Marshaller - */ - private Marshaller $marshaller; - - /** - * @param MapperFactoryInterface|null $mapper - */ - public function __construct(MapperFactoryInterface $mapper = null) - { - $mapper ??= new AttributeMapperFactory(new AttributeReader()); - - $this->marshaller = new Marshaller($mapper); - } - - public function marshal(object $from): array - { - return $this->marshaller->marshal($from); - } - - public function unmarshal(array $from, object $to): object - { - return $this->marshaller->unmarshal($from, $to); - } -} diff --git a/tests/Feature/Testing/TestingQueue.php b/tests/Feature/Testing/TestingQueue.php deleted file mode 100644 index 875dbca99..000000000 --- a/tests/Feature/Testing/TestingQueue.php +++ /dev/null @@ -1,241 +0,0 @@ -commands) { - yield $this->pop(); - } - } - - /** - * @return TestingRequest|TestingSuccessResponse|TestingFailureResponse - */ - public function pop(): CommandInterface - { - return \array_pop($this->commands); - } - - /** - * @return TestingRequest|TestingSuccessResponse|TestingFailureResponse - */ - public function shift(): CommandInterface - { - return \array_shift($this->commands); - } - - /** - * {@inheritDoc} - */ - public function push(CommandInterface $command): void - { - if ($command instanceof Request) { - $command = new TestingRequest($command); - } - - $this->commands[] = $command; - } - - /** - * @return void - */ - public function clear(): void - { - $this->commands = []; - } - - /** - * @param int $expected - * @param string $message - * @return $this - */ - public function assertCount(int $expected, string $message = ''): self - { - Assert::assertCount($expected, $this->commands, $message); - - return $this; - } - - /** - * @param int $expected - * @param string $message - * @return $this - */ - public function assertTypesCount(string $class, int $expected, string $message = ''): self - { - $filter = static fn (CommandInterface $cmd) => $cmd instanceof $class; - - Assert::assertCount($expected, \array_filter($this->commands, $filter), $message); - - return $this; - } - - /** - * @param int $expected - * @param string $message - * @return $this - */ - public function assertRequestsCount(int $expected, string $message = ''): self - { - $this->assertTypesCount(RequestInterface::class, $expected, $message); - - return $this; - } - - /** - * @param int $expected - * @param string $message - * @return $this - */ - public function assertResponsesCount(int $expected, string $message = ''): self - { - $this->assertTypesCount(ResponseInterface::class, $expected, $message); - - return $this; - } - - /** - * @param int $expected - * @param string $message - * @return $this - */ - public function assertErrorResponsesCount(int $expected, string $message = ''): self - { - $this->assertTypesCount(FailureResponseInterface::class, $expected, $message); - - return $this; - } - - /** - * @param int $expected - * @param string $message - * @return $this - */ - public function assertSuccessResponsesCount(int $expected, string $message = ''): self - { - $this->assertTypesCount(SuccessResponseInterface::class, $expected, $message); - - return $this; - } - - /** - * @param string $message - * @return $this - */ - public function assertEmpty(string $message = ''): self - { - $this->assertCount(0, $message); - - return $this; - } - - /** - * @param string $message - * @return $this - */ - public function assertNotEmpty(string $message = ''): self - { - Assert::assertTrue(\count($this->commands) > 0, $message); - - return $this; - } - - /** - * @param array $commands - * @param string $message - * @return $this - */ - public function assertSame(array $commands, string $message = ''): self - { - Assert::assertSame($this->commands, $commands, $message); - - return $this; - } - - /** - * @param array $commands - * @param string $message - * @return $this - */ - public function assertEquals(array $commands, string $message = ''): self - { - Assert::assertEquals($this->commands, $commands, $message); - - return $this; - } - - /** - * @return TestingRequest|TestingSuccessResponse|TestingFailureResponse - */ - public function first(): CommandInterface - { - return $this->get(\array_key_first($this->commands)); - } - - /** - * @return TestingRequest|TestingSuccessResponse|TestingFailureResponse - */ - public function last(): CommandInterface - { - return $this->get(\array_key_first($this->commands)); - } - - /** - * @param positive-int $index - * @return TestingRequest|TestingSuccessResponse|TestingFailureResponse|null - */ - public function find(int $index): ?CommandInterface - { - return $this->commands[$index] ?? null; - } - - /** - * @param positive-int $index - * @return TestingRequest|TestingSuccessResponse|TestingFailureResponse - */ - public function get(int $index): CommandInterface - { - $command = $this->find($index); - - Assert::assertNotNull($command); - - return $command; - } - - /** - * @param \Closure $assert - * @return $this - */ - public function each(\Closure $assert): self - { - foreach ($this->commands as $command) { - $assert($command); - } - - return $this; - } -} diff --git a/tests/Feature/Testing/TestingRequest.php b/tests/Feature/Testing/TestingRequest.php deleted file mode 100644 index 7e8de46aa..000000000 --- a/tests/Feature/Testing/TestingRequest.php +++ /dev/null @@ -1,184 +0,0 @@ - - */ -class TestingRequest extends TestingCommand implements RequestInterface -{ - /** - * @param RequestInterface $request - */ - public function __construct(RequestInterface $request) - { - parent::__construct($request); - } - - /** - * @param string $expected - * @param string $message - * @return $this - */ - public function assertName(string $expected, string $message = ''): self - { - Assert::assertSame($expected, $this->getName(), $message); - - return $this; - } - - /** - * {@inheritDoc} - */ - public function getName(): string - { - return $this->command->getName(); - } - - /** - * @param string $key - * @return mixed - */ - public function getParam(string $key) - { - return $this->getOption($key); - } - - /** - * {@inheritDoc} - */ - public function getOptions(): array - { - return $this->command->getOptions(); - } - - public function getPayloads(): ValuesInterface - { - return $this->command->getPayloads(); - } - - /** - * @param string $expected - * @param string $message - * @return $this - */ - public function assertParamsSame(array $expected, string $message = ''): self - { - Assert::assertSame($expected, $this->getOptions(), $message); - - return $this; - } - - /** - * @param string $key - * @param mixed $expected - * @param string $message - * @return $this - */ - public function assertParamsKeySame(string $key, $expected, string $message = ''): self - { - if ($expected === null) { - $this->assertParamsHasKey($key, $message); - } - - Assert::assertEquals($expected, $this->getOption($key), $message); - - return $this; - } - - /** - * @param string $key - * @param string $message - * @return $this - */ - public function assertParamsHasKey(string $key, string $message = ''): self - { - Assert::assertArrayHasKey($key, $this->getOptions(), $message); - - return $this; - } - - /** - * @param string $key - * @param mixed $expected - * @param string $message - * @return $this - */ - public function assertParamsKeySamePayload(string $key, $expected, string $message = ''): self - { - if ($expected === null) { - $this->assertParamsHasKey($key, $message); - } - - if (\is_array($expected)) { - $expected = \array_map([$this, 'convertValue'], $expected); - } else { - $expected = $this->convertValue($expected); - } - - Assert::assertEquals($expected, $this->getOption($key), $message); - - return $this; - } - - private function convertValue($value): Payload - { - $dc = DataConverter::createDefault(); - - return $dc->toPayload([$value])[0]; - } - - /** - * @param string $key - * @param class-string $expected - * @param string $message - * @return $this - */ - public function assertParamsKeyInstanceOf(string $key, string $expected, string $message = ''): self - { - Assert::assertInstanceOf($expected, $this->getOption($key), $message); - - return $this; - } - - /** - * @param string $key - * @param mixed $expected - * @param string $message - * @return $this - */ - public function assertParamsKeyNotSame(string $key, $expected, string $message = ''): self - { - $this->assertParamsHasKey($key, $message); - - Assert::assertNotSame($expected, $this->getOption($key), $message); - - return $this; - } - - public function isCancellable(): bool - { - return true; - } - - private function getOption(string $key): mixed - { - return $this->getOptions()[$key] ?? null; - } -} diff --git a/tests/Feature/Testing/TestingSuccessResponse.php b/tests/Feature/Testing/TestingSuccessResponse.php deleted file mode 100644 index 9c8035bdc..000000000 --- a/tests/Feature/Testing/TestingSuccessResponse.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class TestingSuccessResponse extends TestingCommand implements SuccessResponseInterface -{ - /** - * @param SuccessResponseInterface $response - */ - public function __construct(SuccessResponseInterface $response) - { - parent::__construct($response); - } - - /** - * {@inheritDoc} - */ - public function getPayloads(): array - { - return $this->command->getPayloads(); - } -}