diff --git a/README.md b/README.md index 84e554fb..942e4155 100644 --- a/README.md +++ b/README.md @@ -58,18 +58,18 @@ final class DownloadFileMessage extends Message public readonly string $destinationPath, ) {} - public static function fromData(string $type, bool|int|float|string|array|null $data): static + public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static { if ($type !== self::TYPE) { throw new \InvalidArgumentException("Expected type \"" . self::TYPE . "\", got \"$type\"."); } - if (!is_array($data) - || !is_string($data['url'] ?? null) - || !is_string($data['destinationPath'] ?? null) + if (!is_array($payload) + || !is_string($payload['url'] ?? null) + || !is_string($payload['destinationPath'] ?? null) ) { throw new \InvalidArgumentException('Invalid data for ' . self::class . '.'); } - return new self($data['url'], $data['destinationPath']); + return new self($payload['url'], $payload['destinationPath']); } public function getType(): string @@ -77,7 +77,7 @@ final class DownloadFileMessage extends Message return self::TYPE; } - public function getData(): array + public function getPayload(): array { return ['url' => $this->url, 'destinationPath' => $this->destinationPath]; } diff --git a/docs/guide/en/best-practices.md b/docs/guide/en/best-practices.md index 5f7c864f..76d17124 100644 --- a/docs/guide/en/best-practices.md +++ b/docs/guide/en/best-practices.md @@ -13,7 +13,7 @@ final class ProcessPaymentHandler implements MessageHandlerInterface { public function handle(MessageInterface $message): void { - $paymentId = $message->getData()['paymentId']; + $paymentId = $message->getPayload()['paymentId']; // Always processes payment, even if already done $this->paymentService->process($paymentId); @@ -28,7 +28,7 @@ final class ProcessPaymentHandler implements MessageHandlerInterface { public function handle(MessageInterface $message): void { - $paymentId = $message->getData()['paymentId']; + $paymentId = $message->getPayload()['paymentId']; // Check if already processed if ($this->paymentRepository->isProcessed($paymentId)) { @@ -64,7 +64,7 @@ final class ProcessPaymentHandler implements MessageHandlerInterface public function handle(MessageInterface $message): void { - $paymentId = $message->getData()['paymentId']; + $paymentId = $message->getPayload()['paymentId']; // State leaks between messages and grows over time if (isset($this->processedIds[$paymentId])) { @@ -84,7 +84,7 @@ final class ProcessPaymentHandler implements MessageHandlerInterface { public function handle(MessageInterface $message): void { - $paymentId = $message->getData()['paymentId']; + $paymentId = $message->getPayload()['paymentId']; // Use persistent storage for deduplication/idempotency if ($this->paymentRepository->isProcessed($paymentId)) { @@ -113,7 +113,7 @@ final class ProcessPaymentHandler implements MessageHandlerInterface public function handle(MessageInterface $message): void { try { - $this->service->process($message->getData()); + $this->service->process($message->getPayload()); } catch (\Throwable $e) { // Message is marked as processed but actually failed } @@ -125,7 +125,7 @@ public function handle(MessageInterface $message): void ```php public function handle(MessageInterface $message): void { - $this->service->process($message->getData()); + $this->service->process($message->getPayload()); // Exception will trigger failure handling } ``` @@ -278,7 +278,7 @@ final class EmailHandler implements MessageHandlerInterface public function handle(MessageInterface $message): void { $start = microtime(true); - $this->sendEmail($message->getData()); + $this->sendEmail($message->getPayload()); $this->metrics->timing('email.duration', microtime(true) - $start); } } @@ -522,10 +522,10 @@ final class ProcessPaymentHandlerTest extends TestCase ```php public function handle(MessageInterface $message): void { - $data = $message->getData(); + $payload = $message->getPayload(); // No validation - trusts all input - $this->processUser($data['userId']); + $this->processUser($payload['userId']); } ``` @@ -534,13 +534,13 @@ public function handle(MessageInterface $message): void ```php public function handle(MessageInterface $message): void { - $data = $message->getData(); + $payload = $message->getPayload(); - if (!isset($data['userId']) || !is_int($data['userId'])) { + if (!isset($payload['userId']) || !is_int($payload['userId'])) { throw new InvalidArgumentException('Invalid userId'); } - $this->processUser($data['userId']); + $this->processUser($payload['userId']); } ``` @@ -558,10 +558,10 @@ public function handle(MessageInterface $message): void ```php public function handle(MessageInterface $message): void { - $data = $message->getData(); + $payload = $message->getPayload(); // Directly using external data in SQL - $this->db->query("DELETE FROM users WHERE id = {$data['userId']}"); + $this->db->query("DELETE FROM users WHERE id = {$payload['userId']}"); } ``` @@ -570,15 +570,15 @@ public function handle(MessageInterface $message): void ```php public function handle(MessageInterface $message): void { - $data = $message->getData(); + $payload = $message->getPayload(); // Validate and sanitize - if (!isset($data['userId']) || !is_int($data['userId']) || $data['userId'] <= 0) { + if (!isset($payload['userId']) || !is_int($payload['userId']) || $payload['userId'] <= 0) { throw new InvalidArgumentException('Invalid userId'); } // Use parameterized query - $this->db->query('DELETE FROM users WHERE id = :id', ['id' => $data['userId']]); + $this->db->query('DELETE FROM users WHERE id = :id', ['id' => $payload['userId']]); } ``` diff --git a/docs/guide/en/consuming-messages-from-external-systems.md b/docs/guide/en/consuming-messages-from-external-systems.md index 27e67599..d8488749 100644 --- a/docs/guide/en/consuming-messages-from-external-systems.md +++ b/docs/guide/en/consuming-messages-from-external-systems.md @@ -38,7 +38,7 @@ External producer then always publishes `"type": "file-download"`. `Yiisoft\Queue\Message\Serializer\MessageSerializer` expects the decoded payload to be an object with these keys (with the default `JsonMessageEncoder`, the message is a JSON string): - `type` (string, required) -- `data` (any JSON value, optional; defaults to `null`) +- `payload` (any JSON value, optional; defaults to `null`) - `meta` (object, optional; defaults to `{}`) Minimal example: @@ -46,7 +46,7 @@ Minimal example: ```json { "type": "file-download", - "data": { + "payload": { "url": "https://example.com/file.pdf", "destinationFile": "/tmp/file.pdf" } @@ -58,7 +58,7 @@ Full example: ```json { "type": "file-download", - "data": { + "payload": { "url": "https://example.com/file.pdf", "destinationFile": "/tmp/file.pdf" }, @@ -76,7 +76,7 @@ The `meta` key is a general-purpose metadata container (for example, tracing, co ## 3. Data encoding rules - The payload must be UTF-8 JSON. -- `data` and `meta` must contain only JSON-encodable values: +- `payload` and `meta` must contain only JSON-encodable values: - strings, numbers, booleans, null - arrays - objects (maps) @@ -106,7 +106,7 @@ import json payload = { "type": "file-download", - "data": {"url": "https://example.com/file.pdf"} + "payload": {"url": "https://example.com/file.pdf"} } body = json.dumps(payload, ensure_ascii=False).encode("utf-8") @@ -117,7 +117,7 @@ body = json.dumps(payload, ensure_ascii=False).encode("utf-8") ```js const payload = { type: 'file-download', - data: { url: 'https://example.com/file.pdf' }, + payload: { url: 'https://example.com/file.pdf' }, }; const body = Buffer.from(JSON.stringify(payload), 'utf8'); @@ -128,6 +128,6 @@ const body = Buffer.from(JSON.stringify(payload), 'utf8'); ```sh curl -X POST \ -H 'Content-Type: application/json' \ - --data '{"type":"file-download","data":{"url":"https://example.com/file.pdf"}}' \ + --data '{"type":"file-download","payload":{"url":"https://example.com/file.pdf"}}' \ https://your-broker-gateway.example.com/publish ``` diff --git a/docs/guide/en/envelopes.md b/docs/guide/en/envelopes.md index 9751cba5..95dc29cc 100644 --- a/docs/guide/en/envelopes.md +++ b/docs/guide/en/envelopes.md @@ -9,7 +9,7 @@ An envelope implements `Yiisoft\Queue\Message\EnvelopeInterface`, which itself e An envelope is transparent to callers: it delegates the wrapped message type and data unchanged. - `getType()` is delegated to the wrapped message. -- `getData()` is delegated to the wrapped message. +- `getPayload()` is delegated to the wrapped message. Envelopes modify the metadata returned by `getMetadata()` and may provide convenience methods for accessing specific metadata entries (for example, `getId()` in an ID envelope). @@ -21,7 +21,7 @@ To wrap a message into an envelope, envelope classes provide: and, via `MessageInterface` inheritance, also support: -- `Envelope::fromData(string $type, mixed $data, array $metadata = []): static` +- `Envelope::fromPayload(string $type, mixed $payload): static` ## Built-in envelopes diff --git a/docs/guide/en/message-handler-advanced.md b/docs/guide/en/message-handler-advanced.md index 5b8be133..f6015b61 100644 --- a/docs/guide/en/message-handler-advanced.md +++ b/docs/guide/en/message-handler-advanced.md @@ -30,19 +30,19 @@ final class SendEmailMessage extends Message public readonly string $body, ) {} - public static function fromData(string $type, bool|int|float|string|array|null $data): static + public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static { if ($type !== self::TYPE) { throw new \InvalidArgumentException("Expected type \"" . self::TYPE . "\", got \"$type\"."); } - if (!is_array($data) - || !is_string($data['to'] ?? null) - || !is_string($data['subject'] ?? null) - || !is_string($data['body'] ?? null) + if (!is_array($payload) + || !is_string($payload['to'] ?? null) + || !is_string($payload['subject'] ?? null) + || !is_string($payload['body'] ?? null) ) { throw new \InvalidArgumentException('Invalid data for ' . self::class . '.'); } - return new self($data['to'], $data['subject'], $data['body']); + return new self($payload['to'], $payload['subject'], $payload['body']); } public function getType(): string @@ -50,7 +50,7 @@ final class SendEmailMessage extends Message return self::TYPE; } - public function getData(): array + public function getPayload(): array { return ['to' => $this->to, 'subject' => $this->subject, 'body' => $this->body]; } diff --git a/docs/guide/en/message-handler.md b/docs/guide/en/message-handler.md index 216dfff8..ec22d344 100644 --- a/docs/guide/en/message-handler.md +++ b/docs/guide/en/message-handler.md @@ -19,12 +19,12 @@ final class RemoteFileMessage extends Message { public function __construct(public readonly string $url) {} - public static function fromData(string $type, bool|int|float|string|array|null $data): static + public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static { - if (!is_array($data) || !is_string($data['url'] ?? null)) { + if (!is_array($payload) || !is_string($payload['url'] ?? null)) { throw new \InvalidArgumentException('Invalid data for ' . self::class . '.'); } - return new self($data['url']); + return new self($payload['url']); } public function getType(): string @@ -32,7 +32,7 @@ final class RemoteFileMessage extends Message return \App\Queue\RemoteFileHandler::class; } - public function getData(): array + public function getPayload(): array { return ['url' => $this->url]; } diff --git a/docs/guide/en/messages-and-handlers.md b/docs/guide/en/messages-and-handlers.md index 06fb88b4..60473d83 100644 --- a/docs/guide/en/messages-and-handlers.md +++ b/docs/guide/en/messages-and-handlers.md @@ -54,19 +54,19 @@ final class SendEmailMessage extends Message public readonly string $body, ) {} - public static function fromData(string $type, bool|int|float|string|array|null $data): static + public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static { if ($type !== self::TYPE) { throw new \InvalidArgumentException("Expected type \"" . self::TYPE . "\", got \"$type\"."); } - if (!is_array($data) - || !is_string($data['to'] ?? null) - || !is_string($data['subject'] ?? null) - || !is_string($data['body'] ?? null) + if (!is_array($payload) + || !is_string($payload['to'] ?? null) + || !is_string($payload['subject'] ?? null) + || !is_string($payload['body'] ?? null) ) { throw new \InvalidArgumentException('Invalid data for ' . self::class . '.'); } - return new self($data['to'], $data['subject'], $data['body']); + return new self($payload['to'], $payload['subject'], $payload['body']); } public function getType(): string @@ -74,7 +74,7 @@ final class SendEmailMessage extends Message return self::TYPE; } - public function getData(): array + public function getPayload(): array { return ['to' => $this->to, 'subject' => $this->subject, 'body' => $this->body]; } @@ -90,7 +90,7 @@ new SendEmailMessage('user@example.com', 'Welcome', 'Thank you for registering.' The message has: - A **message type** — a string used by the worker to look up the correct handler. -- A **data payload** — typed properties serialized via `getData()`. Must contain only `null`, scalars (`bool`, `int`, `float`, `string`), or arrays composed of the same types recursively. +- A **data payload** — typed properties serialized via `getPayload()`. Must contain only `null`, scalars (`bool`, `int`, `float`, `string`), or arrays composed of the same types recursively. The message has no business logic, no dependencies. It is a value object — a typed data wrapper. @@ -125,7 +125,7 @@ When the producer and consumer live in different applications (or even different ### Cross-language interoperability -Because the payload is just data, any language can produce or consume it. A Python service or a Node.js microservice can push a `{"type":"send-email","data":{…}}` JSON object and `yiisoft/queue` will process it correctly. No PHP class names appear in the serialized payload. +Because the payload is just data, any language can produce or consume it. A Python service or a Node.js microservice can push a `{"type":"send-email","payload":{…}}` JSON object and `yiisoft/queue` will process it correctly. No PHP class names appear in the serialized payload. ## Why JSON is the default serialization diff --git a/docs/guide/en/migrating-from-yii2-queue.md b/docs/guide/en/migrating-from-yii2-queue.md index 044f0f3a..38620f09 100644 --- a/docs/guide/en/migrating-from-yii2-queue.md +++ b/docs/guide/en/migrating-from-yii2-queue.md @@ -19,9 +19,9 @@ being consumed. In the new package, it is divided into two different concepts: a - A `Message` is a class implementing `MessageInterface`. It contains two types of data: - Type. The worker uses it to find the right handler for a message. - - Data. Any serializable data that should be used by the message handler. + - Payload. Any serializable data that should be used by the message handler. - All the message data is fully serializable (that means message `data` must be serializable too). It allows you to + All the message payload is fully serializable (that means message `payload` must be serializable too). It allows you to freely choose where and how to send and process messages. Both can be implemented in a single application, or separated into multiple applications, or you can do sending/processing only, leaving part of the work to another system including non-PHP ones (for example, a Go service handling CPU-intensive jobs). diff --git a/docs/guide/en/performance-tuning.md b/docs/guide/en/performance-tuning.md index 7f4eb6bb..5e58002f 100644 --- a/docs/guide/en/performance-tuning.md +++ b/docs/guide/en/performance-tuning.md @@ -81,7 +81,7 @@ See [Best practices](best-practices.md) for general message handler design guide ```php public function handle(MessageInterface $message): void { - $largeData = $this->loadLargeDataset($message->getData()['id']); + $largeData = $this->loadLargeDataset($message->getPayload()['id']); $this->processData($largeData); @@ -99,7 +99,7 @@ class Handler implements MessageHandlerInterface public function handle(MessageInterface $message): void { - self::$cache[$message->getData()['id']] = $this->load(...); + self::$cache[$message->getPayload()['id']] = $this->load(...); // Cache grows indefinitely } } @@ -111,7 +111,7 @@ class Handler implements MessageHandlerInterface public function handle(MessageInterface $message): void { - $this->cache->set($message->getData()['id'], $this->load(...)); + $this->cache->set($message->getPayload()['id'], $this->load(...)); } } ``` @@ -247,7 +247,7 @@ $queue->push(new Message(SendBulkEmailHandler::class, [ ```php public function handle(MessageInterface $message): void { - $userIds = $message->getData()['userIds']; + $userIds = $message->getPayload()['userIds']; // Process in chunks to avoid memory issues foreach (array_chunk($userIds, 100) as $chunk) { @@ -287,7 +287,7 @@ Combine multiple operations into fewer queries: ```php public function handle(MessageInterface $message): void { - foreach ($message->getData()['items'] as $item) { + foreach ($message->getPayload()['items'] as $item) { $this->db->insert('items', $item); // N queries } } @@ -298,7 +298,7 @@ public function handle(MessageInterface $message): void ```php public function handle(MessageInterface $message): void { - $this->db->batchInsert('items', $message->getData()['items']); // 1 query + $this->db->batchInsert('items', $message->getPayload()['items']); // 1 query } ``` @@ -360,7 +360,7 @@ public function handle(MessageInterface $message): void $profiler = new Profiler(); $profiler->start('database'); - $data = $this->loadData($message->getData()['id']); + $data = $this->loadData($message->getPayload()['id']); $profiler->stop('database'); $profiler->start('processing'); diff --git a/docs/guide/en/usage.md b/docs/guide/en/usage.md index 9a0908f8..ba4de48c 100644 --- a/docs/guide/en/usage.md +++ b/docs/guide/en/usage.md @@ -16,18 +16,18 @@ final class DownloadFileMessage extends Message public readonly string $destinationPath, ) {} - public static function fromData(string $type, bool|int|float|string|array|null $data): static + public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static { if ($type !== self::TYPE) { throw new \InvalidArgumentException("Expected type \"" . self::TYPE . "\", got \"$type\"."); } - if (!is_array($data) - || !is_string($data['url'] ?? null) - || !is_string($data['destinationPath'] ?? null) + if (!is_array($payload) + || !is_string($payload['url'] ?? null) + || !is_string($payload['destinationPath'] ?? null) ) { throw new \InvalidArgumentException('Invalid data for ' . self::class . '.'); } - return new self($data['url'], $data['destinationPath']); + return new self($payload['url'], $payload['destinationPath']); } public function getType(): string @@ -35,7 +35,7 @@ final class DownloadFileMessage extends Message return self::TYPE; } - public function getData(): array + public function getPayload(): array { return ['url' => $this->url, 'destinationPath' => $this->destinationPath]; } @@ -110,4 +110,4 @@ For details and edge cases, see [Message status](message-status.md). Messages are pushed in one process and consumed in another. Avoid relying on in-process state (open connections, cached objects, etc.) that may not be available in the worker process. -All data needed to handle a message must be included in the payload passed to `getData()`. +All data needed to handle a message must be included in the payload passed to `getPayload()`. diff --git a/src/Message/Envelope.php b/src/Message/Envelope.php index 513329d2..20345ca0 100644 --- a/src/Message/Envelope.php +++ b/src/Message/Envelope.php @@ -35,14 +35,14 @@ public function __construct(MessageInterface $message, array $metadata) } /** - * Envelopes cannot be created from raw data. Use {@see fromMessage()} to wrap an existing message instead. + * Envelopes cannot be created from a raw payload. Use {@see fromMessage()} to wrap an existing message instead. * * @throws LogicException Always, since this method is not supported for envelopes. */ - final public static function fromData(string $type, mixed $data): static + final public static function fromPayload(string $type, mixed $payload): static { throw new LogicException( - 'Envelopes cannot be created via "fromData()". Wrap an existing "MessageInterface" instance instead.', + 'Envelopes cannot be created via "fromPayload()". Wrap an existing "MessageInterface" instance instead.', ); } @@ -63,9 +63,9 @@ final public function getType(): string return $this->message->getType(); } - final public function getData(): bool|int|float|string|array|null + final public function getPayload(): bool|int|float|string|array|null { - return $this->message->getData(); + return $this->message->getPayload(); } /** diff --git a/src/Message/GenericMessage.php b/src/Message/GenericMessage.php index 1ea919b0..c988263b 100644 --- a/src/Message/GenericMessage.php +++ b/src/Message/GenericMessage.php @@ -9,25 +9,25 @@ * * Prefer creating custom message classes that better express your domain. * - * @psalm-import-type MessageData from MessageInterface + * @psalm-import-type MessagePayload from MessageInterface */ final class GenericMessage extends Message { /** * @param string $type A message type used to resolve the handler. - * @param bool|int|float|string|array|null $data Message payload data. Must contain only `null`, scalars (`bool`, + * @param bool|int|float|string|array|null $payload Message payload data. Must contain only `null`, scalars (`bool`, * `int`, `float`, `string`), or arrays composed of the same types recursively. * - * @psalm-param MessageData $data + * @psalm-param MessagePayload $payload */ public function __construct( private readonly string $type, - private readonly bool|int|float|string|array|null $data, + private readonly bool|int|float|string|array|null $payload, ) {} - public static function fromData(string $type, bool|int|float|string|array|null $data): MessageInterface + public static function fromPayload(string $type, bool|int|float|string|array|null $payload): MessageInterface { - return new self($type, $data); + return new self($type, $payload); } public function getType(): string @@ -35,8 +35,8 @@ public function getType(): string return $this->type; } - public function getData(): bool|int|float|string|array|null + public function getPayload(): bool|int|float|string|array|null { - return $this->data; + return $this->payload; } } diff --git a/src/Message/MessageInterface.php b/src/Message/MessageInterface.php index 8f85f976..6e32331f 100644 --- a/src/Message/MessageInterface.php +++ b/src/Message/MessageInterface.php @@ -7,7 +7,7 @@ /** * Represents a queue message with a type identifier, payload data, and metadata. * - * @psalm-type MessageData = scalar|null|array + * @psalm-type MessagePayload = scalar|null|array * @psalm-type MessageMetadata = array> */ interface MessageInterface @@ -16,12 +16,12 @@ interface MessageInterface * Creates a new message instance from the given type and payload data. * * @param string $type Message type. - * @param bool|int|float|string|array|null $data Message payload data. Must contain only `null`, scalars (`bool`, + * @param bool|int|float|string|array|null $payload Message payload data. Must contain only `null`, scalars (`bool`, * `int`, `float`, `string`), or arrays composed of the same types recursively. * - * @psalm-param MessageData $data + * @psalm-param MessagePayload $payload */ - public static function fromData(string $type, bool|int|float|string|array|null $data): self; + public static function fromPayload(string $type, bool|int|float|string|array|null $payload): self; /** * Returns message type. @@ -36,9 +36,9 @@ public function getType(): string; * @return bool|int|float|string|array|null Payload data containing only `null`, scalars (`bool`, `int`, `float`, * `string`), or arrays composed of the same types recursively. * - * @psalm-return MessageData + * @psalm-return MessagePayload */ - public function getData(): bool|int|float|string|array|null; + public function getPayload(): bool|int|float|string|array|null; /** * Returns message metadata: timings, attempt count, metrics, etc. Keys are always strings. diff --git a/src/Message/Serializer/MessageSerializer.php b/src/Message/Serializer/MessageSerializer.php index b32091ec..89221b40 100644 --- a/src/Message/Serializer/MessageSerializer.php +++ b/src/Message/Serializer/MessageSerializer.php @@ -15,7 +15,7 @@ /** * Serializes and unserializes queue messages, resolving the message class via a {@see MessageClassResolverInterface}. * - * When serializing, assembles an array with `type`, `data`, and `meta` keys and passes it as a single array to + * When serializing, assembles an array with `type`, `payload`, and `meta` keys and passes it as a single array to * {@see MessageEncoderInterface}, which encodes it to a string. When unserializing, decodes the string back to an * array and resolves the message class from the type via the resolver, falling back to {@see GenericMessage} * if the type is not registered. @@ -44,7 +44,7 @@ public function serialize(MessageInterface $message): string { return $this->encoder->encode([ 'type' => $message->getType(), - 'data' => $message->getData(), + 'payload' => $message->getPayload(), 'meta' => $message->getMetadata(), ]); } @@ -69,6 +69,6 @@ public function unserialize(string $value): MessageInterface $class = $this->resolver->resolve($type) ?? GenericMessage::class; - return $class::fromData($type, $data['data'] ?? null)->withMetadata($metadata); + return $class::fromPayload($type, $data['payload'] ?? null)->withMetadata($metadata); } } diff --git a/tests/Integration/MessageConsumingTest.php b/tests/Integration/MessageConsumingTest.php index 24eeb160..c2878dff 100644 --- a/tests/Integration/MessageConsumingTest.php +++ b/tests/Integration/MessageConsumingTest.php @@ -32,8 +32,8 @@ public function testMessagesConsumed(): void $callableFactory = new CallableFactory($container); $worker = new Worker( [ - 'test' => fn(MessageInterface $message): mixed => $this->messagesProcessed[] = $message->getData(), - 'test2' => fn(MessageInterface $message): mixed => $this->messagesProcessedSecond[] = $message->getData(), + 'test' => fn(MessageInterface $message): mixed => $this->messagesProcessed[] = $message->getPayload(), + 'test2' => fn(MessageInterface $message): mixed => $this->messagesProcessedSecond[] = $message->getPayload(), ], new NullLogger(), new Injector($container), diff --git a/tests/Integration/MiddlewareTest.php b/tests/Integration/MiddlewareTest.php index 7e5da8f5..3fffe7cd 100644 --- a/tests/Integration/MiddlewareTest.php +++ b/tests/Integration/MiddlewareTest.php @@ -74,7 +74,7 @@ public function testFullStackPush(): void $message = new GenericMessage('test', ['initial']); $messagePushed = $queue->push($message); - self::assertEquals($stack, $messagePushed->getData()); + self::assertEquals($stack, $messagePushed->getPayload()); } public function testFullStackConsume(): void @@ -116,7 +116,7 @@ public function testFullStackConsume(): void $message = new GenericMessage('test', ['initial']); $messageConsumed = $worker->process($message, $this->createMock(QueueInterface::class)); - self::assertEquals($stack, $messageConsumed->getData()); + self::assertEquals($stack, $messageConsumed->getPayload()); } public function testFullStackFailure(): void diff --git a/tests/Integration/Support/TestHandler.php b/tests/Integration/Support/TestHandler.php index 2a3c50f8..34cd004d 100644 --- a/tests/Integration/Support/TestHandler.php +++ b/tests/Integration/Support/TestHandler.php @@ -13,6 +13,6 @@ public function __construct(public array $messagesProcessed = []) {} public function handle(MessageInterface $message): void { - $this->messagesProcessed[] = $message->getData(); + $this->messagesProcessed[] = $message->getPayload(); } } diff --git a/tests/Integration/Support/TestMiddleware.php b/tests/Integration/Support/TestMiddleware.php index ec65065b..05eb63a7 100644 --- a/tests/Integration/Support/TestMiddleware.php +++ b/tests/Integration/Support/TestMiddleware.php @@ -18,7 +18,7 @@ public function __construct(private readonly string $stage) {} public function processPush(MessageInterface $message, PushHandlerInterface $handler): MessageInterface { - $stack = $message->getData(); + $stack = $message->getPayload(); $stack[] = $this->stage; return $handler->handlePush(new GenericMessage($message->getType(), $stack)); @@ -27,7 +27,7 @@ public function processPush(MessageInterface $message, PushHandlerInterface $han public function processConsume(ConsumeRequest $request, ConsumeHandlerInterface $handler): ConsumeRequest { $message = $request->getMessage(); - $stack = $message->getData(); + $stack = $message->getPayload(); $stack[] = $this->stage; $messageNew = new GenericMessage($message->getType(), $stack); diff --git a/tests/Unit/EnvelopeTest.php b/tests/Unit/EnvelopeTest.php index e09fcd24..1775f60f 100644 --- a/tests/Unit/EnvelopeTest.php +++ b/tests/Unit/EnvelopeTest.php @@ -15,7 +15,7 @@ public function testEnvelopeStack(): void $message = new GenericMessage('handler', 'test'); $message = new IdEnvelope($message, 'test-id'); - $this->assertEquals('test', $message->getMessage()->getData()); + $this->assertEquals('test', $message->getMessage()->getPayload()); $this->assertEquals('test-id', $message->getMetadata()[IdEnvelope::META_ID]); } @@ -26,7 +26,7 @@ public function testEnvelopeDuplicates(): void $message = new IdEnvelope($message, 'test-id-2'); $message = new IdEnvelope($message, 'test-id-3'); - $this->assertEquals('test', $message->getMessage()->getData()); + $this->assertEquals('test', $message->getMessage()->getPayload()); $this->assertEquals('test-id-3', $message->getMetadata()[IdEnvelope::META_ID]); } } diff --git a/tests/Unit/Message/DelayEnvelopeTest.php b/tests/Unit/Message/DelayEnvelopeTest.php index 9d599bb9..0ce2c799 100644 --- a/tests/Unit/Message/DelayEnvelopeTest.php +++ b/tests/Unit/Message/DelayEnvelopeTest.php @@ -17,7 +17,7 @@ public function testDelayEnvelope(): void self::assertSame($message, $delayEnvelope->getMessage()); self::assertSame('test', $delayEnvelope->getType()); - self::assertSame(['data' => 'value'], $delayEnvelope->getData()); + self::assertSame(['data' => 'value'], $delayEnvelope->getPayload()); self::assertSame(300.5, $delayEnvelope->getDelaySeconds()); self::assertSame( [DelayEnvelope::META_DELAY_SECONDS => 300.5], @@ -34,7 +34,7 @@ public function testFromMessage(): void self::assertSame(150.0, $delayEnvelope->getDelaySeconds()); self::assertSame('test', $delayEnvelope->getType()); - self::assertSame(['data' => 'value'], $delayEnvelope->getData()); + self::assertSame(['data' => 'value'], $delayEnvelope->getPayload()); } public function testFromMessageWithoutDelay(): void diff --git a/tests/Unit/Message/EnvelopeTest.php b/tests/Unit/Message/EnvelopeTest.php index 2ba98f84..4dc9e914 100644 --- a/tests/Unit/Message/EnvelopeTest.php +++ b/tests/Unit/Message/EnvelopeTest.php @@ -14,8 +14,8 @@ public function testFromData(): void { $this->expectException(LogicException::class); $this->expectExceptionMessage( - 'Envelopes cannot be created via "fromData()". Wrap an existing "MessageInterface" instance instead.', + 'Envelopes cannot be created via "fromPayload()". Wrap an existing "MessageInterface" instance instead.', ); - DummyEnvelope::fromData('test', []); + DummyEnvelope::fromPayload('test', []); } } diff --git a/tests/Unit/Message/Serializer/MessageSerializerTest.php b/tests/Unit/Message/Serializer/MessageSerializerTest.php index 0223cea2..1213ee4d 100644 --- a/tests/Unit/Message/Serializer/MessageSerializerTest.php +++ b/tests/Unit/Message/Serializer/MessageSerializerTest.php @@ -37,7 +37,7 @@ public function testNonArrayPayload(string $json, string $type): void public function testUnsupportedType(mixed $type): void { $value = json_encode( - ['type' => $type, 'data' => 'test', 'meta' => []], + ['type' => $type, 'payload' => 'test', 'meta' => []], JSON_THROW_ON_ERROR, ); @@ -52,7 +52,7 @@ public function testUnsupportedType(mixed $type): void public function testUnsupportedMetadata(mixed $metadata): void { $value = json_encode( - ['type' => 'test', 'data' => 'test', 'meta' => $metadata], + ['type' => 'test', 'payload' => 'test', 'meta' => $metadata], JSON_THROW_ON_ERROR, ); @@ -65,7 +65,7 @@ public function testFallbackToGenericMessageForUnknownType(): void { $payload = [ 'type' => 'handler', - 'data' => 'test', + 'payload' => 'test', 'meta' => [], ]; @@ -74,23 +74,23 @@ public function testFallbackToGenericMessageForUnknownType(): void $this->assertInstanceOf(GenericMessage::class, $message); } - public function testUnserializeFromData(): void + public function testUnserializeFromPayload(): void { - $payload = ['type' => 'handler', 'data' => 'test']; + $payload = ['type' => 'handler', 'payload' => 'test']; $message = $this->createSerializer()->unserialize(json_encode($payload, JSON_THROW_ON_ERROR)); - $this->assertEquals($payload['data'], $message->getData()); + $this->assertEquals($payload['payload'], $message->getPayload()); $this->assertEquals([], $message->getMetadata()); } public function testUnserializeWithMetadata(): void { - $payload = ['type' => 'handler', 'data' => 'test', 'meta' => ['int' => 1, 'str' => 'string', 'bool' => true]]; + $payload = ['type' => 'handler', 'payload' => 'test', 'meta' => ['int' => 1, 'str' => 'string', 'bool' => true]]; $message = $this->createSerializer()->unserialize(json_encode($payload, JSON_THROW_ON_ERROR)); - $this->assertEquals($payload['data'], $message->getData()); + $this->assertEquals($payload['payload'], $message->getPayload()); $this->assertEquals(['int' => 1, 'str' => 'string', 'bool' => true], $message->getMetadata()); } @@ -101,7 +101,7 @@ public function testSerialize(): void $json = $this->createSerializer()->serialize($message); $this->assertEquals( - '{"type":"handler","data":"test","meta":[]}', + '{"type":"handler","payload":"test","meta":[]}', $json, ); } @@ -114,7 +114,7 @@ public function testSerializeEnvelopeStack(): void $json = $serializer->serialize($message); $this->assertEquals( - sprintf('{"type":"handler","data":"test","meta":{"%s":"test-id"}}', IdEnvelope::META_ID), + sprintf('{"type":"handler","payload":"test","meta":{"%s":"test-id"}}', IdEnvelope::META_ID), $json, ); diff --git a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php index 039d4c55..7a14fcee 100644 --- a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php @@ -36,7 +36,7 @@ static function (ConsumeRequest $request) use ($queue): ConsumeRequest { ); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('New closure test data', $request->getMessage()->getData()); + $this->assertSame('New closure test data', $request->getMessage()->getPayload()); } public function testArrayMiddlewareCallableDefinition(): void @@ -49,7 +49,7 @@ public function testArrayMiddlewareCallableDefinition(): void ); $dispatcher = $this->createDispatcher($container)->withMiddlewares([[TestCallableMiddleware::class, 'index']]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('New test data', $request->getMessage()->getData()); + $this->assertSame('New test data', $request->getMessage()->getPayload()); } public function testFactoryArrayDefinition(): void @@ -62,7 +62,7 @@ public function testFactoryArrayDefinition(): void ]; $dispatcher = $this->createDispatcher($container)->withMiddlewares([$definition]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('New test data from the definition', $request->getMessage()->getData()); + $this->assertSame('New test data from the definition', $request->getMessage()->getPayload()); } public function testMiddlewareFullStackCalled(): void @@ -75,7 +75,7 @@ public function testMiddlewareFullStackCalled(): void return $handler->handleConsume($request); }; $middleware2 = static function (ConsumeRequest $request, ConsumeHandlerInterface $handler): ConsumeRequest { - $request = $request->withMessage(new GenericMessage('new handler', $request->getMessage()->getData())); + $request = $request->withMessage(new GenericMessage('new handler', $request->getMessage()->getPayload())); return $handler->handleConsume($request); }; @@ -83,7 +83,7 @@ public function testMiddlewareFullStackCalled(): void $dispatcher = $this->createDispatcher()->withMiddlewares([$middleware1, $middleware2]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('new test data', $request->getMessage()->getData()); + $this->assertSame('new test data', $request->getMessage()->getPayload()); $this->assertSame('new handler', $request->getMessage()->getType()); } @@ -101,7 +101,7 @@ public function testMiddlewareStackInterrupted(): void $dispatcher = $this->createDispatcher()->withMiddlewares([$middleware1, $middleware2]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('first', $request->getMessage()->getData()); + $this->assertSame('first', $request->getMessage()->getPayload()); } public static function dataHasMiddlewares(): array @@ -145,7 +145,7 @@ public function testResetStackOnWithMiddlewares(): void $dispatcher = $dispatcher->withMiddlewares([TestMiddleware::class]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - self::assertSame('New middleware test data', $request->getMessage()->getData()); + self::assertSame('New middleware test data', $request->getMessage()->getPayload()); } private function getRequestHandler(): ConsumeHandlerInterface diff --git a/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php b/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php index cbc7fb3e..11d8af51 100644 --- a/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php +++ b/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php @@ -52,7 +52,7 @@ public function testCreateFromArray(): void $middleware->processConsume( $this->getConsumeRequest(), $this->createMock(ConsumeHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -70,7 +70,7 @@ public function testCreateFromClosureResponse(): void $middleware->processConsume( $this->getConsumeRequest(), $this->createMock(ConsumeHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -85,7 +85,7 @@ public function testCreateFromClosureMiddleware(): void $middleware->processConsume( $this->getConsumeRequest(), $this->createMock(ConsumeHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -99,7 +99,7 @@ public function testCreateWithUseParamsMiddleware(): void $middleware->processConsume( $this->getConsumeRequest(), $this->getRequestHandler(), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -116,7 +116,7 @@ public function testCreateWithTestCallableMiddleware(): void $middleware->processConsume( $request, $this->getRequestHandler(), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -130,7 +130,7 @@ public function testCreateFromStringCallable(): void $middleware->processConsume( $this->getConsumeRequest(), $this->createMock(ConsumeHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -144,7 +144,7 @@ public function testCreateFromCallableObject(): void $middleware->processConsume( $this->getConsumeRequest(), $this->createMock(ConsumeHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } diff --git a/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php index 00f66c4c..451214ed 100644 --- a/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php @@ -37,7 +37,7 @@ static function (FailureHandlingRequest $request): FailureHandlingRequest { ); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('New closure test data', $request->getMessage()->getData()); + $this->assertSame('New closure test data', $request->getMessage()->getPayload()); } public function testArrayMiddlewareCallableDefinition(): void @@ -56,7 +56,7 @@ public function testArrayMiddlewareCallableDefinition(): void ], ); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('New test data', $request->getMessage()->getData()); + $this->assertSame('New test data', $request->getMessage()->getPayload()); } public function testFactoryArrayDefinition(): void @@ -69,7 +69,7 @@ public function testFactoryArrayDefinition(): void ]; $dispatcher = $this->createDispatcher($container)->withMiddlewares([FailureMiddlewareDispatcher::DEFAULT_PIPELINE => [$definition]]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('New test data from the definition', $request->getMessage()->getData()); + $this->assertSame('New test data from the definition', $request->getMessage()->getPayload()); } public function testMiddlewareFullStackCalled(): void @@ -82,7 +82,7 @@ public function testMiddlewareFullStackCalled(): void return $handler->handleFailure($request); }; $middleware2 = static function (FailureHandlingRequest $request, FailureHandlerInterface $handler): FailureHandlingRequest { - $request = $request->withMessage(new GenericMessage('new handler', $request->getMessage()->getData())); + $request = $request->withMessage(new GenericMessage('new handler', $request->getMessage()->getPayload())); return $handler->handleFailure($request); }; @@ -90,7 +90,7 @@ public function testMiddlewareFullStackCalled(): void $dispatcher = $this->createDispatcher()->withMiddlewares([FailureMiddlewareDispatcher::DEFAULT_PIPELINE => [$middleware1, $middleware2]]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('new test data', $request->getMessage()->getData()); + $this->assertSame('new test data', $request->getMessage()->getPayload()); $this->assertSame('new handler', $request->getMessage()->getType()); } @@ -108,7 +108,7 @@ public function testMiddlewareStackInterrupted(): void $dispatcher = $this->createDispatcher()->withMiddlewares([FailureMiddlewareDispatcher::DEFAULT_PIPELINE => [$middleware1, $middleware2]]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - $this->assertSame('first', $request->getMessage()->getData()); + $this->assertSame('first', $request->getMessage()->getPayload()); } public function dataHasMiddlewares(): array @@ -143,7 +143,7 @@ public function testResetStackOnWithMiddlewares(): void $dispatcher = $dispatcher->withMiddlewares([FailureMiddlewareDispatcher::DEFAULT_PIPELINE => [TestMiddleware::class]]); $request = $dispatcher->dispatch($request, $this->getRequestHandler()); - self::assertSame('New middleware test data', $request->getMessage()->getData()); + self::assertSame('New middleware test data', $request->getMessage()->getPayload()); } private function getRequestHandler(): FailureHandlerInterface diff --git a/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php b/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php index a46f08b7..b228e182 100644 --- a/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php +++ b/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php @@ -45,7 +45,7 @@ public function testCreateCallableFromArray(): void $middleware->processFailure( $this->getConsumeRequest(), $this->createMock(FailureHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -66,7 +66,7 @@ function (): FailureHandlingRequest { $middleware->processFailure( $this->getConsumeRequest(), $this->createMock(FailureHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -83,7 +83,7 @@ static function (): FailureMiddlewareInterface { $middleware->processFailure( $this->getConsumeRequest(), $this->createMock(FailureHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -97,7 +97,7 @@ public function testCreateWithUseParamsMiddleware(): void $middleware->processFailure( $this->getConsumeRequest(), $this->getRequestHandler(), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -114,7 +114,7 @@ public function testCreateWithTestCallableMiddleware(): void $middleware->processFailure( $request, $this->getRequestHandler(), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -128,7 +128,7 @@ public function testCreateFromStringCallable(): void $middleware->processFailure( $this->getConsumeRequest(), $this->createMock(FailureHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } @@ -142,7 +142,7 @@ public function testCreateFromCallableObject(): void $middleware->processFailure( $this->getConsumeRequest(), $this->createMock(FailureHandlerInterface::class), - )->getMessage()->getData(), + )->getMessage()->getPayload(), ); } diff --git a/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php b/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php index 5b5b2660..650a2589 100644 --- a/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php +++ b/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php @@ -27,7 +27,7 @@ public function testWithId(): void $this->assertSame($message, $result); $this->assertNotInstanceOf(IdEnvelope::class, $result); $this->assertEquals('test-id', $result->getMetadata()[IdEnvelope::META_ID]); - $this->assertSame($message->getData(), $result->getData()); + $this->assertSame($message->getPayload(), $result->getPayload()); $this->assertSame($message->getType(), $result->getType()); } @@ -46,7 +46,7 @@ public function testWithoutId(): void $this->assertInstanceOf(IdEnvelope::class, $result); $this->assertNotSame($message, $result); $this->assertNotEmpty($result->getMetadata()[IdEnvelope::META_ID] ?? null); - $this->assertSame($message->getData(), $result->getData()); + $this->assertSame($message->getPayload(), $result->getPayload()); $this->assertSame($message->getType(), $result->getType()); } @@ -66,7 +66,7 @@ public function testWithEmptyId(): void $this->assertNotSame($message, $result); $this->assertNotEmpty($result->getMetadata()[IdEnvelope::META_ID] ?? null); $this->assertNotSame('', $result->getMetadata()[IdEnvelope::META_ID]); - $this->assertSame($message->getData(), $result->getData()); + $this->assertSame($message->getPayload(), $result->getPayload()); $this->assertSame($message->getType(), $result->getType()); } } diff --git a/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php index fbdc0ab7..0d24d697 100644 --- a/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php @@ -34,7 +34,7 @@ static function (MessageInterface $message, PushHandlerInterface $handler): Mess ); $result = $dispatcher->dispatch($message); - $this->assertSame('New closure test data', $result->getData()); + $this->assertSame('New closure test data', $result->getPayload()); } public function testArrayMiddlewareCallableDefinition(): void @@ -47,7 +47,7 @@ public function testArrayMiddlewareCallableDefinition(): void ); $dispatcher = $this->createDispatcher($container)->withMiddlewares([[TestCallableMiddleware::class, 'index']]); $result = $dispatcher->dispatch($message); - $this->assertSame('New test data', $result->getData()); + $this->assertSame('New test data', $result->getPayload()); } public function testFactoryArrayDefinition(): void @@ -60,7 +60,7 @@ public function testFactoryArrayDefinition(): void ]; $dispatcher = $this->createDispatcher($container)->withMiddlewares([$definition]); $result = $dispatcher->dispatch($message); - $this->assertSame('New test data from the definition', $result->getData()); + $this->assertSame('New test data from the definition', $result->getPayload()); } public function testMiddlewareFullStackCalled(): void @@ -77,7 +77,7 @@ public function testMiddlewareFullStackCalled(): void $dispatcher = $this->createDispatcher()->withMiddlewares([$middleware1, $middleware2]); $result = $dispatcher->dispatch($message); - $this->assertSame('new test data', $result->getData()); + $this->assertSame('new test data', $result->getPayload()); } public function testMiddlewareStackInterrupted(): void @@ -90,7 +90,7 @@ public function testMiddlewareStackInterrupted(): void $dispatcher = $this->createDispatcher()->withMiddlewares([$middleware1, $middleware2]); $result = $dispatcher->dispatch($message); - $this->assertSame('first', $result->getData()); + $this->assertSame('first', $result->getPayload()); } public static function dataHasMiddlewares(): array @@ -134,7 +134,7 @@ public function testResetStackOnWithMiddlewares(): void $dispatcher = $dispatcher->withMiddlewares([TestMiddleware::class]); $result = $dispatcher->dispatch($message); - self::assertSame('New middleware test data', $result->getData()); + self::assertSame('New middleware test data', $result->getPayload()); } private function createDispatcher( diff --git a/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php b/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php index 08cbf696..c1d39cc3 100644 --- a/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php +++ b/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php @@ -42,7 +42,7 @@ public function testCreateCallableFromArray(): void $middleware->processPush( $this->getMessage(), $this->createMock(PushHandlerInterface::class), - )->getData(), + )->getPayload(), ); } @@ -59,7 +59,7 @@ static function (): MessageInterface { $middleware->processPush( $this->getMessage(), $this->createMock(PushHandlerInterface::class), - )->getData(), + )->getPayload(), ); } @@ -76,7 +76,7 @@ static function (): PushMiddlewareInterface { $middleware->processPush( $this->getMessage(), $this->createMock(PushHandlerInterface::class), - )->getData(), + )->getPayload(), ); } @@ -90,7 +90,7 @@ public function testCreateWithUseParamsMiddleware(): void $middleware->processPush( $this->getMessage(), $this->getRequestHandler(), - )->getData(), + )->getPayload(), ); } @@ -104,7 +104,7 @@ public function testCreateWithTestCallableMiddleware(): void $middleware->processPush( $this->getMessage(), $this->getRequestHandler(), - )->getData(), + )->getPayload(), ); } @@ -118,7 +118,7 @@ public function testCreateFromStringCallable(): void $middleware->processPush( $this->getMessage(), $this->createMock(PushHandlerInterface::class), - )->getData(), + )->getPayload(), ); } @@ -132,7 +132,7 @@ public function testCreateFromCallableObject(): void $middleware->processPush( $this->getMessage(), $this->createMock(PushHandlerInterface::class), - )->getData(), + )->getPayload(), ); } diff --git a/tests/Unit/Stubs/InMemoryAdapterTest.php b/tests/Unit/Stubs/InMemoryAdapterTest.php index 288879ea..53dda467 100644 --- a/tests/Unit/Stubs/InMemoryAdapterTest.php +++ b/tests/Unit/Stubs/InMemoryAdapterTest.php @@ -26,11 +26,11 @@ public function testPush(): void $this->assertInstanceOf(IdEnvelope::class, $envelope3); $this->assertSame(0, $envelope1->getId()); - $this->assertSame('a', $envelope1->getMessage()->getData()); + $this->assertSame('a', $envelope1->getMessage()->getPayload()); $this->assertSame(1, $envelope2->getId()); - $this->assertSame('b', $envelope2->getMessage()->getData()); + $this->assertSame('b', $envelope2->getMessage()->getPayload()); $this->assertSame(2, $envelope3->getId()); - $this->assertSame('c', $envelope3->getMessage()->getData()); + $this->assertSame('c', $envelope3->getMessage()->getPayload()); } public function testStatusWaitingForPushedMessage(): void @@ -86,7 +86,7 @@ public function testRunExistingProcessesAllMessages(): void $processed = []; $adapter->runExisting( static function (MessageInterface $message) use (&$processed): bool { - $processed[] = $message->getData(); + $processed[] = $message->getPayload(); return true; }, ); @@ -104,7 +104,7 @@ public function testRunExistingStopsWhenHandlerReturnsFalse(): void $processed = []; $adapter->runExisting( static function (MessageInterface $message) use (&$processed): bool { - $processed[] = $message->getData(); + $processed[] = $message->getPayload(); return false; }, ); @@ -163,7 +163,7 @@ public function testSubscribeProcessesExistingMessages(): void $processed = []; $adapter->subscribe( static function (MessageInterface $message) use (&$processed): bool { - $processed[] = $message->getData(); + $processed[] = $message->getPayload(); return true; }, ); diff --git a/tests/Unit/Stubs/StubWorkerTest.php b/tests/Unit/Stubs/StubWorkerTest.php index 58279594..959660ee 100644 --- a/tests/Unit/Stubs/StubWorkerTest.php +++ b/tests/Unit/Stubs/StubWorkerTest.php @@ -21,7 +21,7 @@ public function testBase(): void $this->assertSame($sourceMessage, $message); $this->assertSame('test', $message->getType()); - $this->assertSame(42, $message->getData()); + $this->assertSame(42, $message->getPayload()); $this->assertSame([], $message->getMetadata()); } } diff --git a/tests/Unit/Support/TestMessage.php b/tests/Unit/Support/TestMessage.php index d2913eab..4bcdc3a6 100644 --- a/tests/Unit/Support/TestMessage.php +++ b/tests/Unit/Support/TestMessage.php @@ -9,7 +9,7 @@ final class TestMessage extends Message { - public static function fromData(string $type, mixed $data): MessageInterface + public static function fromPayload(string $type, mixed $payload): MessageInterface { return new self(); } @@ -19,7 +19,7 @@ public function getType(): string return 'test'; } - public function getData(): bool|int|float|string|array|null + public function getPayload(): bool|int|float|string|array|null { return null; } diff --git a/tests/Unit/WorkerTest.php b/tests/Unit/WorkerTest.php index c6c2cb52..e08a527a 100644 --- a/tests/Unit/WorkerTest.php +++ b/tests/Unit/WorkerTest.php @@ -150,7 +150,7 @@ public function testMessageFailWithDefinitionHandlerException(): void } catch (MessageFailureException $exception) { self::assertSame($exception::class, MessageFailureException::class); self::assertSame($exception->getMessage(), "Processing of message without ID is stopped because of an exception:\nTest exception."); - self::assertEquals(['test-data'], $exception->getQueueMessage()->getData()); + self::assertEquals(['test-data'], $exception->getQueueMessage()->getPayload()); } finally { $messages = $logger->getMessages(); $this->assertNotEmpty($messages);