From 7b6dc1eca500f49a17943460576e6bbf1c0b0bbf Mon Sep 17 00:00:00 2001 From: kafkiansky Date: Thu, 15 Oct 2026 19:02:43 +0300 Subject: [PATCH] Raise the minimum PHP version to 8.4 --- .env | 2 +- .github/workflows/check.yaml | 2 +- .php-cs-fixer.dist.php | 4 +-- composer.json | 2 +- examples/jetstream/message-get.php | 2 +- src/Client.php | 6 ++-- src/Description.php | 8 +----- src/Internal/Connection/Connection.php | 2 +- src/Internal/Connection/PingPongHandler.php | 6 ++-- src/Internal/Connection/SocketConnection.php | 7 +---- .../Connection/SocketConnectionFactory.php | 2 +- src/JetStream.php | 6 ++-- src/JetStream/Api/ConsumerInfoCollection.php | 5 ---- src/JetStream/Api/ConsumerNamesCollection.php | 5 ---- src/JetStream/Api/PaginatedResponse.php | 4 +-- src/JetStream/Api/Router.php | 16 ++--------- src/JetStream/Api/StreamInfoCollection.php | 5 ---- src/JetStream/Api/StreamNamesCollection.php | 5 ---- src/JetStream/KeyValue/Bucket.php | 6 ++-- .../KeyValue/Internal/EntryCollector.php | 10 +------ src/JetStream/Metadata.php | 2 +- src/JetStream/ObjectStore/Store.php | 6 ++-- src/Message.php | 2 +- src/Serialization/ValinorSerializer.php | 2 +- tests/HeadersTest.php | 2 +- .../Connection/PingPongHandlerTest.php | 3 +- tests/Internal/Protocol/ErrTest.php | 10 +++---- tests/JetStream/Api/Result/ErrorTest.php | 2 +- tests/JetStream/Api/StreamConfigTest.php | 2 +- tests/JetStream/KeyValue/KeyValueTest.php | 2 +- tests/JetStream/PullConsumerTest.php | 2 +- tests/JetStreamTest.php | 28 +++++++++---------- tests/NatsTestCase.php | 4 +-- tests/PublishOptionsTest.php | 10 +++---- tests/RequestTest.php | 2 +- tests/SubscriptionTest.php | 2 +- 36 files changed, 69 insertions(+), 117 deletions(-) diff --git a/.env b/.env index bc024b6..7cf1cee 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ # Put env variables defaults here # Override locally in gitignored .env.local -PHP_IMAGE_VERSION=8.3 +PHP_IMAGE_VERSION=8.4 diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 069a2c3..a7d7bb1 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -28,7 +28,7 @@ jobs: strategy: &strategy fail-fast: false matrix: - php: [ 8.3, 8.4, 8.5 ] + php: [ 8.4, 8.5 ] deps: [ lowest, highest ] steps: - uses: actions/checkout@v6 diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7fa8943..b4390e8 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -7,7 +7,7 @@ use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; use PHPyh\CodingStandard\PhpCsFixerCodingStandard; -$config = (new Config()) +$config = new Config() ->setFinder( Finder::create() ->in(__DIR__ . '/examples') @@ -20,7 +20,7 @@ ->setParallelConfig(ParallelConfigFactory::detect()) ->setCacheFile(__DIR__ . '/var/' . basename(__FILE__) . '.cache'); -(new PhpCsFixerCodingStandard())->applyTo($config, [ +new PhpCsFixerCodingStandard()->applyTo($config, [ 'numeric_literal_separator' => false, ]); diff --git a/composer.json b/composer.json index 47aea4a..eff7c9a 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": "^8.3", + "php": "^8.4", "ext-filter": "*", "amphp/amp": "^3.1.1", "amphp/byte-stream": "^2.1", diff --git a/examples/jetstream/message-get.php b/examples/jetstream/message-get.php index 6acc636..e09ab26 100644 --- a/examples/jetstream/message-get.php +++ b/examples/jetstream/message-get.php @@ -21,7 +21,7 @@ subject: 'events.activated', message: new Nats\Message( payload: 'Message', - headers: (new Nats\Headers()) + headers: new Nats\Headers() ->with(Nats\Header\ScalarKey::string('x'), 'y'), ), ); diff --git a/src/Client.php b/src/Client.php index 24e7371..819edec 100644 --- a/src/Client.php +++ b/src/Client.php @@ -819,14 +819,14 @@ private function connection(?Cancellation $cancellation = null): Connection\Conn /** @var ?\Throwable $reason the fatal server error that closed the connection */ $reason = null; - $connection->hooks()->onMessage($this->invokeSubscriber(...)); - $connection->hooks()->onError(function (Hooks\ErrorReceived $event) use ( + $connection->hooks->onMessage($this->invokeSubscriber(...)); + $connection->hooks->onError(function (Hooks\ErrorReceived $event) use ( $connection, &$reason, ): void { $reason ??= $this->handleError($event, $connection); }); - $connection->hooks()->onClose(function () use ( + $connection->hooks->onClose(function () use ( $connection, &$reason, ): void { diff --git a/src/Description.php b/src/Description.php index fd22515..d37e99b 100644 --- a/src/Description.php +++ b/src/Description.php @@ -49,13 +49,7 @@ public function is(string ...$values): bool */ public function startsWith(string ...$prefixes): bool { - foreach ($prefixes as $prefix) { - if (str_starts_with($this->value, $prefix)) { - return true; - } - } - - return false; + return array_any($prefixes, fn(string $prefix): bool => str_starts_with($this->value, $prefix)); } /** diff --git a/src/Internal/Connection/Connection.php b/src/Internal/Connection/Connection.php index c038bf3..081ce48 100644 --- a/src/Internal/Connection/Connection.php +++ b/src/Internal/Connection/Connection.php @@ -22,7 +22,7 @@ interface Connection */ public function execute(Protocol\Frame|array $frames, ?Cancellation $cancellation = null): void; - public function hooks(): Hooks\Provider; + public Hooks\Provider $hooks { get; } /** * @throws NatsException diff --git a/src/Internal/Connection/PingPongHandler.php b/src/Internal/Connection/PingPongHandler.php index bbc1041..166ba6e 100644 --- a/src/Internal/Connection/PingPongHandler.php +++ b/src/Internal/Connection/PingPongHandler.php @@ -39,15 +39,15 @@ public function startup(int $interval, int $maxPings): void $this->connection->execute(Protocol\Ping::Frame); }); - $this->connection->hooks()->onPing(function (): void { + $this->connection->hooks->onPing(function (): void { $this->connection->execute(Protocol\Pong::Frame); }); - $this->connection->hooks()->onPong(function (): void { + $this->connection->hooks->onPong(function (): void { $this->pings = 0; }); - $this->connection->hooks()->onClose($this->stop(...)); + $this->connection->hooks->onClose($this->stop(...)); } public function stop(): void diff --git a/src/Internal/Connection/SocketConnection.php b/src/Internal/Connection/SocketConnection.php index 4fc1372..8296575 100644 --- a/src/Internal/Connection/SocketConnection.php +++ b/src/Internal/Connection/SocketConnection.php @@ -30,7 +30,7 @@ final class SocketConnection implements Connection /** @var \SplQueue> */ private readonly \SplQueue $queue; - private readonly Hooks\ConcurrentProvider $hooks; + public readonly Hooks\ConcurrentProvider $hooks; private readonly PingPongHandler $pingpongs; @@ -163,11 +163,6 @@ public function execute(Protocol\Frame|array $frames, ?Cancellation $cancellatio } } - public function hooks(): Hooks\Provider - { - return $this->hooks; - } - public function info(): ConnectionInfo { return $this->info ?? throw new ConnectionIsNotAvailable(); diff --git a/src/Internal/Connection/SocketConnectionFactory.php b/src/Internal/Connection/SocketConnectionFactory.php index f8cca41..91c07a2 100644 --- a/src/Internal/Connection/SocketConnectionFactory.php +++ b/src/Internal/Connection/SocketConnectionFactory.php @@ -25,7 +25,7 @@ private function __construct( public static function fromConfig(Config $config): self { - $context = (new ConnectContext()) + $context = new ConnectContext() ->withConnectTimeout($config->connectionTimeout); if ($config->tcpNoDelay) { diff --git a/src/JetStream.php b/src/JetStream.php index 3a5b45c..385f480 100644 --- a/src/JetStream.php +++ b/src/JetStream.php @@ -630,7 +630,7 @@ public function createOrUpdateCounter(Counter\CounterConfig $config): Counter\Co prefix: $prefix = "\$CNT.{$config->name}.", publishPrefix: $this->publishPrefix( prefix: $prefix, - jsPrefix: $this->router->prefix() !== Api\Router::DEFAULT_PREFIX ? $this->router->prefix() : null, + jsPrefix: $this->router->prefix !== Api\Router::DEFAULT_PREFIX ? $this->router->prefix : null, ), ); } @@ -786,7 +786,7 @@ private function keyValueStreamConfig(KeyValue\BucketConfig $config): Api\Stream */ private function setupKeyValue(string $bucket, JetStream\Stream $stream): KeyValue\Bucket { - $jsPrefix = $this->router->prefix() !== Api\Router::DEFAULT_PREFIX ? $this->router->prefix() : ''; + $jsPrefix = $this->router->prefix !== Api\Router::DEFAULT_PREFIX ? $this->router->prefix : ''; $prefix = "\$KV.{$bucket}."; $putPrefix = "{$jsPrefix}{$prefix}"; @@ -914,7 +914,7 @@ private function paginatedRequest(Api\PaginatedRequest $request): iterable $offset += \count($response); - if ($offset >= $response->total()) { + if ($offset >= $response->total) { break; } } diff --git a/src/JetStream/Api/ConsumerInfoCollection.php b/src/JetStream/Api/ConsumerInfoCollection.php index 5606301..cee5e84 100644 --- a/src/JetStream/Api/ConsumerInfoCollection.php +++ b/src/JetStream/Api/ConsumerInfoCollection.php @@ -23,11 +23,6 @@ public function __construct( public ?array $consumers = null, ) {} - public function total(): int - { - return $this->total; - } - public function getIterator(): \Traversable { yield from $this->consumers ?? []; diff --git a/src/JetStream/Api/ConsumerNamesCollection.php b/src/JetStream/Api/ConsumerNamesCollection.php index a179dba..9b91637 100644 --- a/src/JetStream/Api/ConsumerNamesCollection.php +++ b/src/JetStream/Api/ConsumerNamesCollection.php @@ -23,11 +23,6 @@ public function __construct( public ?array $consumers = null, ) {} - public function total(): int - { - return $this->total; - } - public function getIterator(): \Traversable { yield from $this->consumers ?? []; diff --git a/src/JetStream/Api/PaginatedResponse.php b/src/JetStream/Api/PaginatedResponse.php index 5c32a44..a891f5b 100644 --- a/src/JetStream/Api/PaginatedResponse.php +++ b/src/JetStream/Api/PaginatedResponse.php @@ -14,7 +14,7 @@ interface PaginatedResponse extends \Countable { /** - * @return non-negative-int + * @var non-negative-int */ - public function total(): int; + public int $total { get; } } diff --git a/src/JetStream/Api/Router.php b/src/JetStream/Api/Router.php index 9ef2a2b..15869ef 100644 --- a/src/JetStream/Api/Router.php +++ b/src/JetStream/Api/Router.php @@ -7,29 +7,19 @@ /** * @internal */ -final class Router +final readonly class Router { public const string DEFAULT_PREFIX = '$JS.API.'; /** @var non-empty-string */ - private string $prefix = self::DEFAULT_PREFIX; + public string $prefix; /** * @param ?non-empty-string $domain */ public function __construct(?string $domain = null) { - if ($domain !== null) { - $this->prefix = substr_replace($this->prefix, "\$JS.{$domain}.API.", 0); - } - } - - /** - * @return non-empty-string - */ - public function prefix(): string - { - return $this->prefix; + $this->prefix = $domain !== null ? "\$JS.{$domain}.API." : self::DEFAULT_PREFIX; } /** diff --git a/src/JetStream/Api/StreamInfoCollection.php b/src/JetStream/Api/StreamInfoCollection.php index 4ecfad5..6d35bbe 100644 --- a/src/JetStream/Api/StreamInfoCollection.php +++ b/src/JetStream/Api/StreamInfoCollection.php @@ -23,11 +23,6 @@ public function __construct( public ?array $streams = null, ) {} - public function total(): int - { - return $this->total; - } - public function getIterator(): \Traversable { yield from $this->streams ?? []; diff --git a/src/JetStream/Api/StreamNamesCollection.php b/src/JetStream/Api/StreamNamesCollection.php index 56b4770..c7a7c61 100644 --- a/src/JetStream/Api/StreamNamesCollection.php +++ b/src/JetStream/Api/StreamNamesCollection.php @@ -23,11 +23,6 @@ public function __construct( public ?array $streams = null, ) {} - public function total(): int - { - return $this->total; - } - public function getIterator(): \Traversable { yield from $this->streams ?? []; diff --git a/src/JetStream/KeyValue/Bucket.php b/src/JetStream/KeyValue/Bucket.php index ae4b3cc..065d5ae 100644 --- a/src/JetStream/KeyValue/Bucket.php +++ b/src/JetStream/KeyValue/Bucket.php @@ -160,7 +160,7 @@ public function delete(string $key, ?int $revision = null): void $this->publish( $key, new Message( - headers: (new Headers()) + headers: new Headers() ->with(Header\KvOperation::header(), Header\KvOperation::OP_DEL), ), new PublishOptions(expectedLastSubjectSequence: $revision), @@ -180,7 +180,7 @@ public function purge( $this->publish( $key, new Message( - headers: (new Headers()) + headers: new Headers() ->with(Header\KvOperation::header(), Header\KvOperation::OP_PURGE) ->with(Header\MsgRollup::header(), Header\MsgRollup::ROLLUP_SUBJECT), ), @@ -294,7 +294,7 @@ private function initialEntries(string|array $filters, WatchConfig $config, ?Can } } - return $entries->entries(); + return $entries->entries; } /** diff --git a/src/JetStream/KeyValue/Internal/EntryCollector.php b/src/JetStream/KeyValue/Internal/EntryCollector.php index 48119bd..2eb1d7b 100644 --- a/src/JetStream/KeyValue/Internal/EntryCollector.php +++ b/src/JetStream/KeyValue/Internal/EntryCollector.php @@ -14,18 +14,10 @@ final class EntryCollector { /** @var list */ - private array $entries = []; + public private(set) array $entries = []; public function __invoke(Entry $entry): void { $this->entries[] = $entry; } - - /** - * @return list - */ - public function entries(): array - { - return $this->entries; - } } diff --git a/src/JetStream/Metadata.php b/src/JetStream/Metadata.php index c523316..808ea69 100644 --- a/src/JetStream/Metadata.php +++ b/src/JetStream/Metadata.php @@ -75,7 +75,7 @@ public static function parse(string $subject): self delivered: (int) $tokens[4], streamSequence: (int) $tokens[5], consumerSequence: (int) $tokens[6], - timestamp: (new \DateTimeImmutable())->setTimestamp( + timestamp: new \DateTimeImmutable()->setTimestamp( TimeSpan::fromNanoseconds((int) $tokens[7])->toSeconds(), ), pending: (int) $tokens[8], diff --git a/src/JetStream/ObjectStore/Store.php b/src/JetStream/ObjectStore/Store.php index 1505b46..7539838 100644 --- a/src/JetStream/ObjectStore/Store.php +++ b/src/JetStream/ObjectStore/Store.php @@ -172,7 +172,7 @@ public function put(ObjectMeta $meta, Reader|string $object): ObjectInfo subject: $subject, message: new Message( payload: $this->json->encode($objectInfo), - headers: (new Headers()) + headers: new Headers() ->with(MsgRollup::header(), MsgRollup::ROLLUP_SUBJECT), ), ); @@ -204,7 +204,7 @@ public function delete(string $name): void subject: "\$O.{$info->bucket}.M." . self::base64encode($info->name), message: new Message( payload: $this->json->encode($info), - headers: (new Headers()) + headers: new Headers() ->with(MsgRollup::header(), MsgRollup::ROLLUP_SUBJECT), ), ); @@ -313,7 +313,7 @@ public function addLink(string $name, ObjectInfo $object): ObjectInfo subject: "\$O.{$info->bucket}.M." . self::base64encode($info->name), message: new Message( payload: $this->json->encode($info->withoutTime()), - headers: (new Headers()) + headers: new Headers() ->with(MsgRollup::header(), MsgRollup::ROLLUP_SUBJECT), ), ); diff --git a/src/Message.php b/src/Message.php index 84147f6..64ffd3a 100644 --- a/src/Message.php +++ b/src/Message.php @@ -19,7 +19,7 @@ public function __construct( public static function incr(int $value): self { return new self( - headers: (new Headers()) + headers: new Headers() ->with(Incr::Header, $value), ); } diff --git a/src/Serialization/ValinorSerializer.php b/src/Serialization/ValinorSerializer.php index b29430a..c07d912 100644 --- a/src/Serialization/ValinorSerializer.php +++ b/src/Serialization/ValinorSerializer.php @@ -23,7 +23,7 @@ */ public function __construct(?string $cachePath = null, bool $debug = false) { - $builder = (new MapperBuilder()) + $builder = new MapperBuilder() ->allowSuperfluousKeys() ->registerConstructor( TimeSpan::fromNanoseconds(...), diff --git a/tests/HeadersTest.php b/tests/HeadersTest.php index 0861273..166c601 100644 --- a/tests/HeadersTest.php +++ b/tests/HeadersTest.php @@ -68,7 +68,7 @@ public function testHeaders(): void public function testSequenceHeaders(): void { - $headers = (new Headers()) + $headers = new Headers() ->with(Header\LastSequence::Header, 10) ->with(Header\UpToSequence::Header, 20); diff --git a/tests/Internal/Connection/PingPongHandlerTest.php b/tests/Internal/Connection/PingPongHandlerTest.php index 5ce6a8f..cc68935 100644 --- a/tests/Internal/Connection/PingPongHandlerTest.php +++ b/tests/Internal/Connection/PingPongHandlerTest.php @@ -5,6 +5,7 @@ namespace Thesis\Nats\Internal\Connection; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\MockObject\Runtime\PropertyHook; use PHPUnit\Framework\TestCase; use Thesis\Nats\Internal\Hooks\ConcurrentProvider; use Thesis\Nats\Internal\Hooks\PingReceived; @@ -21,7 +22,7 @@ public function testPingPong(): void $connection = $this->createMock(Connection::class); $connection - ->method('hooks') + ->method(PropertyHook::get('hooks')) ->willReturn($provider); $connection diff --git a/tests/Internal/Protocol/ErrTest.php b/tests/Internal/Protocol/ErrTest.php index 6be93eb..20e86f9 100644 --- a/tests/Internal/Protocol/ErrTest.php +++ b/tests/Internal/Protocol/ErrTest.php @@ -25,19 +25,19 @@ final class ErrTest extends TestCase #[TestWith(['Authorization Violation', null])] public function testViolatedSubscription(string $message, ?array $subscription): void { - self::assertSame($subscription, (new Err($message))->violatedSubscription()); + self::assertSame($subscription, new Err($message)->violatedSubscription()); } public function testToException(): void { - self::assertInstanceOf(AuthorizationViolation::class, (new Err('Authorization Violation'))->toException()); - self::assertInstanceOf(MaximumPayloadViolation::class, (new Err('Maximum Payload Violation'))->toException()); + self::assertInstanceOf(AuthorizationViolation::class, new Err('Authorization Violation')->toException()); + self::assertInstanceOf(MaximumPayloadViolation::class, new Err('Maximum Payload Violation')->toException()); - $e = (new Err('Permissions Violation for Publish to "events.happens"'))->toException(); + $e = new Err('Permissions Violation for Publish to "events.happens"')->toException(); self::assertInstanceOf(PermissionViolated::class, $e); self::assertSame('Permissions Violation for Publish to "events.happens"', $e->getMessage()); - $e = (new Err('Something Unexpected'))->toException(); + $e = new Err('Something Unexpected')->toException(); self::assertInstanceOf(\RuntimeException::class, $e); self::assertSame('Something Unexpected', $e->getMessage()); } diff --git a/tests/JetStream/Api/Result/ErrorTest.php b/tests/JetStream/Api/Result/ErrorTest.php index 5f953c4..ad9192d 100644 --- a/tests/JetStream/Api/Result/ErrorTest.php +++ b/tests/JetStream/Api/Result/ErrorTest.php @@ -38,7 +38,7 @@ final class ErrorTest extends TestCase #[DataProvider('provideExceptionCases')] public function testException(int $code, int $errCode, string $class): void { - $e = (new Error($code, $errCode, 'description'))->exception(); + $e = new Error($code, $errCode, 'description')->exception(); self::assertSame($class, $e::class); self::assertSame($code, $e->getCode()); diff --git a/tests/JetStream/Api/StreamConfigTest.php b/tests/JetStream/Api/StreamConfigTest.php index 7af64da..5df34d7 100644 --- a/tests/JetStream/Api/StreamConfigTest.php +++ b/tests/JetStream/Api/StreamConfigTest.php @@ -51,6 +51,6 @@ public function testInvalidSourceFilter(): void public function testEmptySourceFilterMeansNone(): void { - self::assertSame('', (new StreamSource('SOURCE', filterSubject: ''))->filterSubject); + self::assertSame('', new StreamSource('SOURCE', filterSubject: '')->filterSubject); } } diff --git a/tests/JetStream/KeyValue/KeyValueTest.php b/tests/JetStream/KeyValue/KeyValueTest.php index 40d1553..3ba9aae 100644 --- a/tests/JetStream/KeyValue/KeyValueTest.php +++ b/tests/JetStream/KeyValue/KeyValueTest.php @@ -1092,7 +1092,7 @@ public function testWatchConfigRejectsConflictingOptions(): void } } - self::assertTrue((new WatchConfig(includeHistory: true, resumeFromRevision: 1))->includeHistory); + self::assertTrue(new WatchConfig(includeHistory: true, resumeFromRevision: 1)->includeHistory); } /** diff --git a/tests/JetStream/PullConsumerTest.php b/tests/JetStream/PullConsumerTest.php index fbe3539..14e8d49 100644 --- a/tests/JetStream/PullConsumerTest.php +++ b/tests/JetStream/PullConsumerTest.php @@ -364,7 +364,7 @@ public function testConsumePullsAgainAfterServerDroppedPullRequests(Status $stat if (++$pulls === 1) { \assert($delivery->replyTo !== null); - $nc->publish($delivery->replyTo, new Message(headers: (new Headers()) + $nc->publish($delivery->replyTo, new Message(headers: new Headers() ->with(StatusCode::Header, $status) ->with(StatusDescription::Header, new Description($description)))); } elseif (!$repulled->isComplete()) { diff --git a/tests/JetStreamTest.php b/tests/JetStreamTest.php index 1dc79dc..8f3afb0 100644 --- a/tests/JetStreamTest.php +++ b/tests/JetStreamTest.php @@ -449,7 +449,7 @@ public function testPauseResumeConsumer(): void $consumer = $stream->createConsumer(new ConsumerConfig(durableName: generateUniqueId(10), ackPolicy: AckPolicy::Explicit)); - $until = (new \DateTimeImmutable())->add(new \DateInterval('P1D')); + $until = new \DateTimeImmutable()->add(new \DateInterval('P1D')); $response = $consumer->pause($until); @@ -561,7 +561,7 @@ public function testPublishWrongLastStreamSequence(): void try { self::expectException(WrongLastSequence::class); $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(ExpectedLastSeq::Header, 1), )); } finally { @@ -589,7 +589,7 @@ public function testPublishWrongLastSubjectSequence(): void try { self::expectException(WrongLastSequence::class); $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(ExpectedLastSubjSeq::Header, 1), )); } finally { @@ -617,7 +617,7 @@ public function testPublishWrongLastMsgId(): void try { self::expectException(WrongLastMessageId::class); $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(ExpectedLastMsgID::header(), '123'), )); } finally { @@ -645,7 +645,7 @@ public function testPublishStreamDoesNotMatch(): void try { self::expectException(StreamDoesNotMatch::class); $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(ExpectedStream::header(), 'xxx'), )); } finally { @@ -667,7 +667,7 @@ public function testPublishMsgExpired(): void )); $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(MsgTtl::Header, TimeSpan::fromSeconds(1)), )); @@ -692,7 +692,7 @@ public function testPublishDuplicate(): void )); $response = $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(MsgId::header(), '123'), )); @@ -701,7 +701,7 @@ public function testPublishDuplicate(): void for ($i = 0; $i < 5; ++$i) { $response = $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(MsgId::header(), '123'), )); @@ -710,7 +710,7 @@ public function testPublishDuplicate(): void } $response = $js->publish("{$subject}.xxx", new Message( - headers: (new Headers()) + headers: new Headers() ->with(MsgId::header(), '124'), )); @@ -792,7 +792,7 @@ public function testPublishOptionsOverrideHeaders(): void try { $ack = $js->publish( "{$subject}.a", - new Message(headers: (new Headers())->with(ExpectedStream::header(), 'xxx')), + new Message(headers: new Headers()->with(ExpectedStream::header(), 'xxx')), new PublishOptions(expectedStream: $name), ); @@ -955,7 +955,7 @@ public function testPublishConsume(): void $response = $js->publish("{$subject}.xxx", new Message( payload: $payload, - headers: (new Headers()) + headers: new Headers() ->with(MsgId::header(), "id:{$i}"), )); @@ -1004,7 +1004,7 @@ public function testPublishGet(): void for ($i = 0; $i < 2; ++$i) { $js->publish($publishSubject, new Message( payload: "Message#{$i}", - headers: (new Headers()) + headers: new Headers() ->with(MsgId::header(), "id:{$i}"), )); } @@ -1104,7 +1104,7 @@ public function testScheduleSingleMessage(): void $js->publish('scheduler.recurrents.1', new Message( payload: '{"id":1}', - headers: (new Headers()) + headers: new Headers() ->with(Header\Schedule::Header, new \DateTimeImmutable('+2 seconds')) ->with(Header\ScheduleTarget::header(), 'recurrents'), )); @@ -1151,7 +1151,7 @@ public function testScheduleHeaderDecodedFromStoredMessage(): void $js->publish("{$subject}.schedules.1", new Message( payload: '{"id":1}', - headers: (new Headers()) + headers: new Headers() ->with(Header\Schedule::Header, $at) ->with(Header\ScheduleTarget::header(), $subject), )); diff --git a/tests/NatsTestCase.php b/tests/NatsTestCase.php index fa22209..b9bc1d4 100644 --- a/tests/NatsTestCase.php +++ b/tests/NatsTestCase.php @@ -146,13 +146,13 @@ final protected function kick(string $name): void final protected static function pendingRequests(Client $client): int { /** @var ?Future $rpc */ - $rpc = (new \ReflectionProperty(Client::class, 'rpc'))->getValue($client); + $rpc = new \ReflectionProperty(Client::class, 'rpc')->getValue($client); if ($rpc === null) { return 0; } /** @var array $pendings */ - $pendings = (new \ReflectionProperty(Rpc\Handler::class, 'pendings'))->getValue($rpc->await()); + $pendings = new \ReflectionProperty(Rpc\Handler::class, 'pendings')->getValue($rpc->await()); return \count($pendings); } diff --git a/tests/PublishOptionsTest.php b/tests/PublishOptionsTest.php index 41d0a01..4ca7f73 100644 --- a/tests/PublishOptionsTest.php +++ b/tests/PublishOptionsTest.php @@ -33,7 +33,7 @@ public function testDefaults(): void public function testApplySetsHeaders(): void { - $headers = (new PublishOptions( + $headers = new PublishOptions( msgId: 'id-1', expectedStream: 'orders', expectedLastSequence: 10, @@ -41,7 +41,7 @@ public function testApplySetsHeaders(): void expectedLastSubjectSequenceSubject: 'orders.*', expectedLastMsgId: 'id-0', ttl: TimeSpan::fromMinutes(1), - ))->apply(null); + )->apply(null); self::assertNotNull($headers); self::assertSame('id-1', $headers->get(MsgId::header())); @@ -57,8 +57,8 @@ public function testApplyReplacesHeadersAndKeepsOthers(): void { $custom = ScalarKey::string('X-Custom'); - $headers = (new PublishOptions(msgId: 'from-options'))->apply( - (new Headers()) + $headers = new PublishOptions(msgId: 'from-options')->apply( + new Headers() ->with(MsgId::header(), 'by-hand') ->with($custom, 'value'), ); @@ -70,7 +70,7 @@ public function testApplyReplacesHeadersAndKeepsOthers(): void public function testNeverExpiringTtl(): void { - $headers = (new PublishOptions(ttl: TimeSpan::fromSeconds(-1)))->apply(null); + $headers = new PublishOptions(ttl: TimeSpan::fromSeconds(-1))->apply(null); self::assertNotNull($headers); self::assertSame(-1, $headers->get(MsgTtl::Header)?->toSeconds()); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index ea69259..3faf1b4 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -375,6 +375,6 @@ private static function payloads(iterable $deliveries): array private static function subscribers(Client $client): array { /** @var array */ - return (new \ReflectionProperty(Client::class, 'subscribers'))->getValue($client); + return new \ReflectionProperty(Client::class, 'subscribers')->getValue($client); } } diff --git a/tests/SubscriptionTest.php b/tests/SubscriptionTest.php index 8cf859c..7c94652 100644 --- a/tests/SubscriptionTest.php +++ b/tests/SubscriptionTest.php @@ -283,6 +283,6 @@ private static function waitFor(\Closure $condition, float $timeout = 5): void private static function subscribers(Client $client): array { /** @var array */ - return (new \ReflectionProperty(Client::class, 'subscribers'))->getValue($client); + return new \ReflectionProperty(Client::class, 'subscribers')->getValue($client); } }