|
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') |
|
|
|
|
|
|
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') |
|
|
|
|
|
|
61
|
|
|
->never(); |
|
62
|
|
|
|
|
63
|
|
|
$this->locator = new ContainerBasedHandlerLocator($this->container, $definitions); |
|
64
|
|
|
$this->locator->getHandlerForCommand('MyFakeCommand'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
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.