1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\TreeHouse\WorkerBundle; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use OutOfBoundsException; |
7
|
|
|
use PhpSpec\ObjectBehavior; |
8
|
|
|
use TreeHouse\WorkerBundle\Executor\ExecutorInterface; |
9
|
|
|
use TreeHouse\WorkerBundle\ExecutorPool; |
10
|
|
|
|
11
|
|
|
class ExecutorPoolSpec extends ObjectBehavior |
12
|
|
|
{ |
13
|
|
|
public function it_is_initializable() |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
$this->shouldHaveType(ExecutorPool::class); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function it_should_be_empty_when_constructed() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$this->getExecutors()->shouldHaveCount(0); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function it_should_throw_exception_on_unknown_executor() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$this->shouldThrow( |
26
|
|
|
new OutOfBoundsException('There is no executor registered for action "sample".') |
27
|
|
|
)->duringGetExecutor('sample'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function it_should_have_registered_executor(ExecutorInterface $executor) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$executor->getName()->willReturn('executor'); |
33
|
|
|
|
34
|
|
|
$this->addExecutor($executor); |
35
|
|
|
|
36
|
|
|
$this->hasExecutor('executor')->shouldReturn(true); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function it_should_return_registered_executor(ExecutorInterface $executor) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$executor->getName()->willReturn('executor'); |
42
|
|
|
|
43
|
|
|
$this->addExecutor($executor); |
44
|
|
|
|
45
|
|
|
$this->getExecutor('executor')->shouldReturn($executor); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function it_should_throw_exception_when_readding_executor_with_same_name(ExecutorInterface $executor) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$executor->getName()->willReturn('executor'); |
51
|
|
|
|
52
|
|
|
$this->addExecutor($executor); |
53
|
|
|
|
54
|
|
|
$expectedException = new InvalidArgumentException( |
55
|
|
|
'There is already an executor registered for action "executor".' |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->shouldThrow($expectedException)->duringAddExecutor($executor); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function it_should_register_multiple_executors(ExecutorInterface $firstExecutor, ExecutorInterface $secondExecutor) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$firstExecutor->getName()->willReturn('executor.first'); |
64
|
|
|
$secondExecutor->getName()->willReturn('executor.second'); |
65
|
|
|
|
66
|
|
|
$this->addExecutor($firstExecutor); |
67
|
|
|
$this->addExecutor($secondExecutor); |
68
|
|
|
|
69
|
|
|
$this->getExecutors()->shouldReturn([ |
70
|
|
|
'executor.first' => $firstExecutor, |
71
|
|
|
'executor.second' => $secondExecutor |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|