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 when the current user does not have the 'install_plugins' capability. |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function test_get_messages_user_cannot_install_plugins() { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * The pre-connection JITMs are empty by default. The default value of the 'jetpack_pre_connection_jitms' filter is |
||
| 85 | * an empty array. |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function test_get_messages_jitms_filter_default() { |
|
| 99 | |||
| 100 | /** |
||
| 101 | * The Pre_Connection_JITM::get_messages method returns an empty array when the the 'jetpack_pre_connection_jitms' filter |
||
| 102 | * returns anything other than an array. |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function test_get_messages_filter_returns_string() { |
|
| 117 | |||
| 118 | /** |
||
| 119 | * The pre-connection JITMs are added using the `jetpack_pre_connection_jitms` filter. |
||
| 120 | */ |
||
| 121 | View Code Duplication | public function test_get_messages_return_message() { |
|
| 132 | |||
| 133 | /** |
||
| 134 | * A pre-connection JITM is only displayed if its message_path value matches the message path |
||
| 135 | * passed to Pre_Connection_JITM::get_messages. In this test, the test JITM's path does not match the |
||
| 136 | * tested path. |
||
| 137 | */ |
||
| 138 | public function test_get_messages_unmatched_message_path() { |
||
| 148 | |||
| 149 | /** |
||
| 150 | * The pre-connection JITM is not displayed if the message array is missing a required key. In this test, the JITM is |
||
| 151 | * missing the message_path key. |
||
| 152 | */ |
||
| 153 | View Code Duplication | public function test_get_messages_missing_key() { |
|
| 165 | |||
| 166 | /** |
||
| 167 | * A pre-connection JITM is displayed if it has unexpected keys. |
||
| 168 | */ |
||
| 169 | public function test_get_messages_extra_key() { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Test the pre-connection JITM icon values. |
||
| 185 | * |
||
| 186 | * @param string|null $message_icon_value The message's icon value or null if it's doesn't have one. |
||
| 187 | * @param string $expected_icon The expected icon value input for the generate_icon method. |
||
| 188 | * |
||
| 189 | * @dataProvider data_provider_test_message_icon_values |
||
| 190 | */ |
||
| 191 | public function test_message_icon_values( $message_icon_value, $expected_icon ) { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Data provider for the test_message_icon_values method. |
||
| 214 | * |
||
| 215 | * @return array The test data. The structure of each test data element is: |
||
| 216 | * { test data name } => |
||
| 217 | * array( |
||
| 218 | * { the message's icon value, null if it doesn't have one }, |
||
| 219 | * { the expected icon value input for the generate_icon method }, |
||
| 220 | * ) |
||
| 221 | */ |
||
| 222 | public function data_provider_test_message_icon_values() { |
||
| 242 | |||
| 243 | private function set_user_cap_conditions() { |
||
| 248 | } |
||
| 249 |