From bb08feb5ba7f3c6e5016e7104e6d7ceaea6a193b Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Tue, 2 Dec 2025 03:15:47 +0300 Subject: [PATCH] Rescaffold --- .devcontainer.json | 5 ++ .env | 1 + .gitattributes | 3 +- .github/workflows/{check.yml => check.yaml} | 10 +++- .php-cs-fixer.dist.php | 2 +- Makefile | 48 +++++++++++++------ compose.yaml | 11 +++-- composer.json | 4 ++ infection.json5.dist | 2 +- phpstan.dist.neon | 23 +++++++-- rector.php | 9 +--- src/Config.php | 16 ++++--- .../Delivery/ConsumerTagGenerator.php | 10 ++-- src/Internal/Delivery/DeliverySupervisor.php | 2 +- src/Internal/Io/Buffer.php | 2 +- src/Internal/MessageProperties.php | 2 +- .../Returns/FutureBoundedReturnListener.php | 2 +- src/Internal/VersionProvider.php | 30 +++++++----- src/PublishConfirmation.php | 2 +- src/Rpc.php | 11 +++-- tests/ClientTest.php | 10 ++-- tests/ConfigTest.php | 4 +- tests/Internal/ConsumerTagGeneratorTest.php | 11 ++++- 23 files changed, 143 insertions(+), 77 deletions(-) create mode 100644 .devcontainer.json rename .github/workflows/{check.yml => check.yaml} (75%) diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..b1eed77 --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,5 @@ +{ + "dockerComposeFile": "compose.yaml", + "service": "php", + "workspaceFolder": "/workspace" +} diff --git a/.env b/.env index 5d99414..bc024b6 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ # Put env variables defaults here # Override locally in gitignored .env.local +PHP_IMAGE_VERSION=8.3 diff --git a/.gitattributes b/.gitattributes index 0ef95b2..d9c8bf9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,12 @@ +/.devcontainer/ export-ignore /.github/ export-ignore /docker/ export-ignore /examples/ export-ignore /stubs/ export-ignore /tests/ export-ignore -/.env export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.php-cs-fixer.dist.php export-ignore -/compose.yaml export-ignore /composer.lock export-ignore /infection.json5.dist export-ignore /Makefile export-ignore diff --git a/.github/workflows/check.yml b/.github/workflows/check.yaml similarity index 75% rename from .github/workflows/check.yml rename to .github/workflows/check.yaml index 63e382c..4ce07b1 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yaml @@ -1,9 +1,15 @@ +name: Check + on: workflow_dispatch: ~ push: branches: [main, '*.*.x'] pull_request: ~ +concurrency: + group: check-${{ github.ref }} + cancel-in-progress: true + jobs: code-style: runs-on: ubuntu-latest @@ -26,14 +32,14 @@ jobs: deps: [ lowest, highest ] steps: - uses: actions/checkout@v6 - - run: PHP_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} phpstan + - run: PHP_IMAGE_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} phpstan test: runs-on: ubuntu-latest strategy: *strategy steps: - uses: actions/checkout@v6 - - run: PHP_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} test + - run: PHP_IMAGE_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} test # infect: # runs-on: ubuntu-latest diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8007ba7..7fa8943 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,9 +10,9 @@ $config = (new Config()) ->setFinder( Finder::create() + ->in(__DIR__ . '/examples') ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests') - ->in(__DIR__ . '/examples') ->append([ __FILE__, ]), diff --git a/Makefile b/Makefile index 72e1da8..74a3576 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,10 @@ -include .env --include .env.local - SHELL ?= /bin/bash + DOCKER ?= docker -DOCKER_COMPOSE ?= $(DOCKER) compose +DOCKER_COMPOSE ?= $(DOCKER) compose $(shell test -f .env.local && echo '--env-file .env --env-file .env.local') export CONTAINER_USER ?= $(shell id -u):$(shell id -g) -INSIDE_CONTAINER ?= $(shell test -f /.dockerenv && echo 1) -RUN ?= $(if $(INSIDE_CONTAINER),,$(DOCKER_COMPOSE) run --rm php) +RUN ?= $(if $(INSIDE_DEVCONTAINER),,$(DOCKER_COMPOSE) run --rm php) COMPOSER ?= $(RUN) composer ## @@ -17,31 +14,39 @@ COMPOSER ?= $(RUN) composer var: mkdir var -vendor: composer.json - if [ -f vendor/.lowest ]; then $(MAKE) install-lowest; else $(MAKE) install-highest; fi +vendor: composer.json $(wildcard composer.lock) + @if [ -f vendor/.lowest ]; then $(MAKE) install-lowest; else $(MAKE) install-highest; fi i: install-highest install-highest: ## Install highest Composer dependencies - $(COMPOSER) update $(ARGS) + $(COMPOSER) install @rm -f vendor/.lowest + @touch vendor .PHONY: i install-highest install-lowest: ## Install lowest Composer dependencies - $(COMPOSER) update --prefer-lowest --prefer-stable $(ARGS) + $(COMPOSER) update --prefer-lowest --prefer-stable @touch vendor/.lowest + @touch vendor .PHONY: install-lowest up: ## Docker compose up - $(DOCKER_COMPOSE) up --build --detach $(ARGS) + $(DOCKER_COMPOSE) up --remove-orphans --build --detach $(ARGS) .PHONY: up down: ## Docker compose down $(DOCKER_COMPOSE) down --remove-orphans $(ARGS) .PHONY: down -compose: ## Run docker compose command: `make compose CMD=start` +dc: docker-compose +docker-compose: ## Run docker compose command: `make dc CMD=start` $(DOCKER_COMPOSE) $(CMD) -.PHONY: compose +.PHONY: dc docker-compose + +c: composer +composer: ## Run Composer command: `make c CMD=start` + $(COMPOSER) $(CMD) +.PHONY: c composer run: ## Run a command using the php container: `make run CMD='php --version'` $(RUN) $(CMD) @@ -53,6 +58,19 @@ terminal: var ## Start a terminal inside the php container $(DOCKER_COMPOSE) run --rm $(ARGS) php bash .PHONY: t terminal +rescaffold: + $(DOCKER) run \ + --volume .:/project \ + --user $(CONTAINER_USER) \ + --interactive --tty --rm \ + --pull always \ + ghcr.io/phpyh/scaffolder:latest \ + --user-name-default "$(shell git config user.name 2>/dev/null || whoami 2>/dev/null)" \ + --user-email-default "$(shell git config user.email 2>/dev/null)" \ + --package-project-default "$(shell basename $$(pwd))" + git add --all 2>/dev/null || true +.PHONY: rescaffold + ## ## Tools ## ----- @@ -94,7 +112,7 @@ composer-validate: ## Validate composer.json .PHONY: composer-validate composer-normalize: ## Normalize composer.json - $(COMPOSER) normalize --diff $(ARGS) + $(COMPOSER) normalize --no-check-lock --no-update-lock --diff $(ARGS) .PHONY: composer-normalize composer-normalize-check: ## Check that composer.json is normalized @@ -104,7 +122,7 @@ composer-normalize-check: ## Check that composer.json is normalized fix: fixer rector composer-normalize ## Run all fixing recipes .PHONY: fix -check: fixer-check rector-check composer-validate composer-normalize-check phpstan test deps-analyze ## Run all project checks +check: fixer-check rector-check composer-validate composer-normalize-check deps-analyze phpstan test ## Run all project checks .PHONY: check # ----------------------- diff --git a/compose.yaml b/compose.yaml index 09a02db..a7809e2 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,13 +1,16 @@ services: php: - image: ghcr.io/thesis-php/php:${PHP_VERSION:-8.3} + # noinspection ComposeUnknownValues + image: ghcr.io/phpyh/php:${PHP_IMAGE_VERSION:?Make sure `PHP_IMAGE_VERSION` is declared in `.env`} user: ${CONTAINER_USER:-} environment: - HISTFILE: /app/var/.docker_history - COMPOSER_CACHE_DIR: /app/var/.composer_cache + INSIDE_DEVCONTAINER: true + HISTFILE: /workspace/var/.docker_history + COMPOSER_CACHE_DIR: /workspace/var/.composer_cache tty: true volumes: - - .:/app:cached + - .:/workspace:cached + working_dir: /workspace rabbitmq: image: rabbitmq:4.0-management-alpine diff --git a/composer.json b/composer.json index 44eb403..78eba87 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,10 @@ "phpunit/phpunit": "^12.4.4", "symfony/var-dumper": "^7.3.5" }, + "conflict": { + "amphp/dns": "<2.1.2", + "amphp/socket": "<2.3.1" + }, "autoload": { "psr-4": { "Thesis\\Amqp\\": "src/" diff --git a/infection.json5.dist b/infection.json5.dist index 82590f7..0c4ab7b 100644 --- a/infection.json5.dist +++ b/infection.json5.dist @@ -7,7 +7,7 @@ "logs": { "text": "var/infection.log", "stryker": { - "report": "/^\\d+\\.\\d+\\.x$/" + "report": "/^(?>main|\\d+\\.\\d+\\.x)$/D" }, }, "tmpDir": "var", diff --git a/phpstan.dist.neon b/phpstan.dist.neon index d2fe4ef..b67c4df 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,12 +1,27 @@ +includes: + - /composer/vendor/phpstan/phpstan-strict-rules/rules.neon + - /composer/vendor/phpstan/phpstan-phpunit/extension.neon + - /composer/vendor/phpstan/phpstan-phpunit/rules.neon + parameters: level: max paths: + - examples - src - tests - - examples - checkBenevolentUnionTypes: true + tmpDir: var/phpstan editorUrl: '' - editorUrlTitle: '%%file%%:%%line%%' - tmpDir: ./var/phpstan + editorUrlTitle: '%%relFile%%:%%line%%' stubFiles: - stubs/amphp.phpstub + + # strict rules + checkBenevolentUnionTypes: true + checkMissingCallableSignature: true + # checkMissingOverrideMethodAttribute: true + checkUninitializedProperties: true + # rememberPossiblyImpureFunctionValues: false + reportAlwaysTrueInLastCondition: true + reportAnyTypeWideningInVarTag: true + reportPossiblyNonexistentConstantArrayOffset: true + # reportPossiblyNonexistentGeneralArrayOffset: true diff --git a/rector.php b/rector.php index 4a981c9..3f898a5 100644 --- a/rector.php +++ b/rector.php @@ -2,11 +2,7 @@ declare(strict_types=1); -use Rector\Config\RectorConfig; -use Rector\Php80\Rector\Class_\StringableForToStringRector; -use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector; - -return RectorConfig::configure() +return Rector\Config\RectorConfig::configure() ->withPaths([ __DIR__ . '/examples', __DIR__ . '/src', @@ -16,6 +12,5 @@ ->withCache(__DIR__ . '/var/rector') ->withPhpSets() ->withSkip([ - StringableForToStringRector::class, - AddOverrideAttributeToOverriddenMethodsRector::class, + Rector\Php80\Rector\Class_\StringableForToStringRector::class, ]); diff --git a/src/Config.php b/src/Config.php index acd438c..5dc12c6 100644 --- a/src/Config.php +++ b/src/Config.php @@ -130,14 +130,12 @@ public static function fromURI(#[\SensitiveParameter] string $uri): self } $channelMax = self::MAX_CHANNEL; - if (isset($query['channel_max']) && is_numeric($query['channel_max']) && (int) $query['channel_max'] > 0) { - /** @var int<0, 65535> $channelMax */ + if (isset($query['channel_max']) && is_numeric($query['channel_max']) && (int) $query['channel_max'] >= 0) { $channelMax = min($channelMax, (int) $query['channel_max']); } $frameMax = self::MAX_FRAME; - if (isset($query['frame_max']) && is_numeric($query['frame_max']) && (int) $query['frame_max'] > 0) { - /** @var int<0, 65535> $frameMax */ + if (isset($query['frame_max']) && is_numeric($query['frame_max']) && (int) $query['frame_max'] >= 0) { $frameMax = min($frameMax, (int) $query['frame_max']); } @@ -164,12 +162,16 @@ public static function fromURI(#[\SensitiveParameter] string $uri): self $urls = []; foreach (explode(',', $components['host'] ?? '') as $host) { $hostport = explode(':', $host); - $urls[] = \sprintf('%s:%d', $hostport[0] ?: self::DEFAULT_HOST, (int) ($hostport[1] ?? $port)); + $urls[] = \sprintf('%s:%d', $hostport[0], (int) ($hostport[1] ?? $port)); } $vhost = self::DEFAULT_VHOST; if (isset($components['path'])) { - $vhost = ltrim($components['path'], '/') ?: self::DEFAULT_VHOST; + $vhost = ltrim($components['path'], '/'); + + if ($vhost === '') { + $vhost = self::DEFAULT_VHOST; + } } $user = self::DEFAULT_USERNAME; @@ -183,7 +185,7 @@ public static function fromURI(#[\SensitiveParameter] string $uri): self } return new self( - scheme: Scheme::tryFrom($components['scheme'] ?? Scheme::amqp->value) ?: throw UriIsInvalid::invalidScheme($components['scheme'] ?? ''), + scheme: Scheme::tryFrom($components['scheme'] ?? Scheme::amqp->value) ?? throw UriIsInvalid::invalidScheme($components['scheme'] ?? ''), urls: $urls, user: $user, password: $password, diff --git a/src/Internal/Delivery/ConsumerTagGenerator.php b/src/Internal/Delivery/ConsumerTagGenerator.php index 0945d1c..bfecf39 100644 --- a/src/Internal/Delivery/ConsumerTagGenerator.php +++ b/src/Internal/Delivery/ConsumerTagGenerator.php @@ -13,17 +13,15 @@ final class ConsumerTagGenerator private const string PACKAGE_NAME = 'thesis/amqp'; /** @var non-empty-string */ - private readonly string $commandName; + private readonly string $infix; /** @var non-negative-int */ private int $consumerId = 0; public function __construct() { - /** @var array{0?: string} $cli */ - $cli = $_SERVER['argv'] ?? [0 => self::PACKAGE_NAME]; - - $this->commandName = ($cli[0] ?? self::PACKAGE_NAME) ?: self::PACKAGE_NAME; + $command = $_SERVER['argv'][0] ?? null; // @phpstan-ignore offsetAccess.nonOffsetAccessible + $this->infix = \is_string($command) && $command !== '' ? $command : self::PACKAGE_NAME; } /** @@ -32,7 +30,7 @@ public function __construct() public function next(): string { $prefix = 'ctag-'; - $infix = $this->commandName; + $infix = $this->infix; $suffix = \sprintf('-%d', ++$this->consumerId); if (\strlen($prefix) + \strlen($infix) + \strlen($suffix) > self::TAG_LENGTH_MAX) { diff --git a/src/Internal/Delivery/DeliverySupervisor.php b/src/Internal/Delivery/DeliverySupervisor.php index 00985f7..00696ed 100644 --- a/src/Internal/Delivery/DeliverySupervisor.php +++ b/src/Internal/Delivery/DeliverySupervisor.php @@ -190,7 +190,7 @@ private function runListeners(): void ack: $this->return !== null ? $noAction : $channel->ack(...), nack: $this->return !== null ? $noAction : $channel->nack(...), reject: $this->return !== null ? $noAction : $channel->reject(...), - reply: $this->replier($this->header->properties, $channel) ?: $noAction, + reply: $this->replier($this->header->properties, $channel) ?? $noAction, message: new Message( body: $this->message, headers: $this->header->properties->headers, diff --git a/src/Internal/Io/Buffer.php b/src/Internal/Io/Buffer.php index fb6c03d..d5da502 100644 --- a/src/Internal/Io/Buffer.php +++ b/src/Internal/Io/Buffer.php @@ -228,7 +228,7 @@ public function readDecimal(): int $scale = $this->readUint8(); $value = $this->readUint32(); - return (int) ($value * (10 ** $scale)); + return (int) ($value * (10 ** $scale)); // @phpstan-ignore cast.useless } public function readText(): string diff --git a/src/Internal/MessageProperties.php b/src/Internal/MessageProperties.php index 8cdabf2..aefd666 100644 --- a/src/Internal/MessageProperties.php +++ b/src/Internal/MessageProperties.php @@ -268,7 +268,7 @@ public static function read(Io\ReadBytes $reader, int $mask): self $contentType = self::hasSet($mask, self::FLAG_CONTENT_TYPE) ? $reader->readString() : null; $contentEncoding = self::hasSet($mask, self::FLAG_CONTENT_ENCODING) ? $reader->readString() : null; $headers = self::hasSet($mask, self::FLAG_HEADERS) ? $reader->readTable() : []; - $deliveryMode = self::hasSet($mask, self::FLAG_DELIVERY_MODE) ? (DeliveryMode::tryFrom($reader->readUint8()) ?: DeliveryMode::Whatever) : DeliveryMode::Whatever; + $deliveryMode = self::hasSet($mask, self::FLAG_DELIVERY_MODE) ? (DeliveryMode::tryFrom($reader->readUint8()) ?? DeliveryMode::Whatever) : DeliveryMode::Whatever; /** @var ?int<0, 9> $priority */ $priority = self::hasSet($mask, self::FLAG_PRIORITY) ? $reader->readUint8() : null; /** @var non-empty-string $correlationId */ diff --git a/src/Internal/Returns/FutureBoundedReturnListener.php b/src/Internal/Returns/FutureBoundedReturnListener.php index 718b144..066b23a 100644 --- a/src/Internal/Returns/FutureBoundedReturnListener.php +++ b/src/Internal/Returns/FutureBoundedReturnListener.php @@ -30,7 +30,7 @@ public function __construct( private readonly DeliverySupervisor $supervisor, ?\Closure $mandatoryIdGenerator = null, ) { - $this->mandatoryIdGenerator = $mandatoryIdGenerator ?: static fn(): string => bin2hex(random_bytes(10)); + $this->mandatoryIdGenerator = $mandatoryIdGenerator ?? static fn(): string => bin2hex(random_bytes(10)); } public function listen(): void diff --git a/src/Internal/VersionProvider.php b/src/Internal/VersionProvider.php index ef8f23d..7dd34dd 100644 --- a/src/Internal/VersionProvider.php +++ b/src/Internal/VersionProvider.php @@ -11,10 +11,7 @@ */ final class VersionProvider { - /** @var non-empty-string */ private const string DEFAULT_VERSION = 'dev'; - - /** @var non-empty-string */ private const string PACKAGE_NAME = 'thesis/amqp'; /** @var ?non-empty-string */ @@ -25,13 +22,24 @@ final class VersionProvider */ public static function provide(): string { - return self::$version ??= (static function (): string { - $version = self::DEFAULT_VERSION; - if (InstalledVersions::isInstalled(self::PACKAGE_NAME) && ($prettyVersion = InstalledVersions::getPrettyVersion(self::PACKAGE_NAME)) !== null) { - $version = $prettyVersion ?: self::DEFAULT_VERSION; - } - - return $version; - })(); + return self::$version ??= self::doProvide(); + } + + /** @return non-empty-string */ + private static function doProvide(): string + { + if (!InstalledVersions::isInstalled(self::PACKAGE_NAME)) { + return self::DEFAULT_VERSION; + } + + $prettyVersion = InstalledVersions::getPrettyVersion(self::PACKAGE_NAME); + + if ($prettyVersion !== null && $prettyVersion !== '') { + return $prettyVersion; + } + + return self::DEFAULT_VERSION; } + + private function __construct() {} } diff --git a/src/PublishConfirmation.php b/src/PublishConfirmation.php index 6da0973..2970fbe 100644 --- a/src/PublishConfirmation.php +++ b/src/PublishConfirmation.php @@ -74,7 +74,7 @@ public function await(?Cancellation $cancellation = null): PublishResult try { return $this->result = Future\awaitFirst($futures, $cancellation); - } catch (MessageCannotBeRouted) { // @phpstan-ignore-line + } catch (MessageCannotBeRouted) { // @phpstan-ignore catch.neverThrown return $this->result = PublishResult::Unrouted; } finally { /** @phpstan-ignore argument.type */ diff --git a/src/Rpc.php b/src/Rpc.php index 0201166..c0fcc63 100644 --- a/src/Rpc.php +++ b/src/Rpc.php @@ -18,8 +18,8 @@ final class Rpc /** @var ?Sync\Once */ private ?Sync\Once $channel = null; - /** @var non-empty-string */ - private string $replyTo; + /** @var ?non-empty-string */ + private ?string $replyTo = null; /** @var array> */ private array $futures = []; @@ -101,7 +101,12 @@ private function createMessage(Message $message, string $correlationId): Message private function channel(?Cancellation $cancellation = null): Channel { - return ($this->channel ??= new Sync\Once(weakClosure($this->setup(...)), static fn(Channel $channel): bool => !$channel->isClosed()))->await($cancellation); + $this->channel ??= new Sync\Once( + weakClosure($this->setup(...)), + static fn(Channel $channel): bool => !$channel->isClosed(), + ); + + return $this->channel->await($cancellation); } private function setup(): Channel diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 16ce159..f9667d6 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -16,13 +16,13 @@ final class ClientTest extends TestCase #[DoesNotPerformAssertions] public function testDisconnectDoesNotThrowIfClientIsNotConnected(): void { - $client = $this->createClient(); + $client = self::createClient(); $client->disconnect(); } public function testConnectDisconnectExplicit(): void { - $client = $this->createClient(); + $client = self::createClient(); $channel = $client->channel(); $client->disconnect(); @@ -36,7 +36,7 @@ public function testClientGarbageCollection(): void try { gc_disable(); - $client = $this->createClient(); + $client = self::createClient(); $channel = $client->channel(); $weakClient = \WeakReference::create($client); $weakChannel = \WeakReference::create($channel); @@ -58,7 +58,7 @@ public function testClosedChannelGarbageCollection(): void try { gc_disable(); - $client = $this->createClient(); + $client = self::createClient(); $channel = $client->channel(); $weakChannel = \WeakReference::create($channel); $channel->close(); @@ -76,7 +76,7 @@ public function testClosedChannelGarbageCollection(): void #[RequiresPhp('8.4')] public function testConnectDisconnectOnDestructor(): void { - $client = $this->createClient(); + $client = self::createClient(); $channel = $client->channel(); unset($client); diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index aba97b2..43164b9 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -124,8 +124,8 @@ public function testMaxQueryParameters(): void public function testZeroQueryParameters(): void { $config = Config::fromURI('amqps://foo.bar/test?channel_max=0&frame_max=0&heartbeat=0&connection_timeout=0'); - self::assertSame(0xFFFF, $config->channelMax); - self::assertSame(0xFFFF, $config->frameMax); + self::assertSame(0, $config->channelMax); + self::assertSame(0, $config->frameMax); self::assertSame(0, $config->heartbeat); self::assertEquals(10, $config->connectionTimeout); } diff --git a/tests/Internal/ConsumerTagGeneratorTest.php b/tests/Internal/ConsumerTagGeneratorTest.php index 2c4559d..77c8f2a 100644 --- a/tests/Internal/ConsumerTagGeneratorTest.php +++ b/tests/Internal/ConsumerTagGeneratorTest.php @@ -5,6 +5,7 @@ namespace Thesis\Amqp\Internal; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use Thesis\Amqp\Internal\Delivery\ConsumerTagGenerator; @@ -18,17 +19,23 @@ final class ConsumerTagGeneratorTest extends TestCase #[TestWith([[], 'ctag-thesis/amqp-1'])] #[TestWith([['/kafkiansky/amqp/vendor/bin/phpunit'], 'ctag-/kafkiansky/amqp/vendor/bin/phpunit-1'])] #[TestWith([[''], 'ctag-thesis/amqp-1'])] - public function testNext(array $argv, string $tag): void + #[RunInSeparateProcess] + public function testNext(array $argv, string $expected): void { $_SERVER['argv'] = $argv; $gen = new ConsumerTagGenerator(); - self::assertSame($tag, $gen->next()); + + $tag = $gen->next(); + + self::assertSame($expected, $tag); } + #[RunInSeparateProcess] public function testSelect(): void { $_SERVER['argv'] = []; $gen = new ConsumerTagGenerator(); + self::assertSame('ctag-thesis/amqp-1', $gen->next()); self::assertSame('custom', $gen->select('custom')); self::assertSame('ctag-thesis/amqp-2', $gen->next());