Completed
Push — master ( 03ffe6...2c1c5a )
by Will
11s
created

MessageFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 43.48 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 20
loc 46
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testInterface() 0 4 1
A testCreateMessage() 8 8 1
A testCreateMessageWithMetadata() 0 8 1
A testCreateMessageWithValidator() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 PHPUnit_Framework_TestCase as 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 View Code Duplication
    public function testCreateMessage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function testCreateMessageWithValidator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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

This check looks from 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