diff --git a/src/Connection.php b/src/Connection.php index 4b11d41..6cb4beb 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -172,9 +172,49 @@ public function fetchQueueConsumers($queueName, string $columns = 'consumer_deta return $http->get($request)->json(); } + /** + * Clean up resources + */ public function __destruct() { - $this->channel->close(); - $this->connection->close(); + if ($this->channel) { + $this->channel->close(); + } + + if ($this->connection) { + $this->connection->close(); + } + } + + /** + * @return int + */ + public function getConnectionTimeout() + { + return $this->connectionTimeout; + } + + /** + * @return int + */ + public function getReadWriteTimeout() + { + return $this->readWriteTimeout; + } + + /** + * @return int + */ + public function getHeartbeat() + { + return $this->heartbeat; + } + + /** + * @return string + */ + public function getVhost() + { + return $this->vhost; } } diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 2522210..2405058 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -54,6 +54,7 @@ public function test_set_default_configurations_values() { $mConnection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() + ->setMethods(null) ->getMock(); $this->app->bind(Connection::class, function () use ($mConnection) { @@ -61,10 +62,10 @@ public function test_set_default_configurations_values() }); $connection = $this->app[Connection::class]; - $this->assertAttributeEquals(15, 'heartbeat', $connection); - $this->assertAttributeEquals(30, 'readWriteTimeout', $connection); - $this->assertAttributeEquals(30, 'connectionTimeout', $connection); - $this->assertAttributeEquals('/', 'vhost', $connection); + $this->assertEquals(15, $connection->getHeartbeat()); + $this->assertEquals(30, $connection->getReadWriteTimeout()); + $this->assertEquals(30, $connection->getConnectionTimeout()); + $this->assertEquals('/', $connection->getVhost()); } public function test_set_altered_configurations_values() @@ -88,9 +89,9 @@ public function test_set_altered_configurations_values() $connection = $this->app[Connection::class]; - $this->assertAttributeEquals(30, 'heartbeat', $connection); - $this->assertAttributeEquals(60, 'readWriteTimeout', $connection); - $this->assertAttributeEquals(60, 'connectionTimeout', $connection); - $this->assertAttributeEquals('/test-vhost', 'vhost', $connection); + $this->assertEquals(30, $connection->getHeartbeat()); + $this->assertEquals(60, $connection->getReadWriteTimeout()); + $this->assertEquals(60, $connection->getConnectionTimeout()); + $this->assertEquals('/test-vhost', $connection->getVhost()); } }