graze /
queue
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /** |
||||||
| 4 | * This file is part of graze/queue. |
||||||
| 5 | * |
||||||
| 6 | * Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com> |
||||||
| 7 | * |
||||||
| 8 | * For the full copyright and license information, please view the LICENSE |
||||||
| 9 | * file that was distributed with this source code. |
||||||
| 10 | * |
||||||
| 11 | * @license https://github.com/graze/queue/blob/master/LICENSE MIT |
||||||
| 12 | * |
||||||
| 13 | * @link https://github.com/graze/queue |
||||||
| 14 | */ |
||||||
| 15 | |||||||
| 16 | namespace Graze\Queue; |
||||||
| 17 | |||||||
| 18 | use ArrayIterator; |
||||||
| 19 | use Graze\Queue\Adapter\AdapterInterface; |
||||||
| 20 | use Graze\Queue\Handler\AbstractAcknowledgementHandler; |
||||||
| 21 | use Graze\Queue\Message\MessageFactoryInterface; |
||||||
| 22 | use Graze\Queue\Message\MessageInterface; |
||||||
| 23 | use Mockery as m; |
||||||
| 24 | use Mockery\MockInterface; |
||||||
| 25 | use Graze\Queue\Test\TestCase; |
||||||
| 26 | |||||||
| 27 | class ClientTest extends TestCase |
||||||
| 28 | { |
||||||
| 29 | /** @var AdapterInterface|MockInterface */ |
||||||
| 30 | private $adapter; |
||||||
| 31 | /** @var MessageFactoryInterface|MockInterface */ |
||||||
| 32 | private $factory; |
||||||
| 33 | /** @var AbstractAcknowledgementHandler|MockInterface */ |
||||||
| 34 | private $handler; |
||||||
| 35 | /** @var MessageInterface|MockInterface */ |
||||||
| 36 | private $messageA; |
||||||
| 37 | /** @var MessageInterface|MockInterface */ |
||||||
| 38 | private $messageB; |
||||||
| 39 | /** @var MessageInterface|MockInterface */ |
||||||
| 40 | private $messageC; |
||||||
| 41 | /** @var MessageInterface[]|MockInterface[] */ |
||||||
| 42 | private $messages; |
||||||
| 43 | /** @var Client */ |
||||||
| 44 | private $client; |
||||||
| 45 | |||||||
| 46 | public function setUp() |
||||||
| 47 | { |
||||||
| 48 | $this->adapter = m::mock(AdapterInterface::class); |
||||||
| 49 | $this->factory = m::mock(MessageFactoryInterface::class); |
||||||
| 50 | $this->handler = m::mock(AbstractAcknowledgementHandler::class); |
||||||
| 51 | |||||||
| 52 | $this->messageA = $a = m::mock(MessageInterface::class); |
||||||
| 53 | $this->messageB = $b = m::mock(MessageInterface::class); |
||||||
| 54 | $this->messageC = $c = m::mock(MessageInterface::class); |
||||||
| 55 | $this->messages = [$a, $b, $c]; |
||||||
| 56 | |||||||
| 57 | $this->client = new Client($this->adapter, [ |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 58 | 'handler' => $this->handler, |
||||||
| 59 | 'message_factory' => $this->factory, |
||||||
| 60 | ]); |
||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | public function testInterface() |
||||||
| 64 | { |
||||||
| 65 | assertThat($this->client, is(anInstanceOf(ConsumerInterface::class))); |
||||||
| 66 | assertThat($this->client, is(anInstanceOf(DeleterInterface::class))); |
||||||
| 67 | assertThat($this->client, is(anInstanceOf(ProducerInterface::class))); |
||||||
| 68 | assertThat($this->client, is(anInstanceOf(PurgerInterface::class))); |
||||||
| 69 | } |
||||||
| 70 | |||||||
| 71 | public function testCreate() |
||||||
| 72 | { |
||||||
| 73 | $this->factory->shouldReceive('createMessage')->once()->with('foo', ['bar'])->andReturn($this->messageA); |
||||||
|
0 ignored issues
–
show
The method
shouldReceive() does not exist on Graze\Queue\Message\MessageFactoryInterface.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 74 | |||||||
| 75 | assertThat($this->client->create('foo', ['bar']), is(identicalTo($this->messageA))); |
||||||
| 76 | } |
||||||
| 77 | |||||||
| 78 | public function testSend() |
||||||
| 79 | { |
||||||
| 80 | $this->adapter->shouldReceive('enqueue')->once()->with($this->messages); |
||||||
|
0 ignored issues
–
show
The method
shouldReceive() does not exist on Graze\Queue\Adapter\AdapterInterface.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 81 | |||||||
| 82 | $this->client->send($this->messages); |
||||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | public function testReceive() |
||||||
| 86 | { |
||||||
| 87 | $worker = function () { |
||||||
| 88 | }; |
||||||
| 89 | |||||||
| 90 | $messages = new ArrayIterator($this->messages); |
||||||
| 91 | |||||||
| 92 | $this->adapter->shouldReceive('dequeue')->once()->with($this->factory, 1)->andReturn($messages); |
||||||
| 93 | $this->handler->shouldReceive('__invoke')->once()->with($messages, $this->adapter, $worker); |
||||||
|
0 ignored issues
–
show
The method
shouldReceive() does not exist on Graze\Queue\Handler\AbstractAcknowledgementHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 94 | |||||||
| 95 | $this->client->receive($worker); |
||||||
| 96 | } |
||||||
| 97 | |||||||
| 98 | public function testPurge() |
||||||
| 99 | { |
||||||
| 100 | $this->adapter->shouldReceive('purge')->once(); |
||||||
| 101 | $this->client->purge(); |
||||||
| 102 | } |
||||||
| 103 | |||||||
| 104 | public function testDelete() |
||||||
| 105 | { |
||||||
| 106 | $this->adapter->shouldReceive('delete')->once(); |
||||||
| 107 | $this->client->delete(); |
||||||
| 108 | } |
||||||
| 109 | } |
||||||
| 110 |