Skip to content

Commit 9f6f03c

Browse files
committed
RabbitMQ tests
1 parent a6dca41 commit 9f6f03c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"autoload": {
88
"psr-0": {
99
"MyCLabs": "src/",
10+
"FunctionalTest": "tests/",
1011
"UnitTest": "tests/"
1112
}
1213
},

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
bootstrap="./tests/bootstrap.php">
1212

1313
<testsuites>
14+
<testsuite name="Work functional tests">
15+
<directory>./tests/FunctionalTest/</directory>
16+
</testsuite>
1417
<testsuite name="Work unit tests">
1518
<directory>./tests/UnitTest/</directory>
1619
</testsuite>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace UnitTest\MyCLabs\Work\Dispatcher;
4+
5+
use MyCLabs\Work\Dispatcher\RabbitMQWorkDispatcher;
6+
use PhpAmqpLib\Connection\AMQPConnection;
7+
use PhpAmqpLib\Exception\AMQPRuntimeException;
8+
use PHPUnit_Framework_TestCase;
9+
10+
/**
11+
* Test executing tasks through RabbitMQ
12+
*/
13+
class RabbitMQTest extends PHPUnit_Framework_TestCase
14+
{
15+
const QUEUE_NAME = 'myclabs_work_test';
16+
17+
public function testRunBackground()
18+
{
19+
try {
20+
$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
21+
} catch (AMQPRuntimeException $e) {
22+
// RabbitMQ not installed, mark test skipped
23+
$this->markTestSkipped('RabbitMQ is not installed or was not found');
24+
return;
25+
}
26+
27+
$channel = $connection->channel();
28+
29+
$channel->queue_declare(self::QUEUE_NAME, false, false, false, false);
30+
31+
$workDispatcher = new RabbitMQWorkDispatcher($channel, self::QUEUE_NAME);
32+
33+
$channel->close();
34+
$connection->close();
35+
}
36+
}

0 commit comments

Comments
 (0)