1 | <?php |
||
6 | class DatabaseConnectionTest extends PHPUnit_Framework_TestCase |
||
7 | { |
||
8 | /** |
||
9 | * Instance of DatabaseConnection used in test. |
||
10 | */ |
||
11 | protected $databaseConnection; |
||
12 | |||
13 | public function setUp() |
||
22 | |||
23 | public function testCreateConnectionReturnsDatabaseConnection() |
||
29 | |||
30 | public function testGetInstanceReturnsCorrectInstance() |
||
36 | |||
37 | public function testSetOptionsAndGetOptionsReturnsCorrectValue() |
||
50 | |||
51 | public function testTryAgainIfCausedByLostConnectionCreateNewConnectionWhenReasonForExceptionIsConnectionLoss() |
||
58 | |||
59 | /** |
||
60 | * @expectedException \Exception |
||
61 | */ |
||
62 | public function testTryAgainIfCausedByLostConnectionThrowsExceptionWhenReasonForExceptionIsNotConnectionLoss() |
||
67 | |||
68 | /** |
||
69 | * Reference: https://jtreminio.com/2013/03/unit-testing-tutorial-part-3-testing-protected-private-methods-coverage-reports-and-crap/ |
||
70 | * Call protected/private method of a class. |
||
71 | * |
||
72 | * @param object &$object Instantiated object that we will run method on. |
||
73 | * @param string $methodName Method name to call |
||
74 | * @param array $parameters Array of parameters to pass into method. |
||
75 | * |
||
76 | * @return mixed Method return. |
||
77 | */ |
||
78 | public function invokeMethod(&$object, $methodName, array $parameters = []) |
||
86 | } |
||
87 |
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.