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:disable |
||
| 12 | class Test_Pre_Connection_JITM extends TestCase { |
||
| 13 | use MockeryPHPUnitIntegration; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * An array containing a test pre-connection JITM. |
||
| 17 | * |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | private $test_jitms; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The Pre_Connection_JITM instance. |
||
| 24 | * |
||
| 25 | * @var Pre_Connection_JITM |
||
| 26 | */ |
||
| 27 | private $jitm_instance; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Set up. |
||
| 31 | * |
||
| 32 | * @before |
||
| 33 | */ |
||
| 34 | public function set_up() { |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Tear down. |
||
| 59 | * |
||
| 60 | * @after |
||
| 61 | */ |
||
| 62 | public function tear_down() { |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The pre-connection JITMs are disabled by default by the `jetpack_pre_connection_prompt_helpers` filter's default value. |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function test_get_messages_prompt_helpers_default() { |
|
| 87 | |||
| 88 | /** |
||
| 89 | * The pre-connection JITMs are disabled when the current user does not have the 'install_plugins' capability. |
||
| 90 | */ |
||
| 91 | View Code Duplication | public function test_get_messages_user_cannot_install_plugins() { |
|
| 110 | |||
| 111 | /** |
||
| 112 | * The pre-connection JITMs are empty by default. The default value of the 'jetpack_pre_connection_jitms' filter is |
||
| 113 | * an empty array. |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function test_get_messages_jitms_filter_default() { |
|
| 133 | |||
| 134 | /** |
||
| 135 | * The Pre_Connection_JITM::get_messages method returns an empty array when the the 'jetpack_pre_connection_jitms' filter |
||
| 136 | * returns anything other than an array. |
||
| 137 | */ |
||
| 138 | View Code Duplication | public function test_get_messages_filter_returns_string() { |
|
| 157 | |||
| 158 | /** |
||
| 159 | * The pre-connection JITMs are added using the `jetpack_pre_connection_jitms` filter. |
||
| 160 | */ |
||
| 161 | View Code Duplication | public function test_get_messages_return_message() { |
|
| 172 | |||
| 173 | /** |
||
| 174 | * A pre-connection JITM is only displayed if its message_path value matches the message path |
||
| 175 | * passed to Pre_Connection_JITM::get_messages. In this test, the test JITM's path does not match the |
||
| 176 | * tested path. |
||
| 177 | */ |
||
| 178 | public function test_get_messages_unmatched_message_path() { |
||
| 188 | |||
| 189 | /** |
||
| 190 | * The pre-connection JITM is not displayed if the message array is missing a required key. In this test, the JITM is |
||
| 191 | * missing the message_path key. |
||
| 192 | */ |
||
| 193 | View Code Duplication | public function test_get_messages_missing_key() { |
|
| 205 | |||
| 206 | /** |
||
| 207 | * A pre-connection JITM is displayed if it has unexpected keys. |
||
| 208 | */ |
||
| 209 | public function test_get_messages_extra_key() { |
||
| 222 | |||
| 223 | private function set_prompt_helpers_and_user_cap_conditions() { |
||
| 233 | } |
||
| 234 |