Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit bce8339

Browse files
author
svensp
committed
TestsRabbitMQ - refactored message expection
1 parent c64209e commit bce8339

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/Test/TestsRabbitMQ.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010

1111
trait TestsRabbitMQ
1212
{
13+
14+
/**
15+
* @var string
16+
*/
17+
protected $expectedRoutingKey = '';
18+
19+
/**
20+
* @var string
21+
*/
22+
protected $expectedExchangeName = '';
23+
1324
public function sendMessage(AmqpMessage $message)
1425
{
1526
/**
@@ -42,12 +53,24 @@ protected function setUpRabbitMQ() {
4253
$this->app->instance(RabbitMQ::class, $this->rabbitMQ);
4354
}
4455

56+
protected function expectEvent($routingKey)
57+
{
58+
$this->expectedRoutingKey = $routingKey;
59+
return $this;
60+
}
61+
62+
protected function onExchange($exchangeName)
63+
{
64+
$this->expectedExchangeName = $exchangeName;
65+
return $this;
66+
}
67+
4568
/**
4669
* @param string $event
4770
* @param array $expectedData
4871
*/
49-
protected function expectMessage( $event, $expectedData ) {
50-
$this->rabbitMQ->shouldReceive( 'onExchange' )->with( 'default-exchange', $event )->once()->andReturnSelf();
72+
protected function withMessage( $expectedData ) {
73+
$this->rabbitMQ->shouldReceive( 'onExchange' )->with( $this->expectedExchangeName, $this->expectedRoutingKey )->once()->andReturnSelf();
5174
$this->rabbitMQ->shouldReceive( 'publish' )->withArgs( function ( $data ) use ( $expectedData ) {
5275
$anyMatch = false;
5376

0 commit comments

Comments
 (0)