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\Message; |
17
|
|
|
|
18
|
|
|
use Graze\Queue\Test\TestCase; |
19
|
|
|
|
20
|
|
|
class MessageFactoryTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** @var MessageFactory */ |
23
|
|
|
private $factory; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->factory = new MessageFactory(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testInterface() |
31
|
|
|
{ |
32
|
|
|
assertThat($this->factory, is(anInstanceOf('Graze\Queue\Message\MessageFactoryInterface'))); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCreateMessage() |
36
|
|
|
{ |
37
|
|
|
$message = $this->factory->createMessage('foo'); |
38
|
|
|
|
39
|
|
|
assertThat($message, is(anInstanceOf('Graze\Queue\Message\MessageInterface'))); |
40
|
|
|
assertThat($message->getBody(), is(identicalTo('foo'))); |
41
|
|
|
assertThat($message->isValid(), is(identicalTo(true))); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testCreateMessageWithMetadata() |
45
|
|
|
{ |
46
|
|
|
$message = $this->factory->createMessage('foo', ['metadata' => ['bar' => 'baz']]); |
47
|
|
|
|
48
|
|
|
assertThat($message, is(anInstanceOf('Graze\Queue\Message\MessageInterface'))); |
49
|
|
|
assertThat($message->getBody(), is(identicalTo('foo'))); |
50
|
|
|
assertThat($message->getMetadata()->get('bar'), is(identicalTo('baz'))); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testCreateMessageWithValidator() |
54
|
|
|
{ |
55
|
|
|
$message = $this->factory->createMessage('bar', [ |
56
|
|
|
'validator' => function ($msg) { |
|
|
|
|
57
|
|
|
return false; |
58
|
|
|
}, |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
assertThat($message, is(anInstanceOf('Graze\Queue\Message\MessageInterface'))); |
62
|
|
|
assertThat($message->getBody(), is(identicalTo('bar'))); |
63
|
|
|
assertThat($message->isValid(), is(identicalTo(false))); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.