|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wonderland\Container\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Wonderland\Container\Exception\DuplicatedServiceException; |
|
7
|
|
|
use Wonderland\Container\Service\ServiceInstanceInterface; |
|
8
|
|
|
use Wonderland\Container\ServiceContainer; |
|
9
|
|
|
use Wonderland\Container\Service\ServiceDefinitionInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ContainerTest |
|
13
|
|
|
* @package Wonderland\Container\Tests |
|
14
|
|
|
* @author Alice Praud <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class ServiceContainerTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function test_addService() |
|
19
|
|
|
{ |
|
20
|
|
|
$definition = $this->getMockBuilder(ServiceDefinitionInterface::class)->getMock(); |
|
21
|
|
|
|
|
22
|
|
|
$definition->expects($this->once()) |
|
23
|
|
|
->method('getServiceName') |
|
24
|
|
|
->willReturn('service.name'); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertSame('service.name', $definition->getServiceName()); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// * @expectedException DuplicatedServiceException |
|
30
|
|
|
/** |
|
31
|
|
|
*/ |
|
32
|
|
|
public function test_addServiceInstance() |
|
33
|
|
|
{ |
|
34
|
|
|
$instance = $this->getMockBuilder(ServiceInstanceInterface::class)->getMock(); |
|
35
|
|
|
|
|
36
|
|
|
$instance->expects($this->once()) |
|
37
|
|
|
->method('getServiceName') |
|
38
|
|
|
->willReturn('service.name'); |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$this->assertSame('service.name', $instance->getServiceName()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function test_addServiceInstance2() |
|
45
|
|
|
{ |
|
46
|
|
|
$instance = $this->getMockBuilder(ServiceInstanceInterface::class)->getMock(); |
|
47
|
|
|
|
|
48
|
|
|
$object = new \DateTime(); |
|
49
|
|
|
$instance->expects($this->once()) |
|
50
|
|
|
->method('getInstance') |
|
51
|
|
|
->willReturn($object); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertSame($object, $instance->getInstance()); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
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.