diff --git a/src/Console/Commands/ConsumerHealthCheckCommand.php b/src/Console/Commands/ConsumerHealthCheckCommand.php index 2959a77..7ab7606 100644 --- a/src/Console/Commands/ConsumerHealthCheckCommand.php +++ b/src/Console/Commands/ConsumerHealthCheckCommand.php @@ -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; @@ -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; diff --git a/tests/Console/Commands/ConsumerHealthCheckCommandTest.php b/tests/Console/Commands/ConsumerHealthCheckCommandTest.php index 7c7ac50..7a82290 100644 --- a/tests/Console/Commands/ConsumerHealthCheckCommandTest.php +++ b/tests/Console/Commands/ConsumerHealthCheckCommandTest.php @@ -14,7 +14,7 @@ */ class ConsumerHealthCheckCommandTest extends TestCase { - public function tearDown() : void + public function tearDown(): void { M::close(); } @@ -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); @@ -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); @@ -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) { @@ -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); @@ -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); @@ -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); @@ -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); @@ -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, []) @@ -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); @@ -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);