diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index eab5077..4db0a13 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -45,5 +45,13 @@ public function dequeue(MessageFactoryInterface $factory, $limit); */ public function enqueue(array $messages); + /** + * @return void + */ public function purge(); + + /** + * @return void + */ + public function delete(); } diff --git a/src/Adapter/ArrayAdapter.php b/src/Adapter/ArrayAdapter.php index 3eff7e2..52151fd 100644 --- a/src/Adapter/ArrayAdapter.php +++ b/src/Adapter/ArrayAdapter.php @@ -79,6 +79,14 @@ public function purge() $this->queue = []; } + /** + * {@inheritdoc} + */ + public function delete() + { + $this->purge(); + } + /** * @param MessageInterface $message */ diff --git a/src/Adapter/SqsAdapter.php b/src/Adapter/SqsAdapter.php index 45c3399..fddb28c 100644 --- a/src/Adapter/SqsAdapter.php +++ b/src/Adapter/SqsAdapter.php @@ -198,6 +198,14 @@ public function purge() $this->client->purgeQueue(['QueueUrl' => $this->getQueueUrl()]); } + /** + * {@inheritdoc} + */ + public function delete() + { + $this->client->deleteQueue(['QueueUrl' => $this->getQueueUrl()]); + } + /** * @param MessageInterface[] $messages * diff --git a/src/Client.php b/src/Client.php index a40614c..050f6eb 100644 --- a/src/Client.php +++ b/src/Client.php @@ -92,6 +92,14 @@ public function purge() return $this->adapter->purge(); } + /** + * {@inheritdoc} + */ + public function delete() + { + $this->adapter->delete(); + } + /** * @return callable */ diff --git a/src/ProducerInterface.php b/src/ProducerInterface.php index b1c8f91..f08b2e2 100644 --- a/src/ProducerInterface.php +++ b/src/ProducerInterface.php @@ -10,7 +10,7 @@ * * @license https://github.com/graze/queue/blob/master/LICENSE MIT * - * @link https://github.com/graze/queue + * @link https://github.com/graze/queue */ namespace Graze\Queue; @@ -24,9 +24,17 @@ interface ProducerInterface public function create($body, array $options = []); /** - * @param array $message + * @param array $messages */ public function send(array $messages); + /** + * @return void + */ public function purge(); + + /** + * @return void + */ + public function delete(); } diff --git a/tests/integration/ArrayIntegrationTest.php b/tests/integration/ArrayIntegrationTest.php index 76609a3..f60af7a 100644 --- a/tests/integration/ArrayIntegrationTest.php +++ b/tests/integration/ArrayIntegrationTest.php @@ -94,4 +94,16 @@ public function testPurge() assertThat($msgs, is(emptyArray())); } + + public function testDelete() + { + $this->client->delete(); + + $msgs = []; + $this->client->receive(function ($msg) use (&$msgs) { + $msgs[] = $msg; + }, null); + + assertThat($msgs, is(emptyArray())); + } } diff --git a/tests/integration/SqsIntegrationTest.php b/tests/integration/SqsIntegrationTest.php index 684726f..13210f0 100644 --- a/tests/integration/SqsIntegrationTest.php +++ b/tests/integration/SqsIntegrationTest.php @@ -232,4 +232,16 @@ public function testPurge() assertThat($msgs, is(emptyArray())); } + + public function testDelete() + { + $url = $this->stubCreateQueue(); + + $deleteModel = m::mock('Aws\ResultInterface'); + $this->sqsClient->shouldReceive('deleteQueue')->once()->with([ + 'QueueUrl' => $url, + ])->andReturn($deleteModel); + + $this->client->delete(); + } } diff --git a/tests/unit/Adapter/ArrayAdapterTest.php b/tests/unit/Adapter/ArrayAdapterTest.php index e494cef..bd38e04 100644 --- a/tests/unit/Adapter/ArrayAdapterTest.php +++ b/tests/unit/Adapter/ArrayAdapterTest.php @@ -121,4 +121,17 @@ public function testPurge() assertThat(iterator_to_array($iterator), is(emptyArray())); } + + public function testDelete() + { + $iterator = $this->adapter->dequeue($this->factory, 10); + + assertThat(iterator_to_array($iterator), is(nonEmptyArray())); + + $this->adapter->delete(); + + $iterator = $this->adapter->dequeue($this->factory, 10); + + assertThat(iterator_to_array($iterator), is(emptyArray())); + } } diff --git a/tests/unit/Adapter/SqsAdapterTest.php b/tests/unit/Adapter/SqsAdapterTest.php index 44dbe86..38e52bc 100644 --- a/tests/unit/Adapter/SqsAdapterTest.php +++ b/tests/unit/Adapter/SqsAdapterTest.php @@ -234,4 +234,16 @@ public function testPurge() assertThat($adapter->purge(), is(nullValue())); } + + public function testDelete() + { + $adapter = new SqsAdapter($this->client, 'foo'); + $url = $this->stubCreateQueue('foo'); + + $this->client->shouldReceive('deleteQueue')->once()->with([ + 'QueueUrl' => $url, + ])->andReturn($this->model); + + assertThat($adapter->delete(), is(nullValue())); + } }