Completed
Pull Request — master (#13)
by Marijan
17:08
created

ExecutorPoolSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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()
0 ignored issues
show
Coding Style introduced by
Method name "ExecutorPoolSpec::it_is_initializable" is not in camel caps format
Loading history...
14
    {
15
        $this->shouldHaveType(ExecutorPool::class);
16
    }
17
18
    public function it_should_be_empty_when_constructed()
0 ignored issues
show
Coding Style introduced by
Method name "ExecutorPoolSpec::it_should_be_empty_when_constructed" is not in camel caps format
Loading history...
19
    {
20
        $this->getExecutors()->shouldHaveCount(0);
21
    }
22
23
    public function it_should_throw_exception_on_unknown_executor()
0 ignored issues
show
Coding Style introduced by
Method name "ExecutorPoolSpec::it_should_throw_exception_on_unknown_executor" is not in camel caps format
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
Method name "ExecutorPoolSpec::it_should_have_registered_executor" is not in camel caps format
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
Method name "ExecutorPoolSpec::it_should_return_registered_executor" is not in camel caps format
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
Method name "ExecutorPoolSpec::it_should_throw_exception_when_readding_executor_with_same_name" is not in camel caps format
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
Method name "ExecutorPoolSpec::it_should_register_multiple_executors" is not in camel caps format
Loading history...
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