1 | <?php |
||
10 | class ContainerTest extends \PHPUnit_Framework_TestCase { |
||
11 | |||
12 | /** |
||
13 | * @var Container |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | /** |
||
18 | */ |
||
19 | protected function setUp() { |
||
20 | $this->object = new Container; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | */ |
||
25 | public function testBasicSetAndGet() { |
||
26 | $this->assertFalse($this->object->has('test')); |
||
27 | $this->object->set('test', 'just a string'); |
||
28 | $this->assertTrue($this->object->has('test')); |
||
29 | $this->assertEquals('just a string', $this->object->get('test')); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | */ |
||
34 | public function testNonSharedSetAndGetCallable() { |
||
35 | $this->assertFalse($this->object->has('test')); |
||
36 | $callable = function () { $a = new \stdClass(); $a->mt = microtime(true); return $a; }; |
||
37 | $this->object->set('test', $callable); |
||
38 | $this->assertTrue($this->object->has('test')); |
||
39 | $inst = $this->object->get('test'); |
||
40 | $this->assertInstanceOf('\stdClass', $inst); |
||
41 | $this->assertFalse($inst === $this->object->get('test')); |
||
42 | } |
||
43 | |||
44 | public function testSharedSetAndGetCallable() { |
||
45 | $this->assertFalse($this->object->has('test')); |
||
46 | $callable = function () { $a = new \stdClass(); $a->mt = microtime(true); return $a; }; |
||
47 | $this->object->set('test', CallableDefinition::factory($callable)->setShared(true)); |
||
48 | $this->assertTrue($this->object->has('test')); |
||
49 | $inst = $this->object->get('test'); |
||
50 | $this->assertInstanceOf('stdClass', $inst); |
||
51 | $this->assertTrue($inst === $this->object->get('test')); |
||
52 | } |
||
53 | |||
54 | public function testInvalidDefinition() { |
||
58 | |||
59 | /** |
||
60 | * |
||
61 | */ |
||
62 | public function testUnregisterNotShared() { |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | */ |
||
74 | public function testUnregisterShared() { |
||
82 | |||
83 | public function testUnregisterInvalidSharedDefinition() { |
||
87 | |||
88 | public function testNotSharedSetAndGetDefinition() { |
||
97 | |||
98 | public function testSharedSetAndGetDefinition() { |
||
107 | |||
108 | public function testProperties() |
||
116 | |||
117 | public function testServicesSearch() |
||
142 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.