1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DmTestTest\ServiceManager; |
4
|
|
|
|
5
|
|
|
use DmTest\ServiceManager\ServiceLocatorDummy; |
6
|
|
|
|
7
|
|
|
class ServiceLocatorDummyTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** @var ServiceLocatorDummy */ |
10
|
|
|
protected $sut; |
11
|
|
|
|
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
$this->sut = new ServiceLocatorDummy($this); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @covers DmTest\ServiceManager\ServiceLocatorDummy |
19
|
|
|
*/ |
20
|
|
|
public function testGetReturnsPreviouslySetObject() |
21
|
|
|
{ |
22
|
|
|
$stdObj = new \StdClass; |
23
|
|
|
|
24
|
|
|
$this->sut->set('StdClass', $stdObj); |
25
|
|
|
|
26
|
|
|
$result = $this->sut->get('StdClass'); |
27
|
|
|
|
28
|
|
|
$this->assertSame($result, $stdObj); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @covers DmTest\ServiceManager\ServiceLocatorDummy |
33
|
|
|
*/ |
34
|
|
|
public function testGetCreatesMockByDefault() |
35
|
|
|
{ |
36
|
|
|
$result = $this->sut->get('StdClass'); |
37
|
|
|
|
38
|
|
|
$this->assertInstanceOf('StdClass', $result); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @covers DmTest\ServiceManager\ServiceLocatorDummy |
43
|
|
|
* @expectedException \Zend\ServiceManager\Exception\ServiceNotFoundException |
44
|
|
|
*/ |
45
|
|
|
public function testGetThrowsExceptionWhenGetFailsAndCreationIsOptedOut() |
46
|
|
|
{ |
47
|
|
|
$this->sut->get('StdClass', ServiceLocatorDummy::CREATE_NOTHING); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers DmTest\ServiceManager\ServiceLocatorDummy |
52
|
|
|
*/ |
53
|
|
|
public function testGetCanCreateInterfaceMock() |
54
|
|
|
{ |
55
|
|
|
$result = $this->sut |
56
|
|
|
->get('DmTestTest\ServiceManager\Fixture\TestInterface', ServiceLocatorDummy::CREATE_INTERFACE); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf('DmTestTest\ServiceManager\Fixture\TestInterface', $result); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @covers DmTest\ServiceManager\ServiceLocatorDummy |
63
|
|
|
*/ |
64
|
|
|
public function testGetCanCreateTraitMock() |
65
|
|
|
{ |
66
|
|
|
$mock = $this->sut->get('DmTestTest\ServiceManager\Fixture\TestTrait', ServiceLocatorDummy::CREATE_TRAIT); |
67
|
|
|
|
68
|
|
|
$mock->expects($this->any()) |
69
|
|
|
->method('abstractMethod') |
70
|
|
|
->will($this->returnValue(true)); |
71
|
|
|
|
72
|
|
|
$this->assertTrue($mock->concreteMethod()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @covers DmTest\ServiceManager\ServiceLocatorDummy |
77
|
|
|
*/ |
78
|
|
|
public function testHasReturnsFalseForUnsetKeys() |
79
|
|
|
{ |
80
|
|
|
$this->assertFalse($this->sut->has('StdClass')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @covers DmTest\ServiceManager\ServiceLocatorDummy |
85
|
|
|
*/ |
86
|
|
|
public function testHasReturnsTrueForSetKeys() |
87
|
|
|
{ |
88
|
|
|
$this->sut->set('StdClass', new \StdClass); |
89
|
|
|
|
90
|
|
|
$this->assertTrue($this->sut->has('StdClass')); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|