|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fwk\Di\Definitions; |
|
4
|
|
|
use Fwk\Di\Container; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Test class for CallableDefinition. |
|
8
|
|
|
* Generated by PHPUnit on 2013-06-28 at 00:09:38. |
|
9
|
|
|
*/ |
|
10
|
|
|
class ArrayDefinitionTest extends \PHPUnit_Framework_TestCase { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var ArrayDefinition |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $object; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
$me = $this; |
|
|
|
|
|
|
20
|
|
|
$this->object = new ArrayDefinition(array( |
|
21
|
|
|
'testArg' => 'normalString', |
|
22
|
|
|
'property' => ':propTest', |
|
23
|
|
|
'reference' => '@testRef' |
|
24
|
|
|
)); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected function getContainer() |
|
28
|
|
|
{ |
|
29
|
|
|
$container = new Container(); |
|
30
|
|
|
$container->set('testRef', 'testReferenceOk'); |
|
31
|
|
|
$container->setProperty('propTest', 'testPropertyOk'); |
|
32
|
|
|
|
|
33
|
|
|
return $container; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testArrayResultIsComplete() |
|
37
|
|
|
{ |
|
38
|
|
|
$array = $this->object->invoke($this->getContainer()); |
|
39
|
|
|
$this->assertTrue(is_array($array)); |
|
40
|
|
|
$this->assertArrayHasKey('property', $array); |
|
41
|
|
|
$this->assertArrayHasKey('reference', $array); |
|
42
|
|
|
$this->assertArrayHasKey('testArg', $array); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals('testPropertyOk', $array['property']); |
|
45
|
|
|
$this->assertEquals('testReferenceOk', $array['reference']); |
|
46
|
|
|
$this->assertEquals('normalString', $array['testArg']); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testGettersAndSetters() |
|
50
|
|
|
{ |
|
51
|
|
|
$arr = $this->object->getArray(); |
|
52
|
|
|
$this->assertEquals($arr, $this->object->getArray()); |
|
53
|
|
|
$arr['newProp'] = "ohyeah"; |
|
54
|
|
|
$this->assertNotEquals($arr, $this->object->getArray()); |
|
55
|
|
|
$this->object->setArray($arr); |
|
56
|
|
|
$this->assertEquals($arr, $this->object->getArray()); |
|
57
|
|
|
} |
|
58
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.