Completed
Pull Request — master (#41)
by Ross
03:55
created

ContainerBasedHandlerLocatorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testGetHandler() 0 20 1
A testGetHandlerThrowsExceptionForNotFound() 0 12 1
1
<?php
2
3
namespace League\Tactician\Bundle\Tests\Handler;
4
5
use League\Tactician\Bundle\Handler\ContainerBasedHandlerLocator;
6
use Mockery\MockInterface;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
class ContainerBasedHandlerLocatorTest extends TestCase
11
{
12
13
    /**
14
     * @var ContainerInterface | MockInterface
15
     */
16
    protected $container;
17
18
    /**
19
     * @var ContainerBasedHandlerLocator
20
     */
21
    protected $locator;
22
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
27
        $this->container = \Mockery::mock(ContainerInterface::class);
28
    }
29
30
    public function testGetHandler()
31
    {
32
        $commandName = 'MyFakeCommand';
33
        $serviceId   = 'my_bundle.service.id';
34
35
        $definitions = [
36
            $commandName   => $serviceId,
37
            'OtherCommand' => 'my_bundle.order.id'
38
        ];
39
40
        $this->container->shouldReceive('get')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            ->with($serviceId)
42
            ->once()
43
            ->andReturn($serviceId);
44
45
        $this->locator = new ContainerBasedHandlerLocator($this->container, $definitions);
46
        $result        = $this->locator->getHandlerForCommand($commandName);
47
48
        $this->assertEquals($serviceId, $result);
49
    }
50
51
    /**
52
     * @expectedException \League\Tactician\Exception\MissingHandlerException
53
     */
54
    public function testGetHandlerThrowsExceptionForNotFound()
55
    {
56
        $definitions = [
57
            'OtherCommand' => 'my_bundle.order.id'
58
        ];
59
60
        $this->container->shouldReceive('get')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
            ->never();
62
63
        $this->locator = new ContainerBasedHandlerLocator($this->container, $definitions);
64
        $this->locator->getHandlerForCommand('MyFakeCommand');
65
    }
66
67
}
68