Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KinaneD committed Dec 11, 2020
1 parent 70e7b56 commit 7c38b2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Console/Commands/ConsumerHealthCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Vinelab\Bowler\Console\Commands;

use ErrorException;
use Exception;
use Illuminate\Console\Command;
use PhpAmqpLib\Exception\AMQPProtocolChannelException;
use Vinelab\Bowler\Connection;
Expand Down Expand Up @@ -40,7 +40,7 @@ public function handle()
// may or may not be able to connect
try {
$connection = app(Connection::class);
} catch (ErrorException $e) {
} catch (Exception $e) {
$this->error('Unable to connect to RabbitMQ.');

return 1;
Expand Down
23 changes: 12 additions & 11 deletions tests/Console/Commands/ConsumerHealthCheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class ConsumerHealthCheckCommandTest extends TestCase
{
public function tearDown() : void
public function tearDown(): void
{
M::close();
}
Expand All @@ -38,7 +38,7 @@ public function test_checking_consumer_successfully()
])));

$mChannel = M::mock(AMQPChannel::class);
$mChannel::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib\Wire\Constants091';

$mChannel->shouldReceive('queue_declare')->once()->andReturn([$queueName, 10, 1]);
$mConnection->shouldReceive('getChannel')->once()->andReturn($mChannel);

Expand All @@ -48,7 +48,7 @@ public function test_checking_consumer_successfully()

$result = $this->artisan('bowler:healthcheck:consumer', ['queueName' => $queueName]);

if($result instanceof PendingCommand) {
if ($result instanceof PendingCommand) {
$this->assertEquals(0, $result->run());
} else {
$this->assertEquals(0, $result);
Expand All @@ -70,8 +70,8 @@ public function test_with_no_consumers_connected()
$mConnection->shouldReceive('fetchQueueConsumers')->once()->andReturn(json_decode(json_encode([])));

$mChannel = M::mock(AMQPChannel::class);
$mChannel::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib\Wire\Constants091';
$mChannel->shouldReceive('queue_declare')->once()->andReturn([$queueName, 10, 1]);

$mConnection->shouldReceive('getChannel')->once()->andReturn($mChannel);

$this->app->bind(Connection::class, function () use ($mConnection) {
Expand All @@ -80,7 +80,7 @@ public function test_with_no_consumers_connected()

$result = $this->artisan('bowler:healthcheck:consumer', ['queueName' => $queueName]);

if($result instanceof PendingCommand) {
if ($result instanceof PendingCommand) {
$this->assertEquals(1, $result->run());
} else {
$this->assertEquals(1, $result);
Expand All @@ -95,7 +95,9 @@ public function test_with_consumer_tag_not_found()
$queueName = 'queue-to-consume';
$consumerTag = 'amqp.98oyiuahksjdf';

$command->shouldReceive('error')->once()->with('Health check failed! Could not find consumer with tag "'.$consumerTag.'"');
$command->shouldReceive('error')
->once()
->with('Health check failed! Could not find consumer with tag "' . $consumerTag . '"');

$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);

Expand All @@ -110,7 +112,6 @@ public function test_with_consumer_tag_not_found()
])));

$mChannel = M::mock(AMQPChannel::class);
$mChannel::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib\Wire\Constants091';
$mChannel->shouldReceive('queue_declare')->once()->andReturn([$queueName, 10, 0]);
$mConnection->shouldReceive('getChannel')->once()->andReturn($mChannel);

Expand All @@ -120,7 +121,7 @@ public function test_with_consumer_tag_not_found()

$result = $this->artisan('bowler:healthcheck:consumer', ['queueName' => $queueName]);

if($result instanceof PendingCommand) {
if ($result instanceof PendingCommand) {
$this->assertEquals(1, $result->run());
} else {
$this->assertEquals(1, $result);
Expand All @@ -136,8 +137,8 @@ public function test_healthcheck_with_queue_does_not_exist()
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);

$mConnection = M::mock(Connection::class);

$mChannel = M::mock(AMQPChannel::class);
$mChannel::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib\Wire\Constants091';
$exception = new AMQPProtocolChannelException(404, "NOT_FOUND - no queue 'the-queue' in vhost '/'", [50, 10]);
$mChannel->shouldReceive('queue_declare')->once()
->with('the-queue', true, false, false, false, [])
Expand All @@ -150,7 +151,7 @@ public function test_healthcheck_with_queue_does_not_exist()

$result = $this->artisan('bowler:healthcheck:consumer', ['queueName' => 'the-queue']);

if($result instanceof PendingCommand) {
if ($result instanceof PendingCommand) {
$this->assertEquals(1, $result->run());
} else {
$this->assertEquals(1, $result);
Expand All @@ -170,7 +171,7 @@ public function test_error_connecting_to_rabbitmq()

$result = $this->artisan('bowler:healthcheck:consumer', ['queueName' => 'the-queue']);

if($result instanceof PendingCommand) {
if ($result instanceof PendingCommand) {
$this->assertEquals(1, $result->run());
} else {
$this->assertEquals(1, $result);
Expand Down

0 comments on commit 7c38b2b

Please sign in to comment.