Completed
Push — master ( a91c7b...483fcf )
by Alice
18:08
created

ServiceContainerTest::test_addService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
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());
0 ignored issues
show
Bug introduced by
The method getServiceName() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
		$this->assertSame('service.name', $definition->/** @scrutinizer ignore-call */ getServiceName());

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...
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());
0 ignored issues
show
Bug introduced by
The method getInstance() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
		$this->assertSame($object, $instance->/** @scrutinizer ignore-call */ getInstance());

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...
54
	}
55
}
56