Skip to content

Commit 28c2e2f

Browse files
author
Davert
committed
fix to AMQP module
1 parent 98dfe34 commit 28c2e2f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/Codeception/Module/AMQP.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
* ## Public Properties
4848
*
4949
* * connection - AMQPConnection - current connection
50-
* * channel - AMQPChannel - current channel
5150
*
5251
* @since 1.1.2
5352
@@ -89,7 +88,6 @@ public function _initialize()
8988
} catch (\Exception $e) {
9089
throw new ModuleException(__CLASS__, $e->getMessage() . ' while establishing connection to MQ server');
9190
}
92-
$this->channel = $this->connection->channel();
9391
}
9492

9593
public function _before(\Codeception\TestCase $test)
@@ -117,7 +115,7 @@ public function pushToExchange($exchange, $message)
117115
$message = $message instanceof AMQPMessage
118116
? $message
119117
: new AMQPMessage($message);
120-
$this->channel->basic_publish($message, $exchange);
118+
$this->connection->channel()->basic_publish($message, $exchange);
121119
}
122120

123121
/**
@@ -139,8 +137,8 @@ public function pushToQueue($queue, $message)
139137
? $message
140138
: new AMQPMessage($message);
141139

142-
$this->channel->queue_declare($queue);
143-
$this->channel->basic_publish($message, '',$queue);
140+
$this->connection->channel()->queue_declare($queue);
141+
$this->connection->channel()->basic_publish($message, '',$queue);
144142
}
145143

146144
/**
@@ -161,7 +159,7 @@ public function pushToQueue($queue, $message)
161159
*/
162160
public function seeMessageInQueueContainsText($queue, $text)
163161
{
164-
$msg = $this->channel->basic_get($queue);
162+
$msg = $this->connection->channel()->basic_get($queue);
165163
if (!$msg) $this->fail("Message was not received");
166164
if (!$msg instanceof AMQPMessage) $this->fail("Received message is not format of AMQPMessage");
167165
$this->debugSection("Message",$msg->body);
@@ -178,7 +176,7 @@ public function seeMessageInQueueContainsText($queue, $text)
178176
*/
179177
public function grabMessageFromQueue($queue)
180178
{
181-
$message = $this->channel->basic_get($queue);
179+
$message = $this->connection->channel()->basic_get($queue);
182180
return $message;
183181
}
184182

@@ -187,12 +185,12 @@ protected function cleanup()
187185
if (! isset($this->config['queues'])) {
188186
throw new ModuleException(__CLASS__, "please set queues for cleanup");
189187
}
190-
$channel = $this->channel;
191-
if (!$channel->is_open) return;
188+
if (!$this->connection) return;
189+
if ($this->connection->channel()->is_open) return;
192190
foreach ($this->config['queues'] as $queue) {
193191
try {
194-
$channel->queue_purge($queue);
195-
} catch (AMQPChannelException $e) {
192+
$this->connection->channel()->queue_purge($queue);
193+
} catch (\PhpAmqpLib\Exception\AMQPProtocolChannelException $e) {
196194
# ignore if exchange/queue doesn't exist and rethrow exception if it's something else
197195
if ($e->getCode() !== 404) {
198196
throw $e;

0 commit comments

Comments
 (0)