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

Commit 4d4ff9c

Browse files
author
svensp
committed
TestsRabbitMQ - added setUpRabbitMQ and expectMessage helpers
1 parent 7d2959b commit 4d4ff9c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/Test/TestsRabbitMQ.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,40 @@ protected function makeMessage(string $routingKey, $data) {
3434

3535
return $message;
3636
}
37+
38+
protected function setUpRabbitMQ() {
39+
$this->rabbitMQ = Mockery::mock( RabbitMQ::class );
40+
$this->rabbitMQ->shouldIgnoreMissing($this->rabbitMQ);
41+
$this->app->instance(RabbitMQ::class, $this->rabbitMQ);
42+
}
43+
44+
/**
45+
* @param string $event
46+
* @param array $expectedData
47+
*/
48+
protected function expectMessage( $event, $expectedData ) {
49+
$this->rabbitMQ->shouldReceive( 'onExchange' )->with( 'default-exchange', $event )->once()->andReturnSelf();
50+
$this->rabbitMQ->shouldReceive( 'publish' )->withArgs( function ( $data ) use ( $expectedData ) {
51+
$anyMatch = false;
52+
53+
foreach ( $expectedData as $expectedKey => $expectedValue ) {
54+
55+
if ( !array_key_exists( $expectedKey, $data ) )
56+
return false;
57+
58+
if( is_float($data[ $expectedKey ]))
59+
$data[ $expectedKey ] = round($data[ $expectedKey ], 9);
60+
61+
if( is_float($expectedValue))
62+
$expectedValue = round($expectedValue, 9);
63+
64+
if ( $data[ $expectedKey ] != $expectedValue )
65+
return false;
66+
67+
$anyMatch = true;
68+
}
69+
70+
return $anyMatch;
71+
} )->once()->andReturnSelf();
72+
}
3773
}

0 commit comments

Comments
 (0)