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 | |||||||
| 26 | class ResultAcknowledgementHandlerTest extends TestCase |
||||||
| 27 | { |
||||||
| 28 | /** @var AdapterInterface|MockInterface */ |
||||||
| 29 | private $adapter; |
||||||
| 30 | /** @var ResultAcknowledgementHandler */ |
||||||
| 31 | private $handler; |
||||||
| 32 | /** @var MessageInterface|MockInterface */ |
||||||
| 33 | private $message; |
||||||
| 34 | /** @var ArrayIterator */ |
||||||
| 35 | private $messages; |
||||||
| 36 | |||||||
| 37 | public function setUp() |
||||||
| 38 | { |
||||||
| 39 | $this->adapter = m::mock('Graze\Queue\Adapter\AdapterInterface'); |
||||||
| 40 | |||||||
| 41 | $this->message = m::mock('Graze\Queue\Message\MessageInterface'); |
||||||
| 42 | $this->messages = new ArrayIterator([$this->message]); |
||||||
| 43 | |||||||
| 44 | $this->handler = new EagerAcknowledgementHandler(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | public function testHandleTrueResult() |
||||||
| 48 | { |
||||||
| 49 | $handler = new ResultAcknowledgementHandler(function ($result) { |
||||||
| 50 | return $result === true; |
||||||
| 51 | }, $this->handler); |
||||||
| 52 | |||||||
| 53 | $this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
|
0 ignored issues
–
show
The method
shouldReceive() does not exist on Graze\Queue\Message\MessageInterface.
(
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...
|
|||||||
| 54 | $this->adapter->shouldReceive('acknowledge')->once()->with(m::mustBe([$this->message])); |
||||||
|
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...
|
|||||||
| 55 | |||||||
| 56 | $msgs = []; |
||||||
| 57 | $handler($this->messages, $this->adapter, function ($msg, Closure $done) use (&$msgs) { |
||||||
|
0 ignored issues
–
show
The parameter
$done is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 58 | $msgs[] = $msg; |
||||||
| 59 | return true; |
||||||
| 60 | }); |
||||||
| 61 | |||||||
| 62 | assertThat($msgs, is(identicalTo(iterator_to_array($this->messages)))); |
||||||
| 63 | } |
||||||
| 64 | |||||||
| 65 | public function testHandleNonTrueResponse() |
||||||
| 66 | { |
||||||
| 67 | $handler = new ResultAcknowledgementHandler(function ($result) { |
||||||
| 68 | return $result === true; |
||||||
| 69 | }, $this->handler); |
||||||
| 70 | |||||||
| 71 | $this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 72 | $this->adapter->shouldReceive('reject')->once()->with(m::mustBe([$this->message])); |
||||||
| 73 | |||||||
| 74 | $handler($this->messages, $this->adapter, function ($msg, Closure $done) use (&$msgs) { |
||||||
|
0 ignored issues
–
show
The parameter
$msg is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$done is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 75 | return false; |
||||||
| 76 | }); |
||||||
| 77 | } |
||||||
| 78 | |||||||
| 79 | public function testCustomResultAcknowledgementHandler() |
||||||
| 80 | { |
||||||
| 81 | $handler = new ResultAcknowledgementHandler(function ($result) { |
||||||
| 82 | return $result === false; |
||||||
| 83 | }, $this->handler); |
||||||
| 84 | |||||||
| 85 | $this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
||||||
| 86 | $this->adapter->shouldReceive('acknowledge')->once()->with(m::mustBe([$this->message])); |
||||||
| 87 | |||||||
| 88 | $handler($this->messages, $this->adapter, function ($msg) { |
||||||
|
0 ignored issues
–
show
The parameter
$msg is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 89 | return false; |
||||||
| 90 | }); |
||||||
| 91 | } |
||||||
| 92 | } |
||||||
| 93 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..