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

ArrayIntegrationTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 66.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 62
loc 93
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A testReceive() 9 9 1
A testReceiveWithPolling() 9 9 1
A testReceiveWithNoMessages() 11 11 1
A testReceiveWithLimitAndNoMessages() 11 11 1
A testSend() 0 4 1
A testPurge() 11 11 1
A testDelete() 11 11 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;
17
18
use Graze\Queue\Adapter\ArrayAdapter;
19
use Graze\Queue\Message\MessageFactory;
20
use Graze\Queue\Message\MessageInterface;
21
use PHPUnit_Framework_TestCase as TestCase;
22
23
class ArrayIntegrationTest extends TestCase
24
{
25
    /** @var MessageInterface[] */
26
    private $messages;
27
    /** @var Client */
28
    private $client;
29
30
    public function setUp()
31
    {
32
        $factory = new MessageFactory();
33
34
        $this->messages = [
35
            $factory->createMessage('foo'),
36
            $factory->createMessage('bar'),
37
            $factory->createMessage('baz'),
38
        ];
39
40
        $this->client = new Client(new ArrayAdapter($this->messages));
41
    }
42
43 View Code Duplication
    public function testReceive()
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...
44
    {
45
        $msgs = [];
46
        $this->client->receive(function ($msg) use (&$msgs) {
47
            $msgs[] = $msg;
48
        }, 100);
49
50
        assertThat($msgs, is(identicalTo($this->messages)));
51
    }
52
53 View Code Duplication
    public function testReceiveWithPolling()
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
        $msgs = [];
56
        $this->client->receive(function ($msg) use (&$msgs) {
57
            $msgs[] = $msg;
58
        }, null);
59
60
        assertThat($msgs, is(identicalTo($this->messages)));
61
    }
62
63 View Code Duplication
    public function testReceiveWithNoMessages()
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...
64
    {
65
        $client = new Client(new ArrayAdapter());
66
67
        $msgs = [];
68
        $client->receive(function ($msg) use (&$msgs) {
69
            $msgs[] = $msg;
70
        }, null);
71
72
        assertThat($msgs, is(emptyArray()));
73
    }
74
75 View Code Duplication
    public function testReceiveWithLimitAndNoMessages()
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...
76
    {
77
        $client = new Client(new ArrayAdapter());
78
79
        $msgs = [];
80
        $client->receive(function ($msg) use (&$msgs) {
81
            $msgs[] = $msg;
82
        }, 10);
83
84
        assertThat($msgs, is(emptyArray()));
85
    }
86
87
    public function testSend()
88
    {
89
        $this->client->send([$this->client->create('foo')]);
90
    }
91
92 View Code Duplication
    public function testPurge()
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...
93
    {
94
        $this->client->purge();
95
96
        $msgs = [];
97
        $this->client->receive(function ($msg) use (&$msgs) {
98
            $msgs[] = $msg;
99
        }, null);
100
101
        assertThat($msgs, is(emptyArray()));
102
    }
103
104 View Code Duplication
    public function testDelete()
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...
105
    {
106
        $this->client->delete();
107
108
        $msgs = [];
109
        $this->client->receive(function ($msg) use (&$msgs) {
110
            $msgs[] = $msg;
111
        }, null);
112
113
        assertThat($msgs, is(emptyArray()));
114
    }
115
}
116