Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 11 | class ManagerTest extends TestCase { |
||
| 12 | public function setUp() { |
||
| 17 | |||
| 18 | public function tearDown() { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @covers Automattic\Jetpack\Connection\Manager::is_active |
||
| 26 | */ |
||
| 27 | public function test_is_active_when_connected() { |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @covers Automattic\Jetpack\Connection\Manager::is_active |
||
| 41 | */ |
||
| 42 | public function test_is_active_when_not_connected() { |
||
| 49 | |||
| 50 | public function test_api_url_defaults() { |
||
| 60 | |||
| 61 | public function test_api_url_uses_constants() { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 78 | */ |
||
| 79 | public function test_is_user_connected_with_default_user_id_logged_out() { |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 87 | */ |
||
| 88 | public function test_is_user_connected_with_false_user_id_logged_out() { |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 96 | */ |
||
| 97 | public function test_is_user_connected_with_user_id_logged_out_not_connected() { |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 108 | */ |
||
| 109 | View Code Duplication | public function test_is_user_connected_with_default_user_id_logged_in() { |
|
| 121 | |||
| 122 | /** |
||
| 123 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 124 | */ |
||
| 125 | View Code Duplication | public function test_is_user_connected_with_user_id_logged_in() { |
|
| 137 | |||
| 138 | /** |
||
| 139 | * Mock a global function and make it return a certain value. |
||
| 140 | * |
||
| 141 | * @param string $function_name Name of the function. |
||
| 142 | * @param mixed $return_value Return value of the function. |
||
| 143 | * @return phpmock\Mock The mock object. |
||
| 144 | */ |
||
| 145 | View Code Duplication | protected function mock_function( $function_name, $return_value = null ) { |
|
| 154 | } |
||
| 155 |