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 | function test_class_implements_interface() { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @covers Automattic\Jetpack\Connection\Manager::is_active |
||
| 31 | */ |
||
| 32 | public function test_is_active_when_connected() { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @covers Automattic\Jetpack\Connection\Manager::is_active |
||
| 46 | */ |
||
| 47 | public function test_is_active_when_not_connected() { |
||
| 54 | |||
| 55 | public function test_api_url_defaults() { |
||
| 65 | |||
| 66 | public function test_api_url_uses_constants() { |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 83 | */ |
||
| 84 | public function test_is_user_connected_with_default_user_id_logged_out() { |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 92 | */ |
||
| 93 | public function test_is_user_connected_with_false_user_id_logged_out() { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 101 | */ |
||
| 102 | public function test_is_user_connected_with_user_id_logged_out_not_connected() { |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 113 | */ |
||
| 114 | View Code Duplication | public function test_is_user_connected_with_default_user_id_logged_in() { |
|
| 126 | |||
| 127 | /** |
||
| 128 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
| 129 | */ |
||
| 130 | View Code Duplication | public function test_is_user_connected_with_user_id_logged_in() { |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Mock a global function and make it return a certain value. |
||
| 145 | * |
||
| 146 | * @param string $function_name Name of the function. |
||
| 147 | * @param mixed $return_value Return value of the function. |
||
| 148 | * @return phpmock\Mock The mock object. |
||
| 149 | */ |
||
| 150 | View Code Duplication | protected function mock_function( $function_name, $return_value = null ) { |
|
| 159 | } |
||
| 160 |