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

FailedEnqueueExceptionTest::testInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Adapter\Exception;
17
18
use Exception;
19
use Graze\Queue\Adapter\AdapterInterface;
20
use Graze\Queue\Message\MessageInterface;
21
use Mockery as m;
22
use Mockery\MockInterface;
23
use PHPUnit_Framework_TestCase as TestCase;
24
25 View Code Duplication
class FailedEnqueueExceptionTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
26
{
27
    /** @var AdapterInterface|MockInterface */
28
    private $adapter;
29
    /** @var array */
30
    private $debug;
31
    /** @var MessageInterface[]|MockInterface[] */
32
    private $messages;
33
    /** @var Exception */
34
    private $previous;
35
    /** @var FailedEnqueueException */
36
    private $exception;
37
38
    public function setUp()
39
    {
40
        $this->adapter = m::mock(AdapterInterface::class);
41
        $this->debug = ['foo' => 'bar'];
42
43
        $a = m::mock(MessageInterface::class);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
44
        $b = m::mock(MessageInterface::class);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
45
        $c = m::mock(MessageInterface::class);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
46
        $this->messages = [$a, $b, $c];
47
48
        $this->previous = new Exception();
49
        $this->exception = new FailedEnqueueException($this->adapter, $this->messages, $this->debug, $this->previous);
0 ignored issues
show
Documentation introduced by
$this->messages is of type array<integer,object<Moc...kery\\MockInterface>"}>, but the function expects a array<integer,object<Gra...sage\MessageInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
    }
51
52
    public function testInterface()
53
    {
54
        assertThat($this->exception, is(anInstanceOf(AdapterException::class)));
55
    }
56
57
    public function testGetAdapter()
58
    {
59
        assertThat($this->exception->getAdapter(), is(identicalTo($this->adapter)));
60
    }
61
62
    public function testGetDebug()
63
    {
64
        assertThat($this->exception->getDebug(), is(identicalTo($this->debug)));
65
    }
66
67
    public function testGetMessages()
68
    {
69
        assertThat($this->exception->getMessages(), is(identicalTo($this->messages)));
70
    }
71
72
    public function testGetPrevious()
73
    {
74
        assertThat($this->exception->getPrevious(), is(identicalTo($this->previous)));
75
    }
76
}
77