diff --git a/.gitignore b/.gitignore index d51ebd0..d8dda7b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ composer.phar composer.lock /tests/phpunit_report /docs/source/API/API/cache/ +.phpunit.result.cache + + diff --git a/README.md b/README.md index b950b80..4d09d7d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,37 @@ [![Build Status](https://secure.travis-ci.org/alchemy-fr/RabbitMQ-Management-API-Client.png?branch=master)](https://travis-ci.org/alchemy-fr/RabbitMQ-Management-API-Client) +**Update:** This branch is an update to this library to allow it to work with modern (circa 2019) versions of +PHP (>=7.2), RabbitMQ, Guzzle, React, Doctrine, PHPUnit and related support libraries. (see composer.json for +version details) The existing version had too many dependencies on deprecated versions of other libraries +preventing it from being utilized on new projects. This update fixes that. + +Extensive changes were needed under the hood but the API should remain nearly +identical with the exception of the exceptions thrown from the non-async client code. + +Cases involving a non-existent entity (now including Add methods, such as trying to add a binding to a +non-existent vhost) are now uniformly thrown as RabbitMQ\Management\Exception\EntityNotFoundException +where previously some were RabbitMQ\Management\Exception\RuntimeException. Other exceptions from the +underlying Guzzle library are now passed through as GuzzleHttp\Exception\ClientException rather than +GuzzleHttp\Exception\RequestException due to changes in Guzzle. + +Note that the properties and format thereof returned in queries are dependent on +the rabbitmq server version. The properties defined in the Entity classes of +this package have been updated to include those provided by RabbitMQ 3.8 (with some +older ones retained but not necessarily populated.) These are primarily +provided for reference and code hinting in IDEs but your results may +vary with an actual server. Differences between the defined entity classes +and the properties returned by the server are silently ignored and all +results returned are passed through. + +Note also that due to management api caching and statistics collection +intervals, the results returned from queries may be incomplete or delayed. +Creating an object and then immediately querying it may yield incomplete +or missing results. Because of this, the unit tests have built in delays +to wait before checking the returned results in various tests. + +*(end update message)* + This library is intended to help management of RabbitMQ server in an application. It provides two ways to query RabbitMQ : Synchronous query with Guzzle and Asynchronous query with React. diff --git a/composer.json b/composer.json index 8570688..b5c1f5d 100644 --- a/composer.json +++ b/composer.json @@ -1,38 +1,42 @@ { - "name": "eagle-eye-solutions/rabbitmq-management-client", - "type": "library", - "description": "RabbitMQ Management Plugin API Client", - "keywords": ["api", "rabbitmq", "management"], - "license": "MIT", - "authors": [ - { - "name": "Romain Neutron", - "email": "imprec@gmail.com" - } - ], - "require": { - "doctrine/common": ">=2.0", - "guzzlehttp/guzzle": "~6.0" - }, - "require-dev": { - "videlalvaro/php-amqplib": "dev-master@dev", - "sami/sami": "~1.0", - "phpunit/phpunit": "7.0.*", - "react/promise": "~1.0", - "react/react": "~0.2.0", - "react/curry": "~1.0" - }, - "autoload": { - "psr-0": { - "RabbitMQ": "src" - } - }, - "suggest": { - "react/react": "Version 0.2 to use the async client" - }, - "extra": { - "branch-alias": { - "dev-master": "0.1.x-dev" - } + "name": "eagle-eye-solutions/rabbitmq-management-client", + "type": "library", + "description": "RabbitMQ Management Plugin API Client", + "keywords": [ + "api", + "rabbitmq", + "management" + ], + "license": "MIT", + "authors": [ + { + "name": "Romain Neutron", + "email": "imprec@gmail.com" } + ], + "require": { + "doctrine/common": ">=2.6.3", + "guzzlehttp/guzzle": ">=6.3.3", + "ext-json": "*" + }, + "require-dev": { + "php-amqplib/php-amqplib": "dev-master", + "phpunit/phpunit": ">=7.0", + "react/http-client": "^0.5.9", + "react/partial": "~2.0", + "seregazhuk/react-promise-testing": "dev-master" + }, + "autoload": { + "psr-0": { + "RabbitMQ": "src" + } + }, + "suggest": { + "react/react": "Version 0.2 to use the async client" + }, + "extra": { + "branch-alias": { + "dev-master": "0.1.x-dev" + } + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a33b0e0..3d4ce44 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,13 +7,11 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="true" verbose="false" bootstrap="tests/bootstrap.php" > - @@ -26,10 +24,9 @@ - - vendor - tests - + + src + diff --git a/src/RabbitMQ/Management/APIClient.php b/src/RabbitMQ/Management/APIClient.php index 97c6f5c..5548b0a 100644 --- a/src/RabbitMQ/Management/APIClient.php +++ b/src/RabbitMQ/Management/APIClient.php @@ -1,9 +1,10 @@ client = $client; - $this->config = $config; $this->hydrator = new Hydrator(); } @@ -37,19 +37,28 @@ public function listConnections() return $this->retrieveCollection('/api/connections', 'RabbitMQ\Management\Entity\Connection'); } + public function getConnection($name) { - $uri = sprintf('/api/connections/%s', urlencode($name)); + $uri = sprintf('/api/connections/%s', rawurlencode($name)); - return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Connection'); + try { + return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Connection'); + } catch (EntityNotFoundException $e) { + throw new EntityNotFoundException('Failed to find connection: ' . $name, $e->getCode(), $e); + } } + public function deleteConnection($name) { try { - $this->client->delete(sprintf('/api/connections/%s', urlencode($name))); - } catch (RequestException $e) { - throw new RuntimeException('Failed to delete connection', $e->getCode(), $e); + $this->client->delete(sprintf('/api/connections/%s', rawurlencode($name))); + } catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new EntityNotFoundException('Connection not found: ' . $name); + } + throw $e; } return $this; @@ -62,15 +71,19 @@ public function listChannels() public function getChannel($name, Channel $channel = null) { - $uri = sprintf('/api/channels/%s', urlencode($name)); + $uri = sprintf('/api/channels/%s', rawurlencode($name)); - return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Channel', $channel); + try { + return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Channel', $channel); + } catch (EntityNotFoundException $e) { + throw new EntityNotFoundException('Failed to find channel: ' . $name); + } } public function listExchanges($vhost = null) { if (null !== $vhost) { - $uri = sprintf('/api/exchanges/%s', urlencode($vhost)); + $uri = sprintf('/api/exchanges/%s', rawurlencode($vhost)); } else { $uri = '/api/exchanges'; } @@ -88,9 +101,13 @@ public function getExchange($vhost, $name, Exchange $exchange = null) throw new InvalidArgumentException('Queue requires a name'); } - $uri = sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)); + $uri = sprintf('/api/exchanges/%s/%s', rawurlencode($vhost), rawurlencode($name)); - return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Exchange', $exchange); + try { + return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Exchange', $exchange); + } catch (EntityNotFoundException $e) { + throw new EntityNotFoundException('Failed to find exchange: ' . $name); + } } public function deleteExchange($vhost, $name) @@ -103,22 +120,30 @@ public function deleteExchange($vhost, $name) throw new InvalidArgumentException('Queue requires a name'); } - $uri = sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)); + $uri = sprintf('/api/exchanges/%s/%s', rawurlencode($vhost), rawurlencode($name)); try { $this->client->delete($uri); - } catch (RequestException $e) { - throw new RuntimeException('Unable to delete exchange', $e->getCode(), $e); + } catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new EntityNotFoundException('Unable to find exchange for deletion: ' . $vhost . '/' . $name); + } + throw $e; } + return $this; } public function refreshExchange(Exchange $exchange) { - $uri = sprintf('/api/exchanges/%s/%s', urlencode($exchange->vhost), urlencode($exchange->name)); + $uri = sprintf('/api/exchanges/%s/%s', rawurlencode($exchange->vhost), rawurlencode($exchange->name)); - return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Exchange', $exchange); + try { + return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Exchange', $exchange); + } catch (EntityNotFoundException $e) { + throw new EntityNotFoundException('Failed ot find exchange: ' . $exchange->vhost . '/' . $exchange->name); + } } public function addExchange(Exchange $exchange) @@ -131,22 +156,17 @@ public function addExchange(Exchange $exchange) throw new InvalidArgumentException('Exchange requires a name'); } - $uri = sprintf('/api/exchanges/%s/%s', urlencode($exchange->vhost), urlencode($exchange->name)); - + $uri = sprintf('/api/exchanges/%s/%s', rawurlencode($exchange->vhost), rawurlencode($exchange->name)); + $json = $exchange->toJson(); try { - $response = $this->client->put($uri, [ - 'headers' => [ - 'Content-Type' => 'application/json', - ], - 'body' => $exchange->toJson(), - ]); - } catch (RequestException $e) { - if ($data = json_decode($e->getResponse()->getBody(true), true)) { - if (isset($data['reason']) && strpos($data['reason'], '406 PRECONDITION_FAILED') === 0) { + $this->client->put($uri, ['headers' => ['Content-Type' => 'application/json'], 'body' => $json]); + } catch (ClientException $e) { + if ($data = json_decode($e->getResponse()->getBody(), true)) { + if (isset($data['reason']) && strpos($data['reason'], 'inequivalent arg') === 0) { throw new PreconditionFailedException('Exchange already exists with different properties', $e->getCode(), $e); } } - throw new RuntimeException('Unable to put the exchange', $e->getCode(), $e); + throw $e; } return $this->getExchange($exchange->vhost, $exchange->name, $exchange); @@ -155,26 +175,40 @@ public function addExchange(Exchange $exchange) public function listQueues($vhost = null) { if (null !== $vhost) { - $uri = sprintf('/api/queues/%s', urlencode($vhost)); + $uri = sprintf('/api/queues/%s', rawurlencode($vhost)); } else { $uri = '/api/queues'; } - - return $this->retrieveCollection($uri, 'RabbitMQ\Management\Entity\Queue'); + try { + return $this->retrieveCollection($uri, 'RabbitMQ\Management\Entity\Queue'); + } catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new EntityNotFoundException("Failed to find virtual host to list queues: " . $vhost); + } + throw $e; + } } public function getQueue($vhost, $name, Queue $queue = null) { - $uri = sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name)); + $uri = sprintf('/api/queues/%s/%s', rawurlencode($vhost), rawurlencode($name)); - return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Queue', $queue); + try { + return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Queue', $queue); + } catch (EntityNotFoundException $e) { + throw new EntityNotFoundException('Failed to find queue: ' . $vhost . '/' . $name); + } } public function refreshQueue(Queue $queue) { - $uri = sprintf('/api/queues/%s/%s', urlencode($queue->vhost), urlencode($queue->name)); + $uri = sprintf('/api/queues/%s/%s', rawurlencode($queue->vhost), rawurlencode($queue->name)); - return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Queue', $queue); + try { + return $this->retrieveEntity($uri, 'RabbitMQ\Management\Entity\Queue', $queue); + } catch (EntityNotFoundException $e) { + throw new EntityNotFoundException('Failed to find queue:' . $queue->vhost . '/' . $queue->name); + } } public function addQueue(Queue $queue) @@ -187,22 +221,20 @@ public function addQueue(Queue $queue) throw new InvalidArgumentException('Queue requires a name'); } - $uri = sprintf('/api/queues/%s/%s', urlencode($queue->vhost), urlencode($queue->name)); + $uri = sprintf('/api/queues/%s/%s', rawurlencode($queue->vhost), rawurlencode($queue->name)); try { - $this->client->put($uri, [ - 'headers' => [ - 'Content-type' => 'application/json', - ], - 'body' => $queue->toJson(), - ]); - } catch (RequestException $e) { - if ($data = json_decode($e->getResponse()->getBody(true), true)) { - if (isset($data['reason']) && strpos($data['reason'], '406 PRECONDITION_FAILED') === 0) { + $this->client->put($uri, ['headers' => ['Content-type' => 'application/json'], 'body' => $queue->toJson()]); + } catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new EntityNotFoundException("Failed to find virtual host to add queue: " . $queue->vhost); + } + if ($data = json_decode($e->getResponse()->getBody(), true)) { + if (isset($data['reason']) && strpos($data['reason'], 'inequivalent arg') === 0) { throw new PreconditionFailedException('Queue already exists with different properties', $e->getCode(), $e); } } - throw new RuntimeException('Unable to put the queue', $e->getCode(), $e); + throw $e; } return $this->getQueue($queue->vhost, $queue->name, $queue); @@ -220,10 +252,13 @@ public function deleteQueue($vhost, $name) try { $this->client->delete( - sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name)) + sprintf('/api/queues/%s/%s', rawurlencode($vhost), rawurlencode($name)) ); - } catch (RequestException $e) { - throw new RuntimeException('Unable to delete queue', $e->getCode(), $e); + } catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new EntityNotFoundException('Unable to find queue to delete: ' . $vhost . '/' . $name); + } + throw $e; } return $this; @@ -241,10 +276,13 @@ public function purgeQueue($vhost, $name) try { $this->client->delete( - sprintf('/api/queues/%s/%s/contents', urlencode($vhost), urlencode($name)) + sprintf('/api/queues/%s/%s/contents', rawurlencode($vhost), rawurlencode($name)) ); - } catch (RequestException $e) { - throw new RuntimeException('Unable to purge queue', $e->getCode(), $e); + } catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new EntityNotFoundException('Unable to find queue to purge: ' . $vhost . '/' . $name); + } + throw $e; } return $this; @@ -252,44 +290,45 @@ public function purgeQueue($vhost, $name) public function listBindingsByQueue(Queue $queue) { - $uri = sprintf('/api/queues/%s/%s/bindings', urlencode($queue->vhost), urlencode($queue->name)); + $uri = sprintf('/api/queues/%s/%s/bindings', rawurlencode($queue->vhost), rawurlencode($queue->name)); return $this->retrieveCollection($uri, 'RabbitMQ\Management\Entity\Binding'); } public function listBindingsByExchangeAndQueue($vhost, $exchange, $queue) { - $uri = sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($vhost), urlencode($exchange), urlencode($queue)); + $uri = sprintf('/api/bindings/%s/e/%s/q/%s', rawurlencode($vhost), rawurlencode($exchange), rawurlencode($queue)); return $this->retrieveCollection($uri, 'RabbitMQ\Management\Entity\Binding'); } public function addBinding(Binding $binding) { - $uri = sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($binding->vhost), urlencode($binding->source), urlencode($binding->destination)); + $uri = sprintf('/api/bindings/%s/e/%s/q/%s', rawurlencode($binding->vhost), rawurlencode($binding->source), rawurlencode($binding->destination)); try { - $this->client->post($uri, [ - 'headers' => [ - 'Content-type' => 'application/json', - ], - 'body' => $binding->toJson(), - ]); + $this->client->post($uri, ['headers' => ['Content-type' => 'application/json'], 'body' => $binding->toJson()]); } catch (RequestException $e) { - throw new RuntimeException('Unable to add binding', $e->getCode(), $e); - } + if ($e->getCode() == 404) { + throw new EntityNotFoundException("Failed to find vhost for adding binding: " . $binding->vhost); + } + throw $e; + } return $this; } public function deleteBinding($vhost, $exchange, $queue, Binding $binding) { - $uri = sprintf('/api/bindings/%s/e/%s/q/%s/%s', urlencode($vhost), urlencode($exchange), urlencode($queue), urlencode($binding->properties_key)); + $uri = sprintf('/api/bindings/%s/e/%s/q/%s/%s', rawurlencode($vhost), rawurlencode($exchange), rawurlencode($queue), rawurlencode($binding->properties_key)); try { $this->client->delete($uri); - } catch (RequestException $e) { - throw new RuntimeException('Unable to delete binding', $e->getCode(), $e); + } catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new EntityNotFoundException('Unable to find binding to delete: ' . $vhost . '/' . $exchange . '/' . $queue . '/' . $binding->properties_key); + } + throw $e; } return $this; @@ -298,7 +337,7 @@ public function deleteBinding($vhost, $exchange, $queue, Binding $binding) public function listBindings($vhost = null) { if (null !== $vhost) { - $uri = sprintf('/api/bindings/%s', urlencode($vhost)); + $uri = sprintf('/api/bindings/%s', rawurlencode($vhost)); } else { $uri = '/api/bindings'; } @@ -309,15 +348,15 @@ public function listBindings($vhost = null) public function alivenessTest($vhost) { try { - $response = $this->client->get(sprintf('/api/aliveness-test/%s', urlencode($vhost))); - $data = json_decode((string)$response->getBody(), true); + $res = $this->client->get(sprintf('/api/aliveness-test/%s', rawurlencode($vhost)))->getBody(); + $data = json_decode($res, true); if (!isset($data['status']) || $data['status'] !== 'ok') { return false; } $this->deleteQueue($vhost, 'aliveness-test'); - } catch (RequestException $e) { + } catch (ClientException $e) { return false; } @@ -327,31 +366,28 @@ public function alivenessTest($vhost) private function retrieveEntity($uri, $targetEntity, EntityInterface $entity = null) { try { - $response = $this->client->get($uri); - } catch (RequestException $e) { + //$res = $this->client->get($uri)->getBody(); + //$res = $this->client->get($uri)->getBody(); + $res = $this->client->get($uri)->getBody(); + } catch (ClientException $e) { if ($e->getResponse()->getStatusCode() === 404) { throw new EntityNotFoundException('Entity not found', $e->getCode(), $e); } - - throw new RuntimeException('Error while getting the entity', $e->getCode(), $e); + throw $e; } if (null === $entity) { $entity = new $targetEntity(); } - return $this->hydrator->hydrate($entity, json_decode((string)$response->getBody(), true)); + return $this->hydrator->hydrate($entity, json_decode($res, true)); } private function retrieveCollection($uri, $targetEntity) { - try { - $response = $this->client->get($uri); - } catch (RequestException $e) { - throw new RuntimeException(sprintf('Unable to fetch data for %s', $targetEntity), $e->getCode(), $e); - } + $res = $this->client->get($uri)->getBody(); - $data = json_decode((string)$response->getBody(), true); + $data = json_decode($res, true); $collection = new ArrayCollection(); diff --git a/src/RabbitMQ/Management/AsyncAPIClient.php b/src/RabbitMQ/Management/AsyncAPIClient.php index f695494..43b7c59 100644 --- a/src/RabbitMQ/Management/AsyncAPIClient.php +++ b/src/RabbitMQ/Management/AsyncAPIClient.php @@ -1,8 +1,11 @@ 15672, - 'user' => 'guest', + 'port' => 15672, + 'user' => 'guest', 'password' => 'guest', - 'scheme' => 'http', - 'url' => '127.0.0.1', + 'scheme' => 'http', + 'url' => '127.0.0.1', ); $options = array_merge($defaultOptions, $options); - $dnsResolverFactory = new DnsResolverFactory(); - $dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop); - - $connectionManager = new ConnectionManager($loop, $dnsResolver); - $secureConnectionManager = new SecureConnectionManager($loop, $dnsResolver); - $client = new Client($loop, $connectionManager, $secureConnectionManager); + $client = new Client($loop); return new self($client, $options); } @@ -59,47 +54,45 @@ public function __construct(Client $client, array $options) public function listConnections() { return $this->executeRequest('GET', '/api/connections') - ->then(Curry::bind(array($this, 'handleCollectionData'), 'Connection')); + ->then(bind(array($this, 'handleCollectionData'), 'Connection')); } public function getConnection($name) { - return $this->executeRequest('GET', sprintf('/api/connections/%s', urlencode($name))) - ->then(Curry::bind(array($this, 'handleEntityData'), new Connection())); + return $this->executeRequest('GET', sprintf('/api/connections/%s', rawurlencode($name))) + ->then(bind(array($this, 'handleEntityData'), new Connection())); } public function deleteConnection($name) { - return $this->executeRequest('DELETE', sprintf('/api/connections/%s', urlencode($name))); + return $this->executeRequest('DELETE', sprintf('/api/connections/%s', rawurlencode($name))); } private function executeRequest($method, $uri, $body = null) { $deferred = new Deferred(); - $request = $this->client->request($method, $this->buildUrl($uri), array('Content-Length' => strlen($body), 'Authorization' => 'Basic ' . base64_encode($this->options['user'] . ':' . $this->options['password']), 'Content-Type' => 'application/json')); + $request = $this->client->request($method, $this->buildUrl($uri), array('Content-Length' => strlen($body), 'Authorization' => 'Basic ' . base64_encode($this->options['user'] . ':' . $this->options['password']), 'Content-Type' => 'application/json')); - $request->writeHead(); - - $request->on('error', function ($error) use ($uri, $deferred) { + $request->on('error', function (Exception $error) use ($uri, $deferred) { $deferred->reject(sprintf('Error while doing the request on %s : %s', $uri, $error->getMessage())); }); - $request->on('response', function(Response $response) use ($deferred) { + $request->on('response', function (Response $response) use ($deferred) { if ($response->getCode() < 200 || $response->getCode() >= 400) { $deferred->reject(sprintf('The response is not as expected (status code %s, message is %s)', $response->getCode(), $response->getReasonPhrase())); } - $response->on('error', function($error) use ($deferred) { + $response->on('error', function (Exception $error) use ($deferred) { $deferred->reject($error->getMessage()); }); - $data = (object) array('data' => ''); + $data = (object)array('data' => ''); - $response->on('data', function($chunk) use ($data) { + $response->on('data', function ($chunk) use ($data) { $data->data .= $chunk; }); - $response->on('end', function() use ($deferred, $data) { + $response->on('end', function () use ($deferred, $data) { $deferred->resolve($data->data); }); }); @@ -112,25 +105,25 @@ private function executeRequest($method, $uri, $body = null) public function listChannels() { return $this->executeRequest('GET', '/api/channels') - ->then(Curry::bind(array($this, 'handleCollectionData'), 'Channel')); + ->then(bind(array($this, 'handleCollectionData'), 'Channel')); } public function getChannel($name, Channel $channel = null) { - return $this->executeRequest('GET', sprintf('/api/channels/%s', urlencode($name))) - ->then(Curry::bind(array($this, 'handleEntityData'), $channel ? : new Channel())); + return $this->executeRequest('GET', sprintf('/api/channels/%s', rawurlencode($name))) + ->then(bind(array($this, 'handleEntityData'), $channel ?: new Channel())); } public function listExchanges($vhost = null) { if (null !== $vhost) { - $uri = sprintf('/api/exchanges/%s', urlencode($vhost)); + $uri = sprintf('/api/exchanges/%s', rawurlencode($vhost)); } else { $uri = '/api/exchanges'; } return $this->executeRequest('GET', $uri) - ->then(Curry::bind(array($this, 'handleCollectionData'), 'Exchange')); + ->then(bind(array($this, 'handleCollectionData'), 'Exchange')); } public function getExchange($vhost, $name, Exchange $exchange = null) @@ -143,8 +136,8 @@ public function getExchange($vhost, $name, Exchange $exchange = null) throw new InvalidArgumentException('Queue requires a name'); } - return $this->executeRequest('GET', sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name))) - ->then(Curry::bind(array($this, 'handleEntityData'), $exchange ? : new Exchange())); + return $this->executeRequest('GET', sprintf('/api/exchanges/%s/%s', rawurlencode($vhost), rawurlencode($name))) + ->then(bind(array($this, 'handleEntityData'), $exchange ?: new Exchange())); } public function deleteExchange($vhost, $name) @@ -157,7 +150,7 @@ public function deleteExchange($vhost, $name) throw new InvalidArgumentException('Queue requires a name'); } - return $this->executeRequest('DELETE', sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name))); + return $this->executeRequest('DELETE', sprintf('/api/exchanges/%s/%s', rawurlencode($vhost), rawurlencode($name))); } public function refreshExchange(Exchange $exchange) @@ -175,26 +168,26 @@ public function addExchange(Exchange $exchange) throw new InvalidArgumentException('Exchange requires a name'); } - return $this->executeRequest('PUT', sprintf('/api/exchanges/%s/%s', urlencode($exchange->vhost), urlencode($exchange->name)), $exchange->toJson()) - ->then(Curry::bind(array($this, 'getExchange'), $exchange->vhost, $exchange->name, $exchange)); + return $this->executeRequest('PUT', sprintf('/api/exchanges/%s/%s', rawurlencode($exchange->vhost), rawurlencode($exchange->name)), $exchange->toJson()) + ->then(bind(array($this, 'getExchange'), $exchange->vhost, $exchange->name, $exchange)); } public function listQueues($vhost = null) { if (null !== $vhost) { - $uri = sprintf('/api/queues/%s', urlencode($vhost)); + $uri = sprintf('/api/queues/%s', rawurlencode($vhost)); } else { $uri = '/api/queues'; } return $this->executeRequest('GET', $uri) - ->then(Curry::bind(array($this, 'handleCollectionData'), 'Queue')); + ->then(bind(array($this, 'handleCollectionData'), 'Queue')); } public function getQueue($vhost, $name, Queue $queue = null) { - return $this->executeRequest('GET', sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name))) - ->then(Curry::bind(array($this, 'handleEntityData'), $queue ? : new Queue())); + return $this->executeRequest('GET', sprintf('/api/queues/%s/%s', rawurlencode($vhost), rawurlencode($name))) + ->then(bind(array($this, 'handleEntityData'), $queue ?: new Queue())); } public function refreshQueue(Queue $queue) @@ -212,8 +205,8 @@ public function addQueue(Queue $queue) throw new InvalidArgumentException('Queue requires a name'); } - return $this->executeRequest('PUT', sprintf('/api/queues/%s/%s', urlencode($queue->vhost), urlencode($queue->name)), $queue->toJson()) - ->then(Curry::bind(array($this, 'getQueue'), $queue->vhost, $queue->name, $queue)); + return $this->executeRequest('PUT', sprintf('/api/queues/%s/%s', rawurlencode($queue->vhost), rawurlencode($queue->name)), $queue->toJson()) + ->then(bind(array($this, 'getQueue'), $queue->vhost, $queue->name, $queue)); } public function deleteQueue($vhost, $name) @@ -226,7 +219,7 @@ public function deleteQueue($vhost, $name) throw new InvalidArgumentException('Queue requires a name'); } - return $this->executeRequest('DELETE', sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name))); + return $this->executeRequest('DELETE', sprintf('/api/queues/%s/%s', rawurlencode($vhost), rawurlencode($name))); } public function purgeQueue($vhost, $name) @@ -239,36 +232,36 @@ public function purgeQueue($vhost, $name) throw new InvalidArgumentException('Queue requires a name'); } - return $this->executeRequest('DELETE', sprintf('/api/queues/%s/%s/contents', urlencode($vhost), urlencode($name))) - ->then(Curry::bind(array($this, 'getQueue'), $vhost, $name, null)); + return $this->executeRequest('DELETE', sprintf('/api/queues/%s/%s/contents', rawurlencode($vhost), rawurlencode($name))) + ->then(bind(array($this, 'getQueue'), $vhost, $name, null)); } public function listBindingsByQueue(Queue $queue) { - $uri = sprintf('/api/queues/%s/%s/bindings', urlencode($queue->vhost), urlencode($queue->name)); + $uri = sprintf('/api/queues/%s/%s/bindings', rawurlencode($queue->vhost), rawurlencode($queue->name)); return $this->executeRequest('GET', $uri) - ->then(Curry::bind(array($this, 'handleCollectionData'), 'Binding')); + ->then(bind(array($this, 'handleCollectionData'), 'Binding')); } public function listBindingsByExchangeAndQueue($vhost, $exchange, $queue) { - $uri = sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($vhost), urlencode($exchange), urlencode($queue)); + $uri = sprintf('/api/bindings/%s/e/%s/q/%s', rawurlencode($vhost), rawurlencode($exchange), rawurlencode($queue)); return $this->executeRequest('GET', $uri) - ->then(Curry::bind(array($this, 'handleCollectionData'), 'Binding')); + ->then(bind(array($this, 'handleCollectionData'), 'Binding')); } public function addBinding(Binding $binding) { - $uri = sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($binding->vhost), urlencode($binding->source), urlencode($binding->destination)); + $uri = sprintf('/api/bindings/%s/e/%s/q/%s', rawurlencode($binding->vhost), rawurlencode($binding->source), rawurlencode($binding->destination)); return $this->executeRequest('POST', $uri, $binding->toJson()); } public function deleteBinding(Binding $binding) { - $uri = sprintf('/api/bindings/%s/e/%s/q/%s/%s', urlencode($binding->vhost), urlencode($binding->source), urlencode($binding->destination), urlencode($binding->properties_key)); + $uri = sprintf('/api/bindings/%s/e/%s/q/%s/%s', rawurlencode($binding->vhost), rawurlencode($binding->source), rawurlencode($binding->destination), rawurlencode($binding->properties_key)); return $this->executeRequest('DELETE', $uri); } @@ -276,33 +269,33 @@ public function deleteBinding(Binding $binding) public function listBindings($vhost = null) { if (null !== $vhost) { - $uri = sprintf('/api/bindings/%s', urlencode($vhost)); + $uri = sprintf('/api/bindings/%s', rawurlencode($vhost)); } else { $uri = '/api/bindings'; } return $this->executeRequest('GET', $uri) - ->then(Curry::bind(array($this, 'handleCollectionData'), 'Binding')); + ->then(bind(array($this, 'handleCollectionData'), 'Binding')); } public function alivenessTest($vhost) { $that = $this; - return $this->executeRequest('GET', sprintf('/api/aliveness-test/%s', urlencode($vhost))) - ->then(function($data) use ($that, $vhost) { - $data = json_decode($data, true); - - if (!isset($data['status']) || $data['status'] !== 'ok') { + return $this->executeRequest('GET', sprintf('/api/aliveness-test/%s', rawurlencode($vhost))) + ->then(function ($data) use ($that, $vhost) { + $data = json_decode($data, true); + + if (!isset($data['status']) || $data['status'] !== 'ok') { + return false; + } + + return $that->deleteQueue($vhost, 'aliveness-test') + ->then(function () { + return true; + }, function () { return false; - } - - return $that->deleteQueue($vhost, 'aliveness-test') - ->then(function() { - return true; - }, function() { - return false; - }); - }); + }); + }); } public function handleEntityData(EntityInterface $entity, $rawData) diff --git a/src/RabbitMQ/Management/Entity/Channel.php b/src/RabbitMQ/Management/Entity/Channel.php index c23a3e5..610737f 100644 --- a/src/RabbitMQ/Management/Entity/Channel.php +++ b/src/RabbitMQ/Management/Entity/Channel.php @@ -4,28 +4,34 @@ class Channel extends AbstractEntity { + public $acks_uncommitted; + public $client_flow_blocked; + public $confirm; public $connection_details; + public $consumer_count; public $consumer_details = array(); + public $deliveries = array(); + public $global_prefetch_count; public $idle_since; - public $transactional; - public $confirm; - public $consumer_count; + public $message_stats; public $messages_unacknowledged; - public $messages_unconfirmed; public $messages_uncommitted; - public $message_stats; - public $acks_uncommitted; - public $publishes; - public $prefetch_count; - public $client_flow_blocked; - public $node; + public $messages_unconfirmed; public $name; + public $node; public $number; + public $prefetch_count; + public $publishes; + public $state; + public $transactional; public $user; public $vhost; - public $deliveries = array(); - public $global_prefetch_count; - public $state; + public $garbage_collection; + public $pending_raft_commands; + public $reductions; + public $reductions_details; + public $user_who_performed_action; + protected function getJsonParameters() { diff --git a/src/RabbitMQ/Management/Entity/Connection.php b/src/RabbitMQ/Management/Entity/Connection.php index 95e7ef9..b049dd7 100644 --- a/src/RabbitMQ/Management/Entity/Connection.php +++ b/src/RabbitMQ/Management/Entity/Connection.php @@ -4,43 +4,47 @@ class Connection extends AbstractEntity { + public $address; + public $auth_mechanism; + public $channel_max; + public $channels; + public $client_properties; + public $connected_at; + public $frame_max; public $host; + public $last_blocked_age; + public $last_blocked_by; + public $name; + public $node; + public $peer_address; + public $peer_cert_issuer; + public $peer_cert_subject; + public $peer_cert_validity; public $peer_host; + public $peer_port; + public $port; + public $protocol; + public $recv_cnt; public $recv_oct; public $recv_oct_details; - public $recv_cnt; + public $send_cnt; public $send_oct; public $send_oct_details; - public $send_cnt; public $send_pend; - public $state; - public $last_blocked_by; - public $last_blocked_age; - public $channels; - public $type; - public $node; - public $name; - public $address; - public $port; - public $peer_address; - public $peer_port; public $ssl; - public $peer_cert_subject; - public $peer_cert_issuer; - public $peer_cert_validity; - public $auth_mechanism; - public $ssl_protocol; - public $ssl_key_exchange; public $ssl_cipher; public $ssl_hash; - public $protocol; + public $ssl_key_exchange; + public $ssl_protocol; + public $state; + public $timeout; + public $type; public $user; public $vhost; - public $timeout; - public $frame_max; - public $client_properties; - public $channel_max; - public $connected_at; + public $garbage_collection; + public $reductions; + public $reductions_details; + public $user_who_performed_action; protected function getJsonParameters() { diff --git a/src/RabbitMQ/Management/Entity/Exchange.php b/src/RabbitMQ/Management/Entity/Exchange.php index 8cfd418..74607c2 100644 --- a/src/RabbitMQ/Management/Entity/Exchange.php +++ b/src/RabbitMQ/Management/Entity/Exchange.php @@ -17,6 +17,7 @@ class Exchange extends AbstractEntity public $arguments = array(); public $message_stats = array(); public $policy; + public $user_who_performed_action; protected function getJsonParameters() { diff --git a/src/RabbitMQ/Management/Entity/Queue.php b/src/RabbitMQ/Management/Entity/Queue.php index 3cd3a2e..985db67 100644 --- a/src/RabbitMQ/Management/Entity/Queue.php +++ b/src/RabbitMQ/Management/Entity/Queue.php @@ -4,55 +4,61 @@ class Queue extends AbstractEntity { - public $arguments = array(); - public $auto_delete = false; - public $durable = false; - public $name; - public $vhost; - public $status; - public $node; - public $policy; public $active_consumers; - public $messages_unacknowledged_details; - public $messages_ready_details; - public $messages_details; + public $arguments = array(); + public $auto_delete = false; public $backing_queue_status; - public $slave_nodes; - public $consumers; public $consumer_details = array(); public $consumer_utilisation; - public $state; - public $messages; - public $messages_ready; - public $message_stats; - public $messages_unacknowledged; - public $messages_paged_out; + public $consumers; + public $deliveries = array(); + public $disk_reads; + public $disk_writes; + public $down_slave_nodes; + public $durable = false; + public $effective_policy_definition; + public $exclusive; public $exclusive_consumer_tag; - public $memory; + public $garbage_collection; + public $head_message_timestamp; public $idle_since; public $incoming = array(); - public $deliveries = array(); - public $down_slave_nodes; - public $messages_ram; - public $messages_ready_ram; - public $messages_unacknowledged_ram; - public $messages_persistent; + public $memory; public $message_bytes; + public $message_bytes_paged_out; + public $message_bytes_persistent; + public $message_bytes_ram; public $message_bytes_ready; public $message_bytes_unacknowledged; - public $message_bytes_ram; - public $message_bytes_persistent; - public $message_bytes_paged_out; + public $message_stats; + public $messages; + public $messages_details; + public $messages_paged_out; + public $messages_persistent; + public $messages_ram; + public $messages_ready; + public $messages_ready_details; + public $messages_ready_ram; + public $messages_unacknowledged; + public $messages_unacknowledged_details; + public $messages_unacknowledged_ram; + public $name; + public $node; + public $operator_policy; + public $policy; + public $recoverable_slaves = array(); public $reductions; public $reductions_details; + public $single_active_consumer_tag; + public $slave_nodes; + public $state; + public $synchronised_slave_nodes = array(); - public $recoverable_slaves = array(); - public $garbage_collection; - public $head_message_timestamp; - public $disk_reads; - public $disk_writes; - public $exclusive; + public $type; + public $vhost; + + public function getBindings() { diff --git a/src/RabbitMQ/Management/HttpClient.php b/src/RabbitMQ/Management/HttpClient.php index 282ba8e..cd1db81 100644 --- a/src/RabbitMQ/Management/HttpClient.php +++ b/src/RabbitMQ/Management/HttpClient.php @@ -2,8 +2,8 @@ namespace RabbitMQ\Management; -use Guzzle\Common\Collection; -use Guzzle\Service\Client; + +use GuzzleHttp\Client; use RabbitMQ\Management\Exception\RuntimeException; class HttpClient extends Client @@ -36,18 +36,50 @@ public function getHydrator() public static function factory($options = array()) { $default = array( - 'base_url' => '{scheme}://{username}:{password}@{host}:{port}', - 'scheme' => 'http', + 'base_uri' => '{scheme}://{username}:{password}@{host}:{port}/', + 'scheme' => 'http', 'username' => 'guest', 'password' => 'guest', - 'port' => '15672', + 'port' => '15672', ); - $required = array('username', 'password', 'host', 'base_url'); - $config = Collection::fromConfig($options, $default, $required); + /* accommodate legacy clients of this library using base_url where Guzzle now wants base_uri */ + if(array_key_exists('base_url',$options) and !array_key_exists('base_uri',$options)) { + $options['base_uri']=$options['base_url']; + unset($options['base_url']); + } + + $required = array('username', 'password', 'host', 'base_uri'); + $config = array_merge($default,$options); + if ($missing = array_diff($required, array_keys($config))) { + throw new RuntimeException('Config is missing the following keys: ' . implode(', ', $missing)); + } + + foreach ($config as $key => $value) { + if ($key === 'base_uri') { + continue; + } + $config['base_uri'] = str_replace('{' . $key . '}', $value, $config['base_uri']); + } + + + $client = new self($config); - $client = new self($config->get('base_url'), $config); return $client; } + + /* This is excerpted from the old Guzzle\Common\Collection code (now no longer present in Guzzle) to accommodate + the usage of it above + */ + private static function fromConfig(array $config = array(), array $defaults = array(), array $required = array()): array + { + $data = $config + $defaults; + + if ($missing = array_diff($required, array_keys($data))) { + throw new RuntimeException('Config is missing the following keys: ' . implode(', ', $missing)); + } + + return $data; + } } diff --git a/src/RabbitMQ/Management/Hydrator.php b/src/RabbitMQ/Management/Hydrator.php index 4c4752b..48c7ffc 100644 --- a/src/RabbitMQ/Management/Hydrator.php +++ b/src/RabbitMQ/Management/Hydrator.php @@ -6,6 +6,8 @@ class Hydrator { + private static $audit=false; + private static $lastAuditStatus=false; private static $instance; public static function getInstance() @@ -17,22 +19,62 @@ public static function getInstance() return self::$instance; } + /* notice: not thread safe! */ + public static function requestOneShotAudit($delay) { + self::$audit=true; + self::$lastAuditStatus=false; + sleep($delay); + } + + public static function getLastAuditStatus() { + return self::$lastAuditStatus; + } + public function hydrate(EntityInterface $entity, $data) { + if (self::$audit) { + self::$lastAuditStatus=true; + $shortClassName = preg_replace("/.+\\\\/", "", get_class($entity)); + $expectedProps = get_class_vars(get_class($entity)); + } + foreach ($data as $key => $value) { + /* if (!property_exists($entity, $key)) { throw new \InvalidArgumentException(sprintf('Entity %s does not have property %s', get_class($entity), $key)); } + */ + if (self::$audit) { + if (!property_exists($entity, $key)) { + printf("class %s missing public \$%s;\n", $shortClassName, $key); + self::$lastAuditStatus=false; + } else { + $expectedProps[$key] = true; + } + } + $entity->{$key} = $value; } + if (self::$audit) { + foreach ($expectedProps as $key => $value) { + if ($value === true) { + continue; + } + printf("class %s didn't use %s\n",$shortClassName,$key); + /* warn but don't fail on audit for use against old servers */ + /* self::$lastAuditStatus=false; */ + } + self::$audit=false; + } + return $entity; } public static function camelize($attribute) { - return implode('', array_map(function($part) { - return ucfirst($part); - }, explode('_', $attribute))); + return implode('', array_map(function ($part) { + return ucfirst($part); + }, explode('_', $attribute))); } } diff --git a/tests/src/RabbitMQ/Tests/Management/APIClientTest.php b/tests/src/RabbitMQ/Tests/Management/APIClientTest.php index 41ea086..a3c357c 100644 --- a/tests/src/RabbitMQ/Tests/Management/APIClientTest.php +++ b/tests/src/RabbitMQ/Tests/Management/APIClientTest.php @@ -1,18 +1,25 @@ -client = HttpClient::factory(array('host' => 'localhost')); + $this->client = HttpClient::factory(array('host' => 'localhost')); $this->object = new APIClient($this->client); - $this->conn = new \PhpAmqpLib\Connection\AMQPConnection('localhost', 5672, 'guest', 'guest', '/'); + /* might be left over from previous failed test */ + $this->cleanupTestObjects(); + } + + public function tearDown(): void + { + $this->cleanupTestObjects(); + + try { + if ($this->channel != null) { + $this->channel->close(); + } + if ($this->conn != null) { + $this->conn->close(); + } + } catch (Exception $e) { + /* don't care */ + } + } + + private function needConnection(): void + { + $this->conn = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest', '/'); $this->channel = $this->conn->channel(); + + /* attempting to see own connection just made, management api may delay showing it, so wait before testing */ + sleep(5); + } - public function tearDown() + private function cleanupTestObjects(): void { + /* do not combine into one try/catch block because we want both to be tried even if first fails */ try { $this->object->deleteQueue('/', self::QUEUE_TEST_NAME); - } catch (\Exception $e) { - + } catch (EntityNotFoundException $e) { + /* might not exist, don't care if fails */ } try { $this->object->deleteExchange('/', self::EXCHANGE_TEST_NAME); - } catch (\Exception $e) { - + } catch (EntityNotFoundException $e) { + /* might not exist, don't care if fails */ } - - $this->channel->close(); - $this->conn->close(); } - public function testListConnections() + public function testListConnections(): void { + $this->needConnection(); $connections = $this->object->listConnections(); $this->assertNonEmptyArrayCollection($connections); @@ -72,30 +104,52 @@ public function testListConnections() } } - public function testGetConnection() + public function testGetConnection(): void { + $this->needConnection(); $connections = $this->object->listConnections()->toArray(); $expectedConnection = array_pop($connections); + Hydrator::requestOneShotAudit(6); $connection = $this->object->getConnection($expectedConnection->name); $this->assertInstanceOf('RabbitMQ\Management\Entity\Connection', $connection); + $this->assertTrue(Hydrator::getLastAuditStatus(),"audit failed"); - $this->assertEquals($expectedConnection, $connection); + $this->assertEquals($expectedConnection->name, $connection->name); } - public function testDeleteConnection() + public function testDeleteConnection(): void { - $this->markTestSkipped('Not working ?!'); + $this->needConnection(); + + $success = false; $connections = $this->object->listConnections()->toArray(); - $quantity = count($connections); $expectedConnection = array_pop($connections); $this->object->deleteConnection($expectedConnection->name); - $this->assertEquals($quantity - 1, count($this->object->listConnections())); + /* make sure we don't try to tear down */ + $this->channel = null; + $this->conn = null; + + /* wait for info to update on server */ + sleep(10); + /* its either going to return the connection in closed state or failed to find it */ + try { + $expectedConnection = $this->object->getConnection($expectedConnection->name); + if ($expectedConnection->state == "closed") { + $success = true; + } + } catch (EntityNotFoundException $e) { + $this->assertContains("Failed to find connection", $e->getMessage()); + $success = true; + } + $this->assertEquals(true, $success); + } - public function testListChannels() + public function testListChannels(): void { + $this->needConnection(); $channels = $this->object->listChannels(); $this->assertNonEmptyArrayCollection($channels); @@ -105,19 +159,21 @@ public function testListChannels() } } - public function testGetChannel() + public function testGetChannel(): void { + $this->needConnection(); $channels = $this->object->listChannels()->toArray(); $expectedChannel = array_pop($channels); + Hydrator::requestOneShotAudit(6); $channel = $this->object->getChannel($expectedChannel->name); $this->assertInstanceOf('RabbitMQ\Management\Entity\Channel', $channel); + $this->assertTrue(Hydrator::getLastAuditStatus(),"audit failed"); - $this->markTestSkipped('Not working ?!'); - $this->assertEquals($expectedChannel, $channel); + $this->assertEquals($expectedChannel->name, $channel->name); } - public function testListExchanges() + public function testListExchanges(): void { $exchanges = $this->object->listExchanges(); @@ -128,7 +184,7 @@ public function testListExchanges() } } - public function testListExchangesWithVhost() + public function testListExchangesWithVhost(): void { $exchanges = $this->object->listExchanges(self::VIRTUAL_HOST); @@ -139,59 +195,55 @@ public function testListExchangesWithVhost() } } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testListExchangeFailed() + public function testListExchangeFailed(): void { + $this->expectException(ClientException::class); $this->object->listExchanges(self::NONEXISTENT_VIRTUAL_HOST); } - public function testGetExchange() + public function testGetExchange(): void { $exchanges = $this->object->listExchanges()->toArray(); $expectedExchange = array_pop($exchanges); + Hydrator::requestOneShotAudit(6); $exchange = $this->object->getExchange($expectedExchange->vhost, $expectedExchange->name); $this->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); + $this->assertTrue(Hydrator::getLastAuditStatus(),"audit failed"); - $this->assertEquals($expectedExchange, $exchange); + $this->assertEquals($expectedExchange->name, $exchange->name); } - /** - * @expectedException RabbitMQ\Management\Exception\EntityNotFoundException - */ - public function testGetExchangeFailed() + + public function testGetExchangeFailed(): void { + $this->expectException(EntityNotFoundException::class); $this->object->getExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME); } - public function testDeleteExchange() + public function testDeleteExchange(): void { + $this->expectException(EntityNotFoundException::class); $exchange = new Exchange(); $exchange->name = self::EXCHANGE_TEST_NAME; $exchange->vhost = '/'; + $exchange->type = 'fanout'; $this->object->addExchange($exchange); $this->object->deleteExchange('/', self::EXCHANGE_TEST_NAME); - try { - $this->object->getExchange($exchange->vhost, $exchange->name); - $this->fail('Should raise an exception'); - } catch (EntityNotFoundException $e) { + /* expected to raise an exception */ + $this->object->getExchange($exchange->vhost, $exchange->name); - } } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testDeleteExchangeFailed() + public function testDeleteExchangeFailed(): void { + $this->expectException(EntityNotFoundException::class); $this->object->deleteExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME); } - public function testAddExchange() + public function testAddExchange(): void { $exchange = new Exchange(); @@ -204,16 +256,15 @@ public function testAddExchange() $foundExchange = $this->object->getExchange($exchange->vhost, $exchange->name); - $this->assertEquals($exchange, $foundExchange); + $this->assertEquals($exchange->name, $foundExchange->name); $this->object->deleteExchange('/', self::EXCHANGE_TEST_NAME); } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testAddExchangeFailed() + + public function testAddExchangeFailed(): void { + $this->expectException(ClientException::class); $exchange = new Exchange(); $exchange->vhost = self::NONEXISTENT_VIRTUAL_HOST; @@ -224,11 +275,13 @@ public function testAddExchangeFailed() $this->object->addExchange($exchange); } - public function testAddExchangeThatAlreadyExists() + public function testAddExchangeThatAlreadyExists(): void { + $this->expectNotToPerformAssertions(); $exchange = new Exchange(); $exchange->vhost = '/'; $exchange->name = self::EXCHANGE_TEST_NAME; + $exchange->type = 'fanout'; $this->object->addExchange($exchange); @@ -240,11 +293,12 @@ public function testAddExchangeThatAlreadyExists() } catch (PreconditionFailedException $e) { } + $this->object->deleteExchange($exchange->vhost, $exchange->name); } - public function testListQueues() + public function testListQueues(): void { - $queue = $this->createQueue(); + $this->createQueue(); $queues = $this->object->listQueues(); @@ -255,20 +309,19 @@ public function testListQueues() } } - private function createQueue() + private function createQueue(): Queue { $queue = new Queue(); $queue->vhost = '/'; $queue->name = self::QUEUE_TEST_NAME; - $this->object->addQueue($queue); + return $this->object->addQueue($queue); - return $queue; } - public function testListQueuesWithVhost() + public function testListQueuesWithVhost(): void { - $queue = $this->createQueue(); + $this->createQueue(); $queues = $this->object->listQueues(self::VIRTUAL_HOST); @@ -279,38 +332,32 @@ public function testListQueuesWithVhost() } } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testListQueueFailed() + public function testListQueueFailed(): void { + $this->expectException(EntityNotFoundException::class); $this->object->listQueues(self::NONEXISTENT_VIRTUAL_HOST); } - public function testGetQueue() + public function testGetQueue(): void { - $queue = $this->createQueue(); - - $queues = $this->object->listQueues()->toArray(); - $expectedQueue = array_pop($queues); - - $this->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $expectedQueue); + $expectedQueue=$this->createQueue(); + Hydrator::requestOneShotAudit(6); $queue = $this->object->getQueue($expectedQueue->vhost, $expectedQueue->name); $this->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $queue); + $this->assertTrue(Hydrator::getLastAuditStatus(),"audit failed"); - $this->assertEquals($expectedQueue, $queue); + $this->assertEquals($expectedQueue->vhost, $queue->vhost); + $this->assertEquals($expectedQueue->name, $queue->name); } - /** - * @expectedException RabbitMQ\Management\Exception\EntityNotFoundException - */ - public function testGetQueueFailed() + public function testGetQueueFailed(): void { + $this->expectException(EntityNotFoundException::class); $this->object->getQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME); } - public function testAddQueue() + public function testAddQueue(): void { $queue = new Queue(); $queue->vhost = '/'; @@ -320,16 +367,14 @@ public function testAddQueue() $foundQueue = $this->object->getQueue($queue->vhost, $queue->name); - $this->assertEquals($queue, $foundQueue); + $this->assertEquals($queue->name, $foundQueue->name); $this->object->deleteQueue('/', self::QUEUE_TEST_NAME); } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testAddQueueFailed() + public function testAddQueueFailed(): void { + $this->expectException(EntityNotFoundException::class); $queue = new Queue(); $queue->vhost = self::NONEXISTENT_VIRTUAL_HOST; $queue->name = self::QUEUE_TEST_NAME; @@ -337,30 +382,28 @@ public function testAddQueueFailed() $this->object->addQueue($queue); } - public function testDeleteQueue() + public function testDeleteQueue(): void { + $this->expectException(EntityNotFoundException::class); + $queue = $this->createQueue(); $this->object->deleteQueue('/', self::QUEUE_TEST_NAME); - try { - $this->object->getQueue($queue->vhost, $queue->name); - $this->fail('Should raise an exception'); - } catch (EntityNotFoundException $e) { - - } + /* expected to throw exception */ + $this->object->getQueue($queue->vhost, $queue->name); } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testDeleteQueueFailed() + public function testDeleteQueueFailed(): void { + $this->expectException(EntityNotFoundException::class); $this->object->deleteQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME); } - public function testAddQueueThatAlreadyExists() + public function testAddQueueThatAlreadyExists(): void { + $this->expectNotToPerformAssertions(); + $queue = $this->createQueue(); $queue->durable = true; @@ -373,16 +416,17 @@ public function testAddQueueThatAlreadyExists() } } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testPurgeQueueFailed() + public function testPurgeQueueFailed(): void { + $this->expectException(EntityNotFoundException::class); $this->object->purgeQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME); } - public function testListBindingsByQueue() + public function testListBindingsByQueue(): void { + $this->createQueue(); + $this->createBinding(); + foreach ($this->object->listQueues() as $queue) { foreach ($this->object->listBindingsByQueue($queue) as $binding) { /* @var $binding Binding */ @@ -392,7 +436,7 @@ public function testListBindingsByQueue() } } - public function testListBindingsOnUnknownHostOrQueue() + public function testListBindingsOnUnknownHostOrQueue(): void { $queue = new Queue(); $queue->name = 'nonexistent queue'; @@ -401,8 +445,11 @@ public function testListBindingsOnUnknownHostOrQueue() $this->assertCount(0, $this->object->listBindingsByQueue($queue)); } - public function testListBindingsByExchangeAndQueue() + public function testListBindingsByExchangeAndQueue(): void { + $this->createQueue(); + $this->createBinding(); + foreach ($this->object->listQueues() as $queue) { foreach ($this->object->listExchanges() as $exchange) { if ($exchange->name == '') { @@ -418,14 +465,16 @@ public function testListBindingsByExchangeAndQueue() } } - public function testListBindingsByExchangeAndQueueOnUnknownVhostOrQueue() + public function testListBindingsByExchangeAndQueueOnUnknownVhostOrQueue(): void { $this->assertCount(0, $this->object->listBindingsByExchangeAndQueue(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME)); } - public function testAddBinding() + public function testAddBinding(): void { - $queue = $this->createQueue(); + $this->expectNotToPerformAssertions(); + + $this->createQueue(); $exchange = new Exchange(); $exchange->name = self::EXCHANGE_TEST_NAME; @@ -458,11 +507,9 @@ public function testAddBinding() $this->object->deleteBinding('/', self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME, $found); } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testAddBindingFailed() + public function testAddBindingFailed(): void { + $this->expectException(EntityNotFoundException::class); $binding = new Binding(); $binding->vhost = '/'; $binding->source = self::EXCHANGE_TEST_NAME; @@ -471,8 +518,10 @@ public function testAddBindingFailed() $this->object->addBinding($binding); } - public function testDeleteBinding() + public function testDeleteBinding(): void { + $this->expectNotToPerformAssertions(); + $this->createBinding(); $found = false; @@ -498,9 +547,9 @@ public function testDeleteBinding() } } - private function createBinding() + private function createBinding(): void { - $queue = $this->createQueue(); + $this->createQueue(); $exchange = new Exchange(); $exchange->name = self::EXCHANGE_TEST_NAME; @@ -517,18 +566,17 @@ private function createBinding() $this->object->addBinding($binding); } - /** - * @expectedException RabbitMQ\Management\Exception\RuntimeException - */ - public function testDeleteNonexistentBinding() + + public function testDeleteNonexistentBinding(): void { + $this->expectException(EntityNotFoundException::class); $binding = new Binding(); $binding->properties_key = 'bingo'; $this->object->deleteBinding('/', self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME, $binding); } - public function testListBindings() + public function testListBindings(): void { $this->createBinding(); @@ -541,7 +589,7 @@ public function testListBindings() } } - public function testListBindingsWithVhost() + public function testListBindingsWithVhost(): void { $this->createBinding(); @@ -554,17 +602,17 @@ public function testListBindingsWithVhost() } } - public function testAlivenessTest() + public function testAlivenessTest(): void { $this->assertTrue($this->object->alivenessTest(self::VIRTUAL_HOST)); } - public function testAlivenessTestFailed() + public function testAlivenessTestFailed(): void { $this->assertFalse($this->object->alivenessTest(self::NONEXISTENT_VIRTUAL_HOST)); } - public function testPurgeQueue() + public function testPurgeQueue(): void { $queue = $this->createQueue(); @@ -584,29 +632,32 @@ public function testPurgeQueue() $message = json_encode(array( 'properties' => array(), - 'routing_key' => self::QUEUE_TEST_NAME, - 'payload' => 'body', + 'routing_key' => self::QUEUE_TEST_NAME, + 'payload' => 'body', 'payload_encoding' => 'string', - )); + )); + + $message = str_replace('[]', '{}', $message); $n = 12; while ($n > 0) { - $this->client->post('/api/exchanges/' . urlencode('/') . '/' . self::EXCHANGE_TEST_NAME . '/publish', array('content-type' => 'application/json'), $message)->send(); + $this->client->post('/api/exchanges/' . urlencode('/') . '/' . self::EXCHANGE_TEST_NAME . '/publish', + ['headers' => ['content-type' => 'application/json'], 'body' => $message]); $n--; } - usleep(2000000); + sleep(10); $this->object->refreshQueue($queue); $this->assertEquals(12, $queue->messages_ready); $this->object->purgeQueue('/', self::QUEUE_TEST_NAME); - usleep(4000000); + sleep(10); $this->object->refreshQueue($queue); $this->assertEquals(0, $queue->messages_ready); } - public function assertNonEmptyArrayCollection($collection) + public function assertNonEmptyArrayCollection($collection): void { $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $collection); $this->assertGreaterThan(0, count($collection), 'Collection is not empty'); diff --git a/tests/src/RabbitMQ/Tests/Management/AsyncAPIClientTest.php b/tests/src/RabbitMQ/Tests/Management/AsyncAPIClientTest.php index 4ba961a..17407d3 100644 --- a/tests/src/RabbitMQ/Tests/Management/AsyncAPIClientTest.php +++ b/tests/src/RabbitMQ/Tests/Management/AsyncAPIClientTest.php @@ -1,17 +1,26 @@ loop = \React\EventLoop\Factory::create(); - $this->object = AsyncAPIClient::factory($this->loop, array('host' => '127.0.0.1')); + $this->loop = Factory::create(); + $this->object = AsyncAPIClient::factory($this->loop, array('host' => '127.0.0.1')); - $this->syncClientClient = HttpClient::factory(array('host' => 'localhost')); + $this->syncClientClient = HttpClient::factory(array('host' => 'localhost')); $this->syncClient = new APIClient($this->syncClientClient); - $this->conn = new \PhpAmqpLib\Connection\AMQPConnection('localhost', 5672, 'guest', 'guest', '/'); - $this->channel = $this->conn->channel(); + /* might be left over from previous failed test */ + $this->cleanupTestObjects(); } - public function tearDown() + + public function tearDown(): void { + $this->cleanupTestObjects(); + try { - $this->syncClient->deleteQueue('/', self::QUEUE_TEST_NAME); - } catch (\Exception $e) { + if ($this->channel != null) { + $this->channel->close(); + } + if ($this->conn != null) { + $this->conn->close(); + } + } catch (Exception $e) { + /* don't care */ + } + } + private function cleanupTestObjects(): void + { + /* do not combine into one try/catch block because we want both to be tried even if first fails */ + try { + $this->syncClient->deleteQueue('/', self::QUEUE_TEST_NAME); + } catch (EntityNotFoundException $e) { + /* might not exist, don't care if fails */ } try { $this->syncClient->deleteExchange('/', self::EXCHANGE_TEST_NAME); - } catch (\Exception $e) { - + } catch (EntityNotFoundException $e) { + /* might not exist, don't care if fails */ } + } + + private function needConnection(): void + { + $this->conn = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest', '/'); + $this->channel = $this->conn->channel(); + + /* attempting to see own connection just made, management api may delay showing it, so wait before testing */ + sleep(5); - $this->channel->close(); - $this->conn->close(); } public function testListConnections() { - $loop = $this->loop; - $PHPUnit = $this; + $this->needConnection(); - $this->object->listConnections() - ->then(function($connections) use ($PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($connections); - foreach ($connections as $connection) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Connection', $connection); - } - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $connections = $this->waitForPromiseToFulfill($this->object->listConnections()); + + $this->assertNonEmptyArrayCollection($connections); + foreach ($connections as $connection) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Connection', $connection); + } - $loop->run(); } + public function testGetConnection() { - $loop = $this->loop; - $PHPUnit = $this; + $this->needConnection(); $connections = $this->syncClient->listConnections()->toArray(); $expectedConnection = array_pop($connections); - $this->object->getConnection($expectedConnection->name) - ->then(function($connection) use ($expectedConnection, $PHPUnit, $loop) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Connection', $connection); - $PHPUnit->assertEquals($expectedConnection, $connection); - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $connection = $this->waitForPromiseToFulfill($this->object->getConnection($expectedConnection->name)); - $loop->run(); + $this->assertInstanceOf('RabbitMQ\Management\Entity\Connection', $connection); + $this->assertEquals($expectedConnection->name, $connection->name); } public function testDeleteConnection() { - $this->markTestSkipped('Not working ?!'); + $this->needConnection(); + + $connections = $this->syncClient->listConnections()->toArray(); + $expectedConnection = array_pop($connections); + + $this->waitForPromiseToFulfill($this->object->deleteConnection($expectedConnection->name)); + + /* make sure we don't try to tear down */ + $this->channel = null; + $this->conn = null; + + /* wait for info to update on server */ + sleep(10); + + /* its either going to return the connection in closed state */ + try { + $expectedConnection = $this->syncClient->getConnection($expectedConnection->name); + if ($expectedConnection->state == "closed") { + $success = true; + } + } catch (EntityNotFoundException $e) { + $this->assertContains("Failed to find connection", $e->getMessage()); + $success = true; + } + $this->assertEquals(true, $success); + } public function testListChannels() { - $loop = $this->loop; - $PHPUnit = $this; + $this->needConnection(); - $this->object->listChannels() - ->then(function($channels) use ($PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($channels); - foreach ($channels as $channel) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Channel', $channel); - } - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $channels = $this->waitForPromiseToFulfill($this->object->listChannels()); - $loop->run(); + $this->assertNonEmptyArrayCollection($channels); + foreach ($channels as $channel) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Channel', $channel); + } } public function testGetChannel() { - $loop = $this->loop; - $PHPUnit = $this; + $this->needConnection(); $channels = $this->syncClient->listChannels()->toArray(); + $this->assertNotEmpty($channels); $expectedChannel = array_pop($channels); - $this->object->getConnection($expectedChannel->name) - ->then(function($channel) use ($expectedChannel, $PHPUnit, $loop) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Channel', $channel); - $PHPUnit->assertEquals($expectedChannel, $channel); - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $channel = $this->waitForPromiseToFulfill($this->object->getChannel($expectedChannel->name)); + $this->assertInstanceOf('RabbitMQ\Management\Entity\Channel', $channel); + $this->assertEquals($expectedChannel->name, $channel->name); - $loop->run(); } public function testListExchanges() { - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->listExchanges() - ->then(function($exchanges) use ($PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($exchanges); - foreach ($exchanges as $exchange) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); - } - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $exchanges = $this->waitForPromiseToFulfill($this->object->listExchanges()); + $this->assertNonEmptyArrayCollection($exchanges); + foreach ($exchanges as $exchange) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); + } - $loop->run(); } public function testListExchangesWithVhost() { - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->listExchanges(self::VIRTUAL_HOST) - ->then(function($exchanges) use ($PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($exchanges); - foreach ($exchanges as $exchange) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); - $PHPUnit->assertEquals($PHPUnit::VIRTUAL_HOST, $exchange->vhost); - } - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); - - $loop->run(); + $exchanges = $this->waitForPromiseToFulfill($this->object->listExchanges(self::VIRTUAL_HOST)); + $this->assertNonEmptyArrayCollection($exchanges); + foreach ($exchanges as $exchange) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); + $this->assertEquals(self::VIRTUAL_HOST, $exchange->vhost); + } } public function testListExchangeFailed() { - $loop = $this->loop; - $PHPUnit = $this; - - $success = false; - $this->object->listExchanges(self::NONEXISTENT_VIRTUAL_HOST) - ->then(function($exchanges) use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->listExchanges(self::NONEXISTENT_VIRTUAL_HOST)); } public function testGetExchange() { - $loop = $this->loop; - $PHPUnit = $this; - $exchanges = $this->syncClient->listExchanges()->toArray(); $expectedExchange = array_pop($exchanges); - $success = false; - $this->object->getExchange($expectedExchange->vhost, $expectedExchange->name) - ->then(function($exchange) use ($expectedExchange, &$success, $loop, $PHPUnit) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); - $PHPUnit->assertEquals($expectedExchange, $exchange); - $success = true; - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }); - - $loop->run(); - $this->assertTrue($success); + $exchange = $this->waitForPromiseToFulfill($this->object->getExchange($expectedExchange->vhost, $expectedExchange->name)); + $this->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); + $this->assertEquals($expectedExchange->name, $exchange->name); } public function testGetExchangeFailed() { - $loop = $this->loop; - $PHPUnit = $this; - - $success = false; - $this->object->getExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME) - ->then(function($exchanges) use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->getExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME)); } public function testDeleteExchange() @@ -255,40 +231,13 @@ public function testDeleteExchange() $this->syncClient->addExchange($exchange); $this->syncClient->deleteExchange('/', self::EXCHANGE_TEST_NAME); - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - $this->object->getExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME) - ->then(function($exchanges) use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->getExchange(self::VIRTUAL_HOST, self::EXCHANGE_TEST_NAME)); } public function testDeleteExchangeFailed() { - $loop = $this->loop; - $PHPUnit = $this; - - $success = false; - $this->object->deleteExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME) - ->then(function($exchanges) use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); - - $this->object->deleteExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME); + $this->assertPromiseRejects($this->object->deleteExchange(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME)); } public function testAddExchange() @@ -296,26 +245,11 @@ public function testAddExchange() $exchange = new Exchange(); $exchange->vhost = '/'; - $exchange->type = 'fanout'; $exchange->name = self::EXCHANGE_TEST_NAME; $exchange->durable = true; - $loop = $this->loop; - $PHPUnit = $this; - - $success = false; - $this->object->addExchange($exchange) - ->then(function($resultExchange) use ($exchange, &$success, $loop, $PHPUnit) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Exchange', $exchange); - $PHPUnit->assertEquals($resultExchange->toJson(), $exchange->toJson()); - $success = true; - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }); - - $loop->run(); - $this->assertTrue($success); + $resultExchange = $this->waitForPromiseToFulfill($this->object->addExchange($exchange)); + $this->assertEquals($resultExchange->name, $exchange->name); } public function testAddExchangeFailed() @@ -327,20 +261,7 @@ public function testAddExchangeFailed() $exchange->name = self::EXCHANGE_TEST_NAME; $exchange->durable = true; - $loop = $this->loop; - $PHPUnit = $this; - - $success = false; - $this->object->addExchange($exchange) - ->then(function() use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->addExchange($exchange)); } public function testAddExchangeThatAlreadyExists() @@ -351,158 +272,65 @@ public function testAddExchangeThatAlreadyExists() $this->syncClient->addExchange($exchange); - $exchange->durable = true; - - $loop = $this->loop; - $PHPUnit = $this; + $exchange->type = 'durable'; - $success = false; - $this->object->addExchange($exchange) - ->then(function() use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->addExchange($exchange)); } public function testListQueues() { - $queue = $this->createQueue(); - - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->listQueues() - ->then(function($queues) use ($PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($queues); - foreach ($queues as $queue) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $queue); - } - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $this->createQueue(); - $loop->run(); + $queues = $this->waitForPromiseToFulfill($this->object->listQueues()); + $this->assertNonEmptyArrayCollection($queues); + foreach ($queues as $queue) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $queue); + } } - private function createQueue() - { - $queue = new Queue(); - $queue->vhost = self::VIRTUAL_HOST; - $queue->name = self::QUEUE_TEST_NAME; - - $this->syncClient->addQueue($queue); - - return $queue; - } public function testListQueuesWithVhost() { - $queue = $this->createQueue(); - - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->listQueues(self::VIRTUAL_HOST) - ->then(function($queues) use ($PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($queues); - foreach ($queues as $queue) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $queue); - } - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $this->createQueue(); - $loop->run(); + $queues = $this->waitForPromiseToFulfill($this->object->listQueues(self::VIRTUAL_HOST)); + $this->assertNonEmptyArrayCollection($queues); + foreach ($queues as $queue) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $queue); + } } public function testListQueueFailed() { - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->listQueues(self::NONEXISTENT_VIRTUAL_HOST) - ->then(function($queues) use ($PHPUnit, $loop) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->listQueues(self::NONEXISTENT_VIRTUAL_HOST)); } public function testGetQueue() { $this->createQueue(); - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $this->object->getQueue(self::VIRTUAL_HOST, self::QUEUE_TEST_NAME) - ->then(function($resultQueue) use (&$success, $PHPUnit, $loop) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $resultQueue); - $PHPUnit->assertEquals($PHPUnit::VIRTUAL_HOST, $resultQueue->vhost); - $PHPUnit->assertEquals($PHPUnit::QUEUE_TEST_NAME, $resultQueue->name); - $success = true; - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not fail'); - }); - - $loop->run(); - $this->assertTrue($success); + $resultQueue = $this->waitForPromiseToFulfill($this->object->getQueue(self::VIRTUAL_HOST, self::QUEUE_TEST_NAME)); + $this->assertInstanceOf('RabbitMQ\Management\Entity\Queue', $resultQueue); + $this->assertEquals(self::VIRTUAL_HOST, $resultQueue->vhost); + $this->assertEquals(self::QUEUE_TEST_NAME, $resultQueue->name); } public function testGetQueueFailed() { - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->getQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME) - ->then(function($queues) use ($PHPUnit, $loop) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->getQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME)); } public function testAddQueue() { - $loop = $this->loop; - $client = $this->object; - $PHPUnit = $this; - $queue = new Queue(); $queue->vhost = '/'; $queue->name = self::QUEUE_TEST_NAME; - $this->object->addQueue($queue) - ->then(function($returnedQueue) use ($queue, $loop, $client, $PHPUnit) { - $PHPUnit->assertInstanceOf('RabbitMQ\\Management\\Entity\\Queue', $returnedQueue); - $PHPUnit->assertEquals($returnedQueue->toJson(), $queue->toJson()); + $returnedQueue = $this->waitForPromiseToFulfill($this->object->addQueue($queue)); + $this->assertInstanceOf('RabbitMQ\\Management\\Entity\\Queue', $returnedQueue); + $this->assertEquals($returnedQueue->name, $queue->name); - $client->deleteQueue('/', $PHPUnit::QUEUE_TEST_NAME) - ->then(function() use ($loop) { - $loop->stop(); - }); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not success'); - }); - - $loop->run(); + $this->syncClient->deleteQueue('/', self::QUEUE_TEST_NAME); } public function testAddQueueFailed() @@ -511,158 +339,66 @@ public function testAddQueueFailed() $queue->vhost = self::NONEXISTENT_VIRTUAL_HOST; $queue->name = self::QUEUE_TEST_NAME; - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->addQueue($queue) - ->then(function() use ($PHPUnit, $loop) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->addQueue($queue)); } public function testDeleteQueue() { $queue = $this->createQueue(); - $loop = $this->loop; - $client = $this->object; - $PHPUnit = $this; - $success = false; - - $this->object->deleteQueue($queue->vhost, $queue->name) - ->then(function() use ($queue, $client, &$success) { - $client->getQueue($queue->vhost, $queue->name) - ->then(function() { - $PHPUnit->fail('Should not success'); - }, function() use (&$success) { - $success = true; - }); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not fail'); - }); - - $loop->run(); - $this->assertTrue($success); + $this->waitForPromiseToFulfill($this->object->deleteQueue($queue->vhost, $queue->name)); + $this->assertPromiseRejects($this->object->getQueue($queue->vhost, $queue->name)); } public function testDeleteQueueFailed() { - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->deleteQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME) - ->then(function() use ($PHPUnit, $loop) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->deleteQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME)); } public function testAddQueueThatAlreadyExists() { $queue = $this->createQueue(); - $queue->durable = true; - $loop = $this->loop; - $PHPUnit = $this; - - $this->object->addQueue($queue) - ->then(function() use ($PHPUnit, $loop) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->addQueue($queue)); } + public function testPurgeQueueFailed() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $this->object->purgeQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME) - ->then(function() use ($PHPUnit, $loop) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->purgeQueue(self::NONEXISTENT_VIRTUAL_HOST, self::QUEUE_TEST_NAME)); } + public function testListBindingsByQueue() { - $loop = $this->loop; - $PHPUnit = $this; + $this->createQueue(); foreach ($this->syncClient->listQueues() as $queue) { - $this->object->listBindingsByQueue($queue) - ->then(function($bindings) use ($loop, $queue, $PHPUnit) { - foreach ($bindings as $binding) { - /* @var $binding Binding */ - $PHPUnit->assertEquals('/', $binding->vhost); - $PHPUnit->assertEquals($queue->name, $binding->destination); - } - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not fail'); - }); + $bindings = $this->waitForPromiseToFulfill($this->object->listBindingsByQueue($queue)); + foreach ($bindings as $binding) { + $this->assertEquals('/', $binding->vhost); + $this->assertEquals($queue->name, $binding->destination); + } } - - $loop->run(); } + public function testListBindingsByQueueFailed() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - $queue = new Queue(); $queue->name = 'nonexistent queue'; $queue->vhost = self::NONEXISTENT_VIRTUAL_HOST; - $this->object->listBindingsByQueue($queue) - ->then(function() use ($PHPUnit, $loop) { - $PHPUnit->fail('Should not success'); - }, function() use (&$success, $loop) { - $success = true; - $loop->stop(); - }); - - $loop->run(); + $bindings = $this->waitForPromiseToFulfill($this->object->listBindingsByQueue($queue)); + $count = count($bindings); + $this->assertEquals(0, $count); } + public function testListBindingsByExchangeAndQueue() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $queue = $this->createQueue(); - - $exchange = new Exchange(); - $exchange->vhost = self::VIRTUAL_HOST; - $exchange->name = self::EXCHANGE_TEST_NAME; - - $this->syncClient->addExchange($exchange); + $this->createBinding(); foreach ($this->syncClient->listQueues() as $queue) { foreach ($this->syncClient->listExchanges() as $exchange) { @@ -670,59 +406,26 @@ public function testListBindingsByExchangeAndQueue() continue; } - $this->object->listBindingsByExchangeAndQueue(self::VIRTUAL_HOST, $exchange->name, $queue->name) - ->then(function($bindings) use (&$success, $loop, $queue, $exchange, $PHPUnit) { - foreach ($bindings as $binding) { - $PHPUnit->assertEquals('/', $binding->vhost); - $PHPUnit->assertEquals($queue->name, $binding->destination); - $PHPUnit->assertEquals($exchange->name, $binding->source); - } - $success = true; - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not fail'); - }); - - foreach ($this->object->listBindingsByExchangeAndQueue('/', $exchange->name, $queue->name) as $binding) { - /* @var $binding Binding */ + $bindings = $this->waitForPromiseToFulfill($this->object->listBindingsByExchangeAndQueue(self::VIRTUAL_HOST, $exchange->name, $queue->name)); + foreach ($bindings as $binding) { $this->assertEquals('/', $binding->vhost); $this->assertEquals($queue->name, $binding->destination); $this->assertEquals($exchange->name, $binding->source); } } } - - $loop->run(); - $this->assertTrue($success); } + public function testListBindingsByExchangeAndQueueFailed() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $this->object->listBindingsByExchangeAndQueue(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME) - ->then(function($bindings) use ($PHPUnit, $loop, &$success) { - $success = true; - $loop->stop(); - $PHPUnit->assertCount(0, $bindings); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not fail'); - }); - - $loop->run(); - - $this->assertTrue($success); + $bindings = $this->waitForPromiseToFulfill($this->object->listBindingsByExchangeAndQueue(self::NONEXISTENT_VIRTUAL_HOST, self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME)); + $this->assertCount(0, $bindings); } + public function testAddBinding() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - $client = $this->object; - $queue = $this->createQueue(); $exchange = new Exchange(); @@ -739,33 +442,16 @@ public function testAddBinding() $binding->routing_key = 'rounting.key'; $binding->arguments = array('bim' => 'boom'); - $this->object->addBinding($binding) - ->then(function($res) use ($client, &$success, $loop, $PHPUnit) { - $client->listBindingsByExchangeAndQueue('/', $PHPUnit::EXCHANGE_TEST_NAME, $PHPUnit::QUEUE_TEST_NAME) - ->then(function($bindings) use ($client, &$success, $loop) { - foreach ($bindings as $binding) { - if ($binding->routing_key === 'rounting.key' && $binding->arguments === array('bim' => 'boom')) { - $success = true; - - $found = $binding; - break; - } - } - $client->deleteBinding($binding) - ->then(function() use ($loop) { - $loop->stop(); - }); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should not fail'); - }); - }, function($error) use ($PHPUnit) { - $PHPUnit->fail('Should not fail'); - }); - - $loop->run(); - $this->assertTrue($success); + $this->waitForPromiseToFulfill($this->object->addBinding($binding)); + $bindings = $this->waitForPromiseToFulfill($this->object->listBindingsByExchangeAndQueue('/', self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME)); + foreach ($bindings as $binding) { + $this->assertTrue($binding->routing_key === 'rounting.key' && $binding->arguments === array('bim' => 'boom')); + } + $this->waitForPromiseToFulfill($this->object->deleteBinding($binding)); + } + public function testAddBindingFailed() { $binding = new Binding(); @@ -773,191 +459,82 @@ public function testAddBindingFailed() $binding->source = self::EXCHANGE_TEST_NAME; $binding->destination = self::QUEUE_TEST_NAME; - - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $this->object->addBinding($binding) - ->then(function() use ($PHPUnit) { - $PHPUnit->fail('Should no success'); - }, function() use ($loop, &$success) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->addBinding($binding)); } + public function testDeleteBinding() { $this->createBinding(); + $found = null; + $bindings = $this->waitForPromiseToFulfill($this->object->listBindingsByExchangeAndQueue('/', self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME)); + foreach ($bindings as $binding) { + if ($binding->routing_key == 'rounting.key') { + $found = $binding; + break; + } + } + $this->assertNotNull($found); - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - $client = $this->object; + $this->waitForPromiseToFulfill($this->object->deleteBinding($found)); + $bindings = $this->waitForPromiseToFulfill($this->object->listBindingsByExchangeAndQueue('/', self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME)); + $found = null; - $this->object->listBindingsByExchangeAndQueue('/', self::EXCHANGE_TEST_NAME, self::QUEUE_TEST_NAME) - ->then(function($bindings) use ($client, &$success, $loop, $PHPUnit) { - $found = false; - foreach ($bindings as $binding) { - if ($binding->routing_key == 'rounting.key') { - $found = $binding; - break; - } - } - $client->deleteBinding($found) - ->then(function() use ($client, &$success, $loop, $PHPUnit) { - $client->listBindingsByExchangeAndQueue('/', $PHPUnit::EXCHANGE_TEST_NAME, $PHPUnit::QUEUE_TEST_NAME) - ->then(function($bindings) use (&$success, $loop, $PHPUnit) { - $found = false; - - foreach ($bindings as $binding) { - if ($binding->routing_key == 'rounting.key') { - $found = true; - } - } - - if ($found) { - $PHPUnit->fail('unable to find delete the binding'); - } - $success = true; - $loop->stop(); - }, function() { - $PHPUnit->fail('Should no failed'); - }); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no failed'); - }); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no failed'); - }); - - $loop->run(); - $this->assertTrue($success); + foreach ($bindings as $binding) { + if ($binding->routing_key == 'rounting.key') { + $found = $binding; + break; + } + } + $this->assertNull($found); } - private function createBinding() - { - $queue = $this->createQueue(); - - $exchange = new Exchange(); - $exchange->name = self::EXCHANGE_TEST_NAME; - $exchange->vhost = '/'; - - $this->syncClient->addExchange($exchange); - - $binding = new Binding(); - $binding->vhost = '/'; - $binding->source = self::EXCHANGE_TEST_NAME; - $binding->destination = self::QUEUE_TEST_NAME; - $binding->routing_key = 'rounting.key'; - - $this->syncClient->addBinding($binding); - - return $binding; - } public function testDeleteNonexistentBinding() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - $binding = new Binding(); $binding->vhost = self::VIRTUAL_HOST; $binding->source = self::EXCHANGE_TEST_NAME; $binding->destination = self::QUEUE_TEST_NAME; $binding->properties_key = 'bingo'; - $this->object->deleteBinding($binding) - ->then(function() use ($PHPUnit) { - $PHPUnit->fail('Should no success'); - }, function() use ($loop, &$success) { - $success = true; - $loop->stop(); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseRejects($this->object->deleteBinding($binding)); } + public function testListBindings() { $this->createBinding(); - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $this->object->listBindings() - ->then(function($bindings) use (&$success, $PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($bindings); - foreach ($bindings as $binding) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Binding', $binding); - } - $success = true; - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); + $bindings = $this->waitForPromiseToFulfill($this->object->listBindings()); + $this->assertNonEmptyArrayCollection($bindings); + foreach ($bindings as $binding) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Binding', $binding); + } - $loop->run(); - $this->assertTrue($success); } + public function testListBindingsWithVhost() { $this->createBinding(); - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $this->object->listBindings(self::VIRTUAL_HOST) - ->then(function($bindings) use (&$success, $PHPUnit, $loop) { - $PHPUnit->assertNonEmptyArrayCollection($bindings); - foreach ($bindings as $binding) { - $PHPUnit->assertInstanceOf('RabbitMQ\Management\Entity\Binding', $binding); - } - $success = true; - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); - - $loop->run(); - $this->assertTrue($success); + $bindings = $this->waitForPromiseToFulfill($this->object->listBindings(self::VIRTUAL_HOST)); + $this->assertNonEmptyArrayCollection($bindings); + foreach ($bindings as $binding) { + $this->assertInstanceOf('RabbitMQ\Management\Entity\Binding', $binding); + } } + public function testAlivenessTest() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - - $this->object->alivenessTest(self::VIRTUAL_HOST) - ->then(function($result) use ($PHPUnit, &$success){ - $PHPUnit->assertTrue($result); - $success = true; - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); - - $loop->run(); - $this->assertTrue($success); + $this->assertPromiseFulfills($this->object->alivenessTest(self::VIRTUAL_HOST)); } public function testPurgeQueue() { - $loop = $this->loop; - $PHPUnit = $this; - $success = false; - $client = $this->object; - $queue = $this->createQueue(); $exchange = new Exchange(); @@ -976,37 +553,64 @@ public function testPurgeQueue() $message = json_encode(array( 'properties' => array(), - 'routing_key' => self::QUEUE_TEST_NAME, - 'payload' => 'body', + 'routing_key' => self::QUEUE_TEST_NAME, + 'payload' => 'body', 'payload_encoding' => 'string', - )); + )); + $message = str_replace('[]', '{}', $message); $n = 12; while ($n > 0) { - $this->syncClientClient->post('/api/exchanges/' . urlencode('/') . '/' . self::EXCHANGE_TEST_NAME . '/publish', array('content-type' => 'application/json'), $message)->send(); + $this->syncClientClient->post('/api/exchanges/' . urlencode('/') . '/' . self::EXCHANGE_TEST_NAME . '/publish', + ['headers' => ['content-type' => 'application/json'], 'body' => $message]); $n--; } - usleep(2000000); + sleep(10); $this->syncClient->refreshQueue($queue); $this->assertEquals(12, $queue->messages_ready); - $this->object->purgeQueue('/', self::QUEUE_TEST_NAME) - ->then(function() use ($client, &$success, $PHPUnit, $queue){ + $this->waitForPromiseToFulfill($this->object->purgeQueue('/', self::QUEUE_TEST_NAME)); + sleep(15); + $this->syncClient->refreshQueue($queue); + $this->assertEquals(0, $queue->messages_ready); + } - usleep(4000000); - $client->refreshQueue($queue); - $success = true; - $PHPUnit->assertEquals(0, $queue->messages_ready); - $loop->stop(); - }, function() use ($PHPUnit) { - $PHPUnit->fail('Should no fail'); - }); - $loop->run(); - $this->assertTrue($success); + private function createQueue() + { + $queue = new Queue(); + $queue->vhost = self::VIRTUAL_HOST; + $queue->name = self::QUEUE_TEST_NAME; + + $this->syncClient->addQueue($queue); + + return $queue; + } + + + private function createBinding() + { + $this->createQueue(); + + $exchange = new Exchange(); + $exchange->name = self::EXCHANGE_TEST_NAME; + $exchange->vhost = '/'; + + $this->syncClient->addExchange($exchange); + + $binding = new Binding(); + $binding->vhost = '/'; + $binding->source = self::EXCHANGE_TEST_NAME; + $binding->destination = self::QUEUE_TEST_NAME; + $binding->routing_key = 'rounting.key'; + + $this->syncClient->addBinding($binding); + + return $binding; } + public function assertNonEmptyArrayCollection($collection) { $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $collection); diff --git a/tests/src/RabbitMQ/Tests/Management/GuaranteeTest.php b/tests/src/RabbitMQ/Tests/Management/GuaranteeTest.php index ada800e..11ce5ea 100644 --- a/tests/src/RabbitMQ/Tests/Management/GuaranteeTest.php +++ b/tests/src/RabbitMQ/Tests/Management/GuaranteeTest.php @@ -1,14 +1,18 @@ -client = APIClient::factory(array('host' => 'localhost')); $this->object = new Guarantee($this->client); @@ -424,6 +428,8 @@ public function testProbeBindingThatDoesExistWithDifferentArguments() */ public function testEnsureBinding() { + $this->expectNotToPerformAssertions(); + $exchange = new Exchange(); $exchange->type = 'fanout'; $exchange->vhost = '/'; @@ -466,6 +472,8 @@ public function testEnsureBinding() */ public function testEnsureBindingAlreadyBound() { + $this->expectNotToPerformAssertions(); + $exchange = new Exchange(); $exchange->type = 'fanout'; $exchange->vhost = '/'; diff --git a/testserver/Dockerfile b/testserver/Dockerfile new file mode 100644 index 0000000..43e73dc --- /dev/null +++ b/testserver/Dockerfile @@ -0,0 +1,13 @@ +FROM rabbitmq:3.8.0-rc.1-management +COPY rabbitmq.conf /etc/rabbitmq/ + + +# run me with: +# docker build -f Dockerfile -t rabbitmq-test-server +# docker run -p 5672:5672 -p 15672:15672 --name rabbitmq-test-server rabbitmq-test-server + +# warning, those ports will be open on the local machine with default guest/guest username/password +# this is for testing only + + + diff --git a/testserver/rabbitmq.conf b/testserver/rabbitmq.conf new file mode 100644 index 0000000..57300e0 --- /dev/null +++ b/testserver/rabbitmq.conf @@ -0,0 +1,10 @@ +listeners.tcp.default = 5672 +management.listener.port = 15672 +management.listener.ssl = false +collect_statistics_interval=500 + +# Note: this makes the guest/guest user externally accessible +# export with care from docker. This is just for the testing +# server +loopback_users.guest = false +