1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KochTest\Code; |
4
|
|
|
|
5
|
|
|
use Koch\Code\Reflection; |
6
|
|
|
|
7
|
|
|
class ReflectionTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var Reflection |
11
|
|
|
*/ |
12
|
|
|
protected $object; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Sets up the fixture, for example, opens a network connection. |
16
|
|
|
* This method is called before a test is executed. |
17
|
|
|
*/ |
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->object = new Reflection('Koch\Code\Reflection'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Tears down the fixture, for example, closes a network connection. |
25
|
|
|
* This method is called after a test is executed. |
26
|
|
|
*/ |
27
|
|
|
protected function tearDown() |
28
|
|
|
{ |
29
|
|
|
unset($this->object); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @covers Koch\Code\Reflection::setClassName |
34
|
|
|
* @covers Koch\Code\Reflection::__construct |
35
|
|
|
*/ |
36
|
|
|
public function testSetClassName() |
37
|
|
|
{ |
38
|
|
|
// set class via constructor |
39
|
|
|
$this->object = new Reflection('A'); |
40
|
|
|
$this->assertEquals('A', $this->object->getClassName()); |
41
|
|
|
|
42
|
|
|
// set class via method |
43
|
|
|
$this->object->setClassName('B'); |
44
|
|
|
$this->assertEquals('B', $this->object->getClassName()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @covers Koch\Code\Reflection::getClassName |
49
|
|
|
*/ |
50
|
|
|
public function testGetClassName() |
51
|
|
|
{ |
52
|
|
|
$this->assertEquals('Koch\Code\Reflection', $this->object->getClassName()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers Koch\Code\Reflection::getMethods |
57
|
|
|
* @covers Koch\Code\Reflection::__construct |
58
|
|
|
* @covers Koch\Autoload\Loader::autoload |
59
|
|
|
*/ |
60
|
|
|
public function testGetMethods() |
61
|
|
|
{ |
62
|
|
|
$methodsArray = $this->object->getMethods(); |
63
|
|
|
$this->assertArrayHasKey('Koch\Code\Reflection', $methodsArray); |
64
|
|
|
$this->assertArrayHasKey('getMethods', array_flip($methodsArray['Koch\Code\Reflection'])); |
65
|
|
|
|
66
|
|
|
// class does not exist exception |
67
|
|
|
$this->object = new Reflection('A'); |
68
|
|
|
$this->setExpectedException('RuntimeException', 'Class not existing: A'); |
69
|
|
|
$methodsArray = $this->object->getMethods(); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.