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 // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 20 | class Test_Roles extends TestCase { |
||
| 21 | use MockeryPHPUnitIntegration; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Test setup. |
||
| 25 | * |
||
| 26 | * @before |
||
| 27 | */ |
||
| 28 | public function set_up() { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Test teardown. |
||
| 35 | * |
||
| 36 | * @after |
||
| 37 | */ |
||
| 38 | public function tear_down() { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Tests the current user by role. |
||
| 44 | * |
||
| 45 | * @covers Automattic\Jetpack\Roles::translate_current_user_to_role |
||
| 46 | */ |
||
| 47 | public function test_current_user_to_role_with_role() { |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Tests the current user by capability. |
||
| 59 | * |
||
| 60 | * @covers Automattic\Jetpack\Roles::translate_current_user_to_role |
||
| 61 | */ |
||
| 62 | public function test_current_user_to_role_with_capability() { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Test current user with no match. |
||
| 78 | * |
||
| 79 | * @covers Automattic\Jetpack\Roles::translate_current_user_to_role |
||
| 80 | */ |
||
| 81 | public function test_current_user_to_role_with_no_match() { |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Test translating an user to a role by role. |
||
| 89 | * |
||
| 90 | * @covers Automattic\Jetpack\Roles::translate_user_to_role |
||
| 91 | */ |
||
| 92 | View Code Duplication | public function test_user_to_role_with_role() { |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Test translating an user to a role by capablity. |
||
| 105 | * |
||
| 106 | * @covers Automattic\Jetpack\Roles::translate_user_to_role |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function test_user_to_role_with_capability() { |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Test translating an user to a role with no match. |
||
| 121 | * |
||
| 122 | * @covers Automattic\Jetpack\Roles::translate_user_to_role |
||
| 123 | */ |
||
| 124 | public function test_user_to_role_with_no_match() { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Test translating a role to a cap with an existing role. |
||
| 133 | * |
||
| 134 | * @covers Automattic\Jetpack\Roles::translate_role_to_cap |
||
| 135 | */ |
||
| 136 | public function test_role_to_cap_existing_role() { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Test translating a role to a cap with a non-existing role. |
||
| 142 | * |
||
| 143 | * @covers Automattic\Jetpack\Roles::translate_role_to_cap |
||
| 144 | */ |
||
| 145 | public function test_role_to_cap_non_existing_role() { |
||
| 148 | |||
| 149 | } |
||
| 150 |