forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreSendTest.php
More file actions
116 lines (94 loc) · 3.43 KB
/
PreSendTest.php
File metadata and controls
116 lines (94 loc) · 3.43 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
namespace Enqueue\Tests\Client;
use Enqueue\Client\DriverInterface;
use Enqueue\Client\Message;
use Enqueue\Client\PreSend;
use Enqueue\Client\ProducerInterface;
use Enqueue\Test\ClassExtensionTrait;
use PHPUnit\Framework\TestCase;
class PreSendTest extends TestCase
{
use ClassExtensionTrait;
public function testShouldBeFinal()
{
self::assertClassFinal(PreSend::class);
}
public function testShouldAllowGetArgumentSetInConstructor()
{
$expectedCommandOrTopic = 'theCommandOrTopic';
$expectedMessage = new Message();
$expectedProducer = $this->createProducerMock();
$expectedDriver = $this->createDriverMock();
$context = new PreSend(
$expectedCommandOrTopic,
$expectedMessage,
$expectedProducer,
$expectedDriver
);
$this->assertSame($expectedCommandOrTopic, $context->getTopic());
$this->assertSame($expectedCommandOrTopic, $context->getCommand());
$this->assertSame($expectedMessage, $context->getMessage());
$this->assertSame($expectedProducer, $context->getProducer());
$this->assertSame($expectedDriver, $context->getDriver());
$this->assertEquals($expectedMessage, $context->getOriginalMessage());
$this->assertNotSame($expectedMessage, $context->getOriginalMessage());
}
public function testCouldChangeTopic()
{
$context = new PreSend(
'aCommandOrTopic',
new Message(),
$this->createProducerMock(),
$this->createDriverMock()
);
// guard
$this->assertSame('aCommandOrTopic', $context->getTopic());
$context->changeTopic('theChangedTopic');
$this->assertSame('theChangedTopic', $context->getTopic());
}
public function testCouldChangeCommand()
{
$context = new PreSend(
'aCommandOrTopic',
new Message(),
$this->createProducerMock(),
$this->createDriverMock()
);
// guard
$this->assertSame('aCommandOrTopic', $context->getCommand());
$context->changeCommand('theChangedCommand');
$this->assertSame('theChangedCommand', $context->getCommand());
}
public function testCouldChangeBody()
{
$context = new PreSend(
'aCommandOrTopic',
new Message('aBody'),
$this->createProducerMock(),
$this->createDriverMock()
);
// guard
$this->assertSame('aBody', $context->getMessage()->getBody());
$this->assertNull($context->getMessage()->getContentType());
$context->changeBody('theChangedBody');
$this->assertSame('theChangedBody', $context->getMessage()->getBody());
$this->assertNull($context->getMessage()->getContentType());
$context->changeBody('theChangedBodyAgain', 'foo/bar');
$this->assertSame('theChangedBodyAgain', $context->getMessage()->getBody());
$this->assertSame('foo/bar', $context->getMessage()->getContentType());
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject
*/
private function createDriverMock(): DriverInterface
{
return $this->createMock(DriverInterface::class);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject
*/
private function createProducerMock(): ProducerInterface
{
return $this->createMock(ProducerInterface::class);
}
}