-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathFailureEnvelopeTest.php
More file actions
44 lines (34 loc) · 1.59 KB
/
FailureEnvelopeTest.php
File metadata and controls
44 lines (34 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Tests\Unit\Middleware\FailureHandling;
use PHPUnit\Framework\TestCase;
use Yiisoft\Queue\Message\Message;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\FailureHandling\FailureEnvelope;
final class FailureEnvelopeTest extends TestCase
{
public function testConstructor(): void
{
$message = $this->createMessage();
$metadata = ['attempt' => 1, 'error' => 'Test error'];
$envelope = new FailureEnvelope($message, $metadata);
$this->assertSame($message, $envelope->getMessage());
$this->assertArrayHasKey(FailureEnvelope::FAILURE_META_KEY, $envelope->getMetadata());
$this->assertSame($metadata, $envelope->getMetadata()[FailureEnvelope::FAILURE_META_KEY]);
}
public function testMetadataMerging(): void
{
$existingMetadata = ['attempt' => 1, 'firstError' => 'First error'];
$message = $this->createMessage([FailureEnvelope::FAILURE_META_KEY => $existingMetadata]);
$newMetadata = ['attempt' => 2, 'lastError' => 'Last error'];
$envelope = new FailureEnvelope($message, $newMetadata);
$mergedMetadata = $envelope->getMetadata()[FailureEnvelope::FAILURE_META_KEY];
$this->assertSame(2, $mergedMetadata['attempt']);
$this->assertSame('First error', $mergedMetadata['firstError']);
$this->assertSame('Last error', $mergedMetadata['lastError']);
}
private function createMessage(array $metadata = []): MessageInterface
{
return new Message('test-handler', ['test-data'], $metadata);
}
}