MessageFactoryTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateMessageWithValidator() 0 11 1
A setUp() 0 3 1
A testInterface() 0 3 1
A testCreateMessageWithMetadata() 0 7 1
A testCreateMessage() 0 7 1
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) {
0 ignored issues
show
Unused Code introduced by
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 ignore-unused  annotation

56
            'validator' => function (/** @scrutinizer ignore-unused */ $msg) {

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...
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