Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
8 changes: 8 additions & 0 deletions src/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public function purge()
$this->queue = [];
}

/**
* {@inheritdoc}
*/
public function delete()
{
$this->purge();
}

/**
* @param MessageInterface $message
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Adapter/SqsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 8 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public function purge()
return $this->adapter->purge();
}

/**
* {@inheritdoc}
*/
public function delete()
{
$this->adapter->delete();
}

/**
* @return callable
*/
Expand Down
12 changes: 10 additions & 2 deletions src/ProducerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
12 changes: 12 additions & 0 deletions tests/integration/ArrayIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
12 changes: 12 additions & 0 deletions tests/integration/SqsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
13 changes: 13 additions & 0 deletions tests/unit/Adapter/ArrayAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
12 changes: 12 additions & 0 deletions tests/unit/Adapter/SqsAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}