4
4
5
5
use Codeception \Exception \Module as ModuleException ;
6
6
use Exception ;
7
- use PhpAmqpLib \Message \AMQPMessage ;
8
- use PhpAmqpLib \Connection \AMQPConnection ;
9
7
use PhpAmqpLib \Channel \AMQPChannel ;
10
- use PhpAmqpLib \Exception \AMQPChannelException ;
8
+ use PhpAmqpLib \Connection \AMQPConnection ;
9
+ use PhpAmqpLib \Message \AMQPMessage ;
11
10
12
11
/**
13
12
* This module interacts with message broker software that implements
58
57
*/
59
58
class AMQP extends \Codeception \Module
60
59
{
61
- protected $ config = array (
62
- 'host ' => 'locahost ' ,
60
+ protected $ config = [
61
+ 'host ' => 'locahost ' ,
63
62
'username ' => 'guest ' ,
64
63
'password ' => 'guest ' ,
65
- 'port ' => '5672 ' ,
66
- 'vhost ' => '/ ' ,
67
- 'cleanup ' => true ,
68
- ) ;
64
+ 'port ' => '5672 ' ,
65
+ 'vhost ' => '/ ' ,
66
+ 'cleanup ' => true ,
67
+ ] ;
69
68
70
69
/**
71
70
* @var AMQPConnection
@@ -77,7 +76,7 @@ class AMQP extends \Codeception\Module
77
76
*/
78
77
protected $ channel ;
79
78
80
- protected $ requiredFields = array ( 'host ' , 'username ' , 'password ' , 'vhost ' ) ;
79
+ protected $ requiredFields = [ 'host ' , 'username ' , 'password ' , 'vhost ' ] ;
81
80
82
81
public function _initialize ()
83
82
{
@@ -142,7 +141,7 @@ public function pushToQueue($queue, $message)
142
141
: new AMQPMessage ($ message );
143
142
144
143
$ this ->connection ->channel ()->queue_declare ($ queue );
145
- $ this ->connection ->channel ()->basic_publish ($ message , '' ,$ queue );
144
+ $ this ->connection ->channel ()->basic_publish ($ message , '' , $ queue );
146
145
}
147
146
148
147
/**
@@ -164,9 +163,13 @@ public function pushToQueue($queue, $message)
164
163
public function seeMessageInQueueContainsText ($ queue , $ text )
165
164
{
166
165
$ msg = $ this ->connection ->channel ()->basic_get ($ queue );
167
- if (!$ msg ) $ this ->fail ("Message was not received " );
168
- if (!$ msg instanceof AMQPMessage) $ this ->fail ("Received message is not format of AMQPMessage " );
169
- $ this ->debugSection ("Message " ,$ msg ->body );
166
+ if (!$ msg ) {
167
+ $ this ->fail ("Message was not received " );
168
+ }
169
+ if (!$ msg instanceof AMQPMessage) {
170
+ $ this ->fail ("Received message is not format of AMQPMessage " );
171
+ }
172
+ $ this ->debugSection ("Message " , $ msg ->body );
170
173
$ this ->assertContains ($ text , $ msg ->body );
171
174
}
172
175
@@ -186,10 +189,12 @@ public function grabMessageFromQueue($queue)
186
189
187
190
protected function cleanup ()
188
191
{
189
- if (! isset ($ this ->config ['queues ' ])) {
192
+ if (!isset ($ this ->config ['queues ' ])) {
190
193
throw new ModuleException (__CLASS__ , "please set queues for cleanup " );
191
194
}
192
- if (!$ this ->connection ) return ;
195
+ if (!$ this ->connection ) {
196
+ return ;
197
+ }
193
198
foreach ($ this ->config ['queues ' ] as $ queue ) {
194
199
try {
195
200
$ this ->connection ->channel ()->queue_purge ($ queue );
0 commit comments