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\Handler; |
||||||
| 17 | |||||||
| 18 | use ArrayIterator; |
||||||
| 19 | use Closure; |
||||||
| 20 | use Graze\Queue\Adapter\AdapterInterface; |
||||||
| 21 | use Graze\Queue\Message\MessageInterface; |
||||||
| 22 | use Mockery as m; |
||||||
| 23 | use Mockery\MockInterface; |
||||||
| 24 | use Graze\Queue\Test\TestCase; |
||||||
| 25 | use RuntimeException; |
||||||
| 26 | |||||||
| 27 | class BatchAcknowledgementHandlerTest extends TestCase |
||||||
| 28 | { |
||||||
| 29 | /** @var AdapterInterface|MockInterface */ |
||||||
| 30 | private $adapter; |
||||||
| 31 | /** @var MessageInterface|MockInterface */ |
||||||
| 32 | private $messageA; |
||||||
| 33 | /** @var MessageInterface|MockInterface */ |
||||||
| 34 | private $messageB; |
||||||
| 35 | /** @var MessageInterface|MockInterface */ |
||||||
| 36 | private $messageC; |
||||||
| 37 | /** @var ArrayIterator */ |
||||||
| 38 | private $messages; |
||||||
| 39 | /** @var BatchAcknowledgementHandler */ |
||||||
| 40 | private $handler; |
||||||
| 41 | |||||||
| 42 | public function setUp() |
||||||
| 43 | { |
||||||
| 44 | $this->adapter = m::mock(AdapterInterface::class); |
||||||
| 45 | |||||||
| 46 | $this->messageA = $a = m::mock(MessageInterface::class); |
||||||
| 47 | $this->messageB = $b = m::mock(MessageInterface::class); |
||||||
| 48 | $this->messageC = $c = m::mock(MessageInterface::class); |
||||||
| 49 | $this->messages = new ArrayIterator([$a, $b, $c]); |
||||||
| 50 | |||||||
| 51 | $this->handler = new BatchAcknowledgementHandler(3); |
||||||
| 52 | } |
||||||
| 53 | |||||||
| 54 | public function testHandle() |
||||||
| 55 | { |
||||||
| 56 | $handler = $this->handler; |
||||||
| 57 | |||||||
| 58 | $this->messageA->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 59 | $this->messageB->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 60 | $this->messageC->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 61 | $this->adapter->shouldReceive('acknowledge')->once()->with(iterator_to_array($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...
|
|||||||
| 62 | |||||||
| 63 | $msgs = []; |
||||||
| 64 | $handler($this->messages, $this->adapter, function ($msg, Closure $done) use (&$msgs) { |
||||||
| 65 | $msgs[] = $msg; |
||||||
| 66 | }); |
||||||
| 67 | |||||||
| 68 | assertThat($msgs, is(identicalTo(iterator_to_array($this->messages)))); |
||||||
| 69 | } |
||||||
| 70 | |||||||
| 71 | public function testHandleInvalidMessage() |
||||||
| 72 | { |
||||||
| 73 | $handler = $this->handler; |
||||||
| 74 | |||||||
| 75 | $this->messageA->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 76 | $this->messageB->shouldReceive('isValid')->once()->withNoArgs()->andReturn(false); |
||||||
| 77 | $this->messageC->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 78 | $this->adapter->shouldReceive('acknowledge')->once()->with([$this->messageA, $this->messageC]); |
||||||
| 79 | |||||||
| 80 | $msgs = []; |
||||||
| 81 | $handler($this->messages, $this->adapter, function ($msg) use (&$msgs) { |
||||||
| 82 | $msgs[] = $msg; |
||||||
| 83 | }); |
||||||
| 84 | |||||||
| 85 | assertThat($msgs, is(identicalTo([$this->messageA, $this->messageC]))); |
||||||
| 86 | } |
||||||
| 87 | |||||||
| 88 | /** |
||||||
| 89 | * @expectedException \RuntimeException |
||||||
| 90 | * @expectedExceptionMessage foo |
||||||
| 91 | */ |
||||||
| 92 | public function testHandleWorkerWithThrownException() |
||||||
| 93 | { |
||||||
| 94 | $handler = $this->handler; |
||||||
| 95 | |||||||
| 96 | $this->messageA->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 97 | $this->messageB->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 98 | |||||||
| 99 | $this->adapter->shouldReceive('acknowledge')->once()->with([$this->messageA]); |
||||||
| 100 | |||||||
| 101 | $handler($this->messages, $this->adapter, function ($msg) { |
||||||
| 102 | if ($msg === $this->messageB) { |
||||||
| 103 | throw new RuntimeException('foo'); |
||||||
| 104 | } |
||||||
| 105 | }); |
||||||
| 106 | } |
||||||
| 107 | } |
||||||
| 108 |
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.