Skip to content
Merged
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
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SHELL = /bin/sh

install: ## Download the depenedencies then build the image :rocket:.
make 'composer-install --optimize-autoloader --ignore-platform-reqs'
docker build --tag graze-queue:latest .
docker build --tag graze/graze-queue:latest .

composer-%: ## Run a composer command, `make "composer-<command> [...]"`.
docker run -it --rm \
Expand All @@ -22,17 +22,17 @@ test: ## Run the unit and intergration testsuites.
test: test-unit test-intergration

test-unit: ## Run the unit testsuite.
docker run --rm -t graze-queue \
docker run --rm -t graze/graze-queue -v $$(pwd):/opt/graze/queue \
vendor/bin/phpunit --testsuite unit

test-intergration: ## Run the integration testsuite.
docker run --rm -t graze-queue \
docker run --rm -t graze/graze-queue -v $$(pwd):/opt/graze/queue \
vendor/bin/phpunit --testsuite integration

test-coverage: ## Run the testsuites with coverage enabled.
docker run --rm -t graze-queue \
docker run --rm -t graze/graze-queue -v $$(pwd):/opt/graze/queue \
vendor/bin/phpunit --coverage-text --testsuite unit
docker run --rm -t graze-queue \
docker run --rm -t graze/graze-queue -v $$(pwd):/opt/graze/queue \
vendor/bin/phpunit --coverage-text --testsuite integration

test-matrix:
Expand All @@ -44,8 +44,8 @@ test-matrix:
vendor/bin/phpunit --testsuite unit


clean: ## Stop running containers and clean up an images.
docker rmi graze-queue:latest
clean: ## Clean up any images.
docker rmi graze/graze-queue:latest

help: ## Show this help message.
echo "usage: make [target] ..."
Expand Down
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
54 changes: 54 additions & 0 deletions src/Adapter/Exception/MethodNotSupportedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* This file is part of graze/queue.
*
* Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license https://github.com/graze/queue/blob/master/LICENSE MIT
*
* @link https://github.com/graze/queue
*/

namespace Graze\Queue\Adapter\Exception;

use Exception;
use Graze\Queue\Adapter\AdapterInterface;
use Graze\Queue\Message\MessageInterface;

/**
* Exception to throw when an implmentation of {@see \Graze\Queue\AdapterInterface}
* does not support a method on {@see \Graze\Queue\Adapter\AdapterInterface}.
*/
class MethodNotSupportedException extends AdapterException
{
/**
* @var string
*/
protected $method;

/**
* @param string $method
* @param AdapterInterface $adapter
* @param MessageInterface[] $messages
* @param array $debug
* @param Exception $previous
*/
public function __construct($method, AdapterInterface $adapter, array $messages, array $debug = [], Exception $previous = null)
{
$this->method = $method;

parent::__construct(sprintf('Method `%s` is not supported by this adapter', $method), $adapter, $messages, $debug, $previous);
}

/**
* @return string
*/
public function getMethod()
{
return $this->method;
}
}
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
10 changes: 9 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Graze\Queue\Message\MessageFactory;
use Graze\Queue\Message\MessageFactoryInterface;

final class Client implements ConsumerInterface, ProducerInterface
final class Client implements ConsumerInterface, DeleterInterface, ProducerInterface, PurgerInterface
{
/**
* @param AdapterInterface
Expand Down Expand Up @@ -92,6 +92,14 @@ public function purge()
return $this->adapter->purge();
}

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

/**
* @return callable
*/
Expand Down
24 changes: 24 additions & 0 deletions src/DeleterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* This file is part of graze/queue.
*
* Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license https://github.com/graze/queue/blob/master/LICENSE MIT
*
* @link https://github.com/graze/queue
*/

namespace Graze\Queue;

interface DeleterInterface
{
/**
* @return void
*/
public function delete();
}
6 changes: 2 additions & 4 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,7 @@ interface ProducerInterface
public function create($body, array $options = []);

/**
* @param array $message
* @param array $messages
*/
public function send(array $messages);

public function purge();
}
24 changes: 24 additions & 0 deletions src/PurgerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* This file is part of graze/queue.
*
* Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license https://github.com/graze/queue/blob/master/LICENSE MIT
*
* @link https://github.com/graze/queue
*/

namespace Graze\Queue;

interface PurgerInterface
{
/**
* @return void
*/
public function purge();
}
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()));
}
}
68 changes: 68 additions & 0 deletions tests/unit/Adapter/Exception/MethodNotSupportedExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* This file is part of graze/queue.
*
* Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license https://github.com/graze/queue/blob/master/LICENSE MIT
*
* @link https://github.com/graze/queue
*/

namespace Graze\Queue\Adapter\Exception;

use Exception;
use Mockery as m;
use PHPUnit_Framework_TestCase as TestCase;

class MethodNotSupportedExceptionTest extends TestCase
{
public function setUp()
{
$this->adapter = m::mock('Graze\Queue\Adapter\AdapterInterface');
$this->debug = ['foo' => 'bar'];

$this->messageA = $a = m::mock('Graze\Queue\Message\MessageInterface');
$this->messageB = $b = m::mock('Graze\Queue\Message\MessageInterface');
$this->messageC = $c = m::mock('Graze\Queue\Message\MessageInterface');
$this->messages = [$a, $b, $c];

$this->previous = new Exception();

$this->exception = new MethodNotSupportedException('method', $this->adapter, $this->messages, $this->debug, $this->previous);
}

public function testInterface()
{
assertThat($this->exception, is(anInstanceOf('Graze\Queue\Adapter\Exception\AdapterException')));
}

public function testGetMethod()
{
assertThat($this->exception->getMethod(), is(identicalTo('method')));
}

public function testGetAdapter()
{
assertThat($this->exception->getAdapter(), is(identicalTo($this->adapter)));
}

public function testGetDebug()
{
assertThat($this->exception->getDebug(), is(identicalTo($this->debug)));
}

public function testGetMessages()
{
assertThat($this->exception->getMessages(), is(identicalTo($this->messages)));
}

public function testGetPrevious()
{
assertThat($this->exception->getPrevious(), is(identicalTo($this->previous)));
}
}
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()));
}
}
14 changes: 14 additions & 0 deletions tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function setUp()
public function testInterface()
{
assertThat($this->client, is(anInstanceOf('Graze\Queue\ConsumerInterface')));
assertThat($this->client, is(anInstanceOf('Graze\Queue\DeleterInterface')));
assertThat($this->client, is(anInstanceOf('Graze\Queue\ProducerInterface')));
assertThat($this->client, is(anInstanceOf('Graze\Queue\PurgerInterface')));
}

public function testCreate()
Expand Down Expand Up @@ -70,4 +72,16 @@ public function testReceive()

$this->client->receive($worker);
}

public function testPurge()
{
$this->adapter->shouldReceive('purge')->once();
$this->client->purge();
}

public function testDelete()
{
$this->adapter->shouldReceive('delete')->once();
$this->client->delete();
}
}