1 | <?php |
||
9 | class ContainerTest extends \PHPUnit_Framework_TestCase { |
||
10 | |||
11 | /** |
||
12 | * @var Container |
||
13 | */ |
||
14 | protected $object; |
||
15 | |||
16 | /** |
||
17 | */ |
||
18 | protected function setUp() { |
||
19 | $this->object = new Container; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | */ |
||
24 | public function testBasicSetAndGet() { |
||
25 | $this->assertFalse($this->object->has('test')); |
||
26 | $this->object->set('test', 'just a string'); |
||
27 | $this->assertTrue($this->object->has('test')); |
||
28 | $this->assertEquals('just a string', $this->object->get('test')); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | */ |
||
33 | public function testNonSharedSetAndGetCallable() { |
||
34 | $this->assertFalse($this->object->has('test')); |
||
35 | $callable = function () { $a = new \stdClass(); $a->mt = microtime(true); return $a; }; |
||
36 | $this->object->set('test', $callable); |
||
37 | $this->assertTrue($this->object->has('test')); |
||
38 | $inst = $this->object->get('test'); |
||
39 | $this->assertInstanceOf('\stdClass', $inst); |
||
40 | $this->assertFalse($inst === $this->object->get('test')); |
||
41 | } |
||
42 | |||
43 | public function testSharedSetAndGetCallable() { |
||
44 | $this->assertFalse($this->object->has('test')); |
||
45 | $callable = function () { $a = new \stdClass(); $a->mt = microtime(true); return $a; }; |
||
46 | $this->object->set('test', CallableDefinition::factory($callable)->setShared(true)); |
||
47 | $this->assertTrue($this->object->has('test')); |
||
48 | $inst = $this->object->get('test'); |
||
49 | $this->assertInstanceOf('stdClass', $inst); |
||
50 | $this->assertTrue($inst === $this->object->get('test')); |
||
51 | } |
||
52 | |||
53 | public function testInvalidDefinition() { |
||
57 | |||
58 | /** |
||
59 | * |
||
60 | */ |
||
61 | public function testUnregisterNotShared() { |
||
69 | |||
70 | /** |
||
71 | * |
||
72 | */ |
||
73 | public function testUnregisterShared() { |
||
81 | |||
82 | public function testUnregisterInvalidSharedDefinition() { |
||
86 | |||
87 | public function testNotSharedSetAndGetDefinition() { |
||
96 | |||
97 | public function testSharedSetAndGetDefinition() { |
||
106 | |||
107 | public function testProperties() |
||
115 | |||
116 | public function __testServicesSearch() |
||
141 | } |
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.