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); |
|
|
|
|
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); |
|
|
|
|
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() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$channel = 'foo'; |
59
|
|
|
$lock = Phake::mock('Itkg\DelayEventBundle\Model\Lock'); |
60
|
|
|
Phake::when($this->manager)->getLock($channel)->thenReturn($lock); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->handler->lock($channel); |
63
|
|
|
Phake::verify($lock)->setCommandLocked(true); |
64
|
|
|
Phake::verify($this->manager)->save($lock); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function testRelease() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$channel = 'foo'; |
70
|
|
|
$lock = Phake::mock('Itkg\DelayEventBundle\Model\Lock'); |
71
|
|
|
Phake::when($this->manager)->getLock($channel)->thenReturn($lock); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->handler->release($channel); |
74
|
|
|
Phake::verify($lock)->setCommandLocked(false); |
75
|
|
|
Phake::verify($this->manager)->save($lock); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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: