From f5b61df56a670bb9a4a1a0416aeb1b1a1315d016 Mon Sep 17 00:00:00 2001 From: Harry Bragg Date: Mon, 28 Sep 2015 11:58:54 +0100 Subject: [PATCH 1/2] add delete functionality --- src/Adapter/AdapterInterface.php | 8 ++++++++ src/Adapter/ArrayAdapter.php | 8 ++++++++ src/Adapter/SqsAdapter.php | 8 ++++++++ src/Client.php | 8 ++++++++ src/ProducerInterface.php | 12 ++++++++++-- tests/integration/ArrayIntegrationTest.php | 12 ++++++++++++ tests/integration/SqsIntegrationTest.php | 12 ++++++++++++ tests/unit/Adapter/ArrayAdapterTest.php | 13 +++++++++++++ tests/unit/Adapter/SqsAdapterTest.php | 12 ++++++++++++ 9 files changed, 91 insertions(+), 2 deletions(-) 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..7298650 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..32deae1 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..f86a548 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..d6c7ecd 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())); + } } From eac039189a9af03a1f15c64c6bd7dd07add7d4ee Mon Sep 17 00:00:00 2001 From: Harry Bragg Date: Mon, 28 Sep 2015 12:05:18 +0100 Subject: [PATCH 2/2] style-ci fixes --- src/Adapter/ArrayAdapter.php | 2 +- src/Adapter/SqsAdapter.php | 2 +- src/Client.php | 2 +- tests/unit/Adapter/SqsAdapterTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Adapter/ArrayAdapter.php b/src/Adapter/ArrayAdapter.php index 7298650..52151fd 100644 --- a/src/Adapter/ArrayAdapter.php +++ b/src/Adapter/ArrayAdapter.php @@ -80,7 +80,7 @@ public function purge() } /** - * {@inheritDoc} + * {@inheritdoc} */ public function delete() { diff --git a/src/Adapter/SqsAdapter.php b/src/Adapter/SqsAdapter.php index 32deae1..fddb28c 100644 --- a/src/Adapter/SqsAdapter.php +++ b/src/Adapter/SqsAdapter.php @@ -199,7 +199,7 @@ public function purge() } /** - * {@inheritDoc} + * {@inheritdoc} */ public function delete() { diff --git a/src/Client.php b/src/Client.php index f86a548..050f6eb 100644 --- a/src/Client.php +++ b/src/Client.php @@ -93,7 +93,7 @@ public function purge() } /** - * {@inheritDoc} + * {@inheritdoc} */ public function delete() { diff --git a/tests/unit/Adapter/SqsAdapterTest.php b/tests/unit/Adapter/SqsAdapterTest.php index d6c7ecd..38e52bc 100644 --- a/tests/unit/Adapter/SqsAdapterTest.php +++ b/tests/unit/Adapter/SqsAdapterTest.php @@ -241,7 +241,7 @@ public function testDelete() $url = $this->stubCreateQueue('foo'); $this->client->shouldReceive('deleteQueue')->once()->with([ - 'QueueUrl' => $url + 'QueueUrl' => $url, ])->andReturn($this->model); assertThat($adapter->delete(), is(nullValue()));