Skip to content

Commit 86de6aa

Browse files
committed
add tests for pre send object.
1 parent dd55031 commit 86de6aa

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
namespace Enqueue\Tests\Client;
4+
5+
use Enqueue\Client\DriverInterface;
6+
use Enqueue\Client\Message;
7+
use Enqueue\Client\PreSend;
8+
use Enqueue\Client\ProducerInterface;
9+
use Enqueue\Test\ClassExtensionTrait;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class PreSendTest extends TestCase
13+
{
14+
use ClassExtensionTrait;
15+
16+
public function testShouldBeFinal()
17+
{
18+
self::assertClassFinal(PreSend::class);
19+
}
20+
21+
public function testCouldBeConstructedWithExpectedArguments()
22+
{
23+
new PreSend(
24+
'aCommandOrTopic',
25+
new Message(),
26+
$this->createProducerMock(),
27+
$this->createDriverMock()
28+
);
29+
}
30+
31+
public function testShouldAllowGetArgumentSetInConstructor()
32+
{
33+
$expectedCommandOrTopic = 'theCommandOrTopic';
34+
$expectedMessage = new Message();
35+
$expectedProducer = $this->createProducerMock();
36+
$expectedDriver = $this->createDriverMock();
37+
38+
$context = new PreSend(
39+
$expectedCommandOrTopic,
40+
$expectedMessage,
41+
$expectedProducer,
42+
$expectedDriver
43+
);
44+
45+
$this->assertSame($expectedCommandOrTopic, $context->getTopic());
46+
$this->assertSame($expectedCommandOrTopic, $context->getCommand());
47+
$this->assertSame($expectedMessage, $context->getMessage());
48+
$this->assertSame($expectedProducer, $context->getProducer());
49+
$this->assertSame($expectedDriver, $context->getDriver());
50+
51+
$this->assertEquals($expectedMessage, $context->getOriginalMessage());
52+
$this->assertNotSame($expectedMessage, $context->getOriginalMessage());
53+
}
54+
55+
public function testCouldChangeTopic()
56+
{
57+
$context = new PreSend(
58+
'aCommandOrTopic',
59+
new Message(),
60+
$this->createProducerMock(),
61+
$this->createDriverMock()
62+
);
63+
64+
//guard
65+
$this->assertSame('aCommandOrTopic', $context->getTopic());
66+
67+
$context->changeTopic('theChangedTopic');
68+
69+
$this->assertSame('theChangedTopic', $context->getTopic());
70+
}
71+
72+
public function testCouldChangeCommand()
73+
{
74+
$context = new PreSend(
75+
'aCommandOrTopic',
76+
new Message(),
77+
$this->createProducerMock(),
78+
$this->createDriverMock()
79+
);
80+
81+
//guard
82+
$this->assertSame('aCommandOrTopic', $context->getCommand());
83+
84+
$context->changeCommand('theChangedCommand');
85+
86+
$this->assertSame('theChangedCommand', $context->getCommand());
87+
}
88+
89+
public function testCouldChangeBody()
90+
{
91+
$context = new PreSend(
92+
'aCommandOrTopic',
93+
new Message('aBody'),
94+
$this->createProducerMock(),
95+
$this->createDriverMock()
96+
);
97+
98+
//guard
99+
$this->assertSame('aBody', $context->getMessage()->getBody());
100+
$this->assertNull($context->getMessage()->getContentType());
101+
102+
$context->changeBody('theChangedBody');
103+
$this->assertSame('theChangedBody', $context->getMessage()->getBody());
104+
$this->assertNull($context->getMessage()->getContentType());
105+
106+
$context->changeBody('theChangedBodyAgain', 'foo/bar');
107+
$this->assertSame('theChangedBodyAgain', $context->getMessage()->getBody());
108+
$this->assertSame('foo/bar', $context->getMessage()->getContentType());
109+
}
110+
111+
/**
112+
* @return \PHPUnit_Framework_MockObject_MockObject
113+
*/
114+
private function createDriverMock(): DriverInterface
115+
{
116+
return $this->createMock(DriverInterface::class);
117+
}
118+
119+
/**
120+
* @return \PHPUnit_Framework_MockObject_MockObject
121+
*/
122+
private function createProducerMock(): ProducerInterface
123+
{
124+
return $this->createMock(ProducerInterface::class);
125+
}
126+
}

0 commit comments

Comments
 (0)