Completed
Pull Request — master (#34)
by Clément
20:44 queued 16:37
created

CommandLockHandlerTest::testInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
4
namespace Itkg\DelayEventBundle\Tests\Handler;
5
6
use Itkg\DelayEventBundle\DomainManager\LockManagerInterface;
7
use Itkg\DelayEventBundle\Handler\CommandLockHandler;
8
use Phake;
9
use Phake_IMock;
10
11
12
/**
13
 * Class CommandLockHandlerTest
14
 */
15
class CommandLockHandlerTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * @var CommandLockHandler
19
     */
20
    private $handler;
21
22
    /**
23
     * @var LockManagerInterface|Phake_IMock
24
     */
25
    private $manager;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function setUp()
31
    {
32
        parent::setUp();
33
34
        $this->manager = Phake::mock('Itkg\DelayEventBundle\DomainManager\LockManagerInterface');
35
        $this->handler = new CommandLockHandler($this->manager);
0 ignored issues
show
Documentation introduced by
$this->manager is of type object<Phake_IMock>, but the function expects a object<Itkg\DelayEventBu...r\LockManagerInterface>.

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...
36
    }
37
38
    public function testInstance()
39
    {
40
        $this->assertInstanceOf('Itkg\DelayEventBundle\Handler\LockHandlerInterface', $this->handler);
41
    }
42
43
    public function testIsLocked()
44
    {
45
        $channel = 'foo';
46
        $lock = Phake::mock('Itkg\DelayEventBundle\Model\Lock');
47
        Phake::when($this->manager)->getLock($channel)->thenReturn($lock);
0 ignored issues
show
Bug introduced by
It seems like $this->manager can also be of type object<Itkg\DelayEventBu...r\LockManagerInterface>; however, Phake::when() does only seem to accept object<Phake_IMock>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
48
49
        Phake::when($lock)->isCommandLocked()->thenReturn(false);
50
        $this->assertFalse($this->handler->isLocked($channel));
51
52
        Phake::when($lock)->isCommandLocked()->thenReturn(true);
53
        $this->assertTrue($this->handler->isLocked($channel));
54
    }
55
56 View Code Duplication
    public function testLock()
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...
57
    {
58
        $channel = 'foo';
59
        $lock = Phake::mock('Itkg\DelayEventBundle\Model\Lock');
60
        Phake::when($this->manager)->getLock($channel)->thenReturn($lock);
0 ignored issues
show
Bug introduced by
It seems like $this->manager can also be of type object<Itkg\DelayEventBu...r\LockManagerInterface>; however, Phake::when() does only seem to accept object<Phake_IMock>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
62
        $this->handler->lock($channel);
63
        Phake::verify($lock)->setCommandLocked(true);
64
        Phake::verify($this->manager)->save($lock);
0 ignored issues
show
Bug introduced by
It seems like $this->manager can also be of type object<Itkg\DelayEventBu...r\LockManagerInterface>; however, Phake::verify() does only seem to accept object<Phake_IMock>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
65
    }
66
67 View Code Duplication
    public function testRelease()
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...
68
    {
69
        $channel = 'foo';
70
        $lock = Phake::mock('Itkg\DelayEventBundle\Model\Lock');
71
        Phake::when($this->manager)->getLock($channel)->thenReturn($lock);
0 ignored issues
show
Bug introduced by
It seems like $this->manager can also be of type object<Itkg\DelayEventBu...r\LockManagerInterface>; however, Phake::when() does only seem to accept object<Phake_IMock>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
72
73
        $this->handler->release($channel);
74
        Phake::verify($lock)->setCommandLocked(false);
75
        Phake::verify($this->manager)->save($lock);
0 ignored issues
show
Bug introduced by
It seems like $this->manager can also be of type object<Itkg\DelayEventBu...r\LockManagerInterface>; however, Phake::verify() does only seem to accept object<Phake_IMock>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
76
    }
77
}
78