| layout | doc |
|---|---|
| title | AMQP - Codeception - Documentation |
If you use Codeception installed using composer, install this module with the following command:
{% highlight yaml %} composer require --dev codeception/module-amqp
{% endhighlight %}
Alternatively, you can enable AMQP module in suite configuration file and run
{% highlight yaml %} codecept init upgrade4
{% endhighlight %}
This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately.
Some modules are bundled with PHAR files.
Warning. Using PHAR file and composer in the same project can cause unexpected errors.
This module interacts with message broker software that implements the Advanced Message Queuing Protocol (AMQP) standard. For example, RabbitMQ (tested).
- host: localhost - host to connect
- username: guest - username to connect
- password: guest - password to connect
- vhost: '/' - vhost to connect
- cleanup: true - defined queues will be purged before running every test.
- queues: [mail, twitter] - queues to cleanup
- single_channel - create and use only one channel during test execution
modules:
enabled:
- AMQP:
host: 'localhost'
port: '5672'
username: 'guest'
password: 'guest'
vhost: '/'
queues: [queue1, queue2]
single_channel: false
- connection - AMQPStreamConnection - current connection
Binds a queue to an exchange
This is an alias of method queue_bind of PhpAmqpLib\Channel\AMQPChannel.
{% highlight php %}
bindQueueToExchange( 'nameOfMyQueueToBind', // name of the queue 'transactionTracking.transaction', // exchange name to bind to 'your.routing.key' // Optionally, provide a binding key ) {% endhighlight %} #### declareExchange Declares an exchange This is an alias of method `exchange_declare` of `PhpAmqpLib\Channel\AMQPChannel`. {% highlight php %} declareExchange( 'nameOfMyExchange', // exchange name 'topic' // exchange type ) {% endhighlight %} #### declareQueue Declares queue, creates if needed This is an alias of method `queue_declare` of `PhpAmqpLib\Channel\AMQPChannel`. {% highlight php %} declareQueue( 'nameOfMyQueue', // exchange name ) {% endhighlight %} #### dontSeeQueueIsEmpty Checks if queue is not empty. {% highlight php %} pushToQueue('queue.emails', 'Hello, davert'); $I->dontSeeQueueIsEmpty('queue.emails'); {% endhighlight %} #### grabMessageFromQueue Takes last message from queue. {% highlight php %} grabMessageFromQueue('queue.emails'); {% endhighlight %} #### purgeAllQueues Purge all queues defined in config. {% highlight php %} purgeAllQueues(); {% endhighlight %} #### purgeQueue Purge a specific queue defined in config. {% highlight php %} purgeQueue('queue.emails'); {% endhighlight %} #### pushToExchange Sends message to exchange by sending exchange name, message and (optionally) a routing key {% highlight php %} pushToExchange('exchange.emails', 'thanks'); $I->pushToExchange('exchange.emails', new AMQPMessage('Thanks!')); $I->pushToExchange('exchange.emails', new AMQPMessage('Thanks!'), 'severity'); {% endhighlight %} #### pushToQueue Sends message to queue {% highlight php %} pushToQueue('queue.jobs', 'create user'); $I->pushToQueue('queue.jobs', new AMQPMessage('create')); {% endhighlight %} #### scheduleQueueCleanup Add a queue to purge list #### seeMessageInQueueContainsText Checks if message containing text received. **This method drops message from queue** **This method will wait for message. If none is sent the script will stuck**. {% highlight php %} pushToQueue('queue.emails', 'Hello, davert'); $I->seeMessageInQueueContainsText('queue.emails','davert'); {% endhighlight %} #### seeNumberOfMessagesInQueue Checks that queue have expected number of message {% highlight php %} pushToQueue('queue.emails', 'Hello, davert'); $I->seeNumberOfMessagesInQueue('queue.emails',1); {% endhighlight %} #### seeQueueIsEmpty Checks that queue is empty {% highlight php %} pushToQueue('queue.emails', 'Hello, davert'); $I->purgeQueue('queue.emails'); $I->seeQueueIsEmpty('queue.emails'); {% endhighlight %}