-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
518bfcb
commit 11269d2
Showing
7 changed files
with
270 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/.idea | ||
/tests/coverage | ||
/vendor | ||
composer.lock | ||
.phpstorm.meta.php | ||
.phpstorm.meta.php | ||
phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="HOST" value="127.0.0.1"/> | ||
<env name="PORT" value="5672"/> | ||
</php> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-html" target="tests/coverage" charset="UTF-8" yui="true" highlight="true"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Connectors\RabbitMQConnector; | ||
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue; | ||
|
||
class RabbitMQConnectorTest extends TestCase | ||
{ | ||
|
||
public function test_connect() | ||
{ | ||
$config = [ | ||
'host' => getenv('HOST'), | ||
'port' => getenv('PORT'), | ||
'login' => 'guest', | ||
'password' => 'guest', | ||
'vhost' => '/', | ||
|
||
'queue' => 'queue_name', | ||
'exchange_declare' => true, | ||
'queue_declare_bind' => true, | ||
|
||
'queue_params' => [ | ||
'passive' => false, | ||
'durable' => true, | ||
'exclusive' => false, | ||
'auto_delete' => false, | ||
], | ||
'exchange_params' => [ | ||
'name' => null, | ||
'type' => 'direct', | ||
'passive' => false, | ||
'durable' => true, | ||
'auto_delete' => false, | ||
], | ||
]; | ||
|
||
$connector = new RabbitMQConnector(); | ||
$queue = $connector->connect($config); | ||
|
||
$this->assertInstanceOf(RabbitMQQueue::class, $queue); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<?php | ||
|
||
use Illuminate\Container\Container; | ||
use PhpAmqpLib\Channel\AMQPChannel; | ||
use PhpAmqpLib\Connection\AMQPStreamConnection; | ||
use PhpAmqpLib\Message\AMQPMessage; | ||
use PHPUnit\Framework\TestCase; | ||
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue; | ||
|
||
/** | ||
* @property \Mockery\MockInterface connection | ||
* @property \Mockery\MockInterface channel | ||
* @property array config | ||
* @property RabbitMQQueue queue | ||
*/ | ||
class RabbitMQQueueTest extends TestCase | ||
{ | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->connection = Mockery::mock(AMQPStreamConnection::class); | ||
$this->channel = Mockery::mock(AMQPChannel::class); | ||
|
||
$this->connection->shouldReceive('channel')->andReturn($this->channel); | ||
|
||
$this->config = [ | ||
'queue' => str_random(), | ||
'queue_params' => [ | ||
'passive' => false, | ||
'durable' => true, | ||
'exclusive' => false, | ||
'auto_delete' => false, | ||
], | ||
'exchange_params' => [ | ||
'name' => 'exchange_name', | ||
'type' => 'direct', | ||
'passive' => false, | ||
'durable' => true, | ||
'auto_delete' => false, | ||
], | ||
'exchange_declare' => true, | ||
'queue_declare_bind' => true, | ||
]; | ||
|
||
$this->queue = new RabbitMQQueue($this->connection, $this->config); | ||
} | ||
|
||
public function test_size() | ||
{ | ||
$this->queue->size(); | ||
} | ||
|
||
public function test_push() | ||
{ | ||
$job = new TestJob(); | ||
$data = []; | ||
|
||
$this->channel->shouldReceive('exchange_declare')->with( | ||
$this->config['exchange_params']['name'], | ||
$this->config['exchange_params']['type'], | ||
$this->config['exchange_params']['passive'], | ||
$this->config['exchange_params']['durable'], | ||
$this->config['exchange_params']['auto_delete'] | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('queue_declare')->with( | ||
$this->config['queue'], | ||
$this->config['queue_params']['passive'], | ||
$this->config['queue_params']['durable'], | ||
$this->config['queue_params']['exclusive'], | ||
$this->config['queue_params']['auto_delete'] | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('queue_bind')->with( | ||
$this->config['queue'], | ||
$this->config['exchange_params']['name'], | ||
$this->config['queue'] | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('basic_publish')->once(); | ||
|
||
$correlationId = $this->queue->push($job, $data); | ||
|
||
$this->assertEquals(13, strlen($correlationId)); | ||
} | ||
|
||
public function test_later() | ||
{ | ||
$job = new TestJob(); | ||
$data = []; | ||
$delay = mt_rand(10, 60); | ||
|
||
$this->channel->shouldReceive('exchange_declare')->with( | ||
$this->config['exchange_params']['name'], | ||
$this->config['exchange_params']['type'], | ||
$this->config['exchange_params']['passive'], | ||
$this->config['exchange_params']['durable'], | ||
$this->config['exchange_params']['auto_delete'] | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('queue_declare')->once(); | ||
|
||
// main queue | ||
$this->channel->shouldReceive('queue_bind')->with( | ||
$this->config['queue'], | ||
$this->config['exchange_params']['name'], | ||
$this->config['queue'] | ||
)->once(); | ||
|
||
// delayed queue | ||
$this->channel->shouldReceive('queue_bind')->with( | ||
$this->config['queue'] . '_deferred_' . $delay, | ||
$this->config['exchange_params']['name'], | ||
$this->config['queue'] . '_deferred_' . $delay | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('basic_publish')->once(); | ||
|
||
$correlationId = $this->queue->later($delay, $job, $data); | ||
|
||
$this->assertEquals(13, strlen($correlationId)); | ||
} | ||
|
||
public function test_pop() | ||
{ | ||
$message = Mockery::mock(AMQPMessage::class); | ||
|
||
$this->channel->shouldReceive('exchange_declare')->with( | ||
$this->config['exchange_params']['name'], | ||
$this->config['exchange_params']['type'], | ||
$this->config['exchange_params']['passive'], | ||
$this->config['exchange_params']['durable'], | ||
$this->config['exchange_params']['auto_delete'] | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('queue_declare')->with( | ||
$this->config['queue'], | ||
$this->config['queue_params']['passive'], | ||
$this->config['queue_params']['durable'], | ||
$this->config['queue_params']['exclusive'], | ||
$this->config['queue_params']['auto_delete'] | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('queue_bind')->with( | ||
$this->config['queue'], | ||
$this->config['exchange_params']['name'], | ||
$this->config['queue'] | ||
)->once(); | ||
|
||
$this->channel->shouldReceive('basic_get')->with($this->config['queue'])->andReturn($message)->once(); | ||
|
||
$this->queue->setContainer(Mockery::mock(Container::class)); | ||
$this->queue->pop(); | ||
} | ||
|
||
public function test_setAttempts() { | ||
$count = mt_rand(); | ||
|
||
$this->queue->setAttempts($count); | ||
} | ||
|
||
public function test_setCorrelationId() { | ||
$id = str_random(); | ||
|
||
$this->queue->setCorrelationId($id); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class TestJob | ||
{ | ||
|
||
public function handle() | ||
{ | ||
|
||
} | ||
|
||
} |