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 |
||
16 | class WP_Test_Integration_Manifest extends TestCase { |
||
17 | |||
18 | /** |
||
19 | * The path to the test manifest we want to operate on. |
||
20 | */ |
||
21 | const TEST_MANIFEST_PATH = TEST_DATA_PATH . '/plugins/plugin_current/test-manifest.php'; |
||
22 | |||
23 | /** |
||
24 | * The manifest handler we're testing. |
||
25 | * |
||
26 | * @var Manifest_Handler |
||
27 | */ |
||
28 | private $manifest_handler; |
||
29 | |||
30 | /** |
||
31 | * Setup runs before each test. |
||
32 | * |
||
33 | * @before |
||
34 | */ |
||
35 | public function set_up() { |
||
36 | $this->manifest_handler = new Manifest_Handler( |
||
37 | array( |
||
38 | TEST_DATA_PATH . '/plugins/plugin_current', |
||
39 | ), |
||
40 | new Version_Selector() |
||
41 | ); |
||
42 | |||
43 | // Make sure the test manifest does not exist. |
||
44 | if ( file_exists( self::TEST_MANIFEST_PATH ) ) { |
||
45 | unlink( self::TEST_MANIFEST_PATH ); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Teardown runs after each test. |
||
51 | * |
||
52 | * @after |
||
53 | */ |
||
54 | public function tear_down() { |
||
55 | // Make sure the test manifest does not exist. |
||
56 | if ( file_exists( self::TEST_MANIFEST_PATH ) ) { |
||
57 | unlink( self::TEST_MANIFEST_PATH ); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Tests that the classmap manifest we generate can be read by the handler. |
||
63 | */ |
||
64 | View Code Duplication | public function test_that_handler_reads_classmap_manifests() { |
|
88 | |||
89 | /** |
||
90 | * Tests that the PSR-4 manifest we generate can be read by the handler. |
||
91 | */ |
||
92 | View Code Duplication | public function test_that_handler_reads_psr4_manifests() { |
|
116 | |||
117 | /** |
||
118 | * Tests that the files manifest we generate can be read by the handler. |
||
119 | */ |
||
120 | View Code Duplication | public function test_that_handler_reads_files_manifests() { |
|
144 | |||
145 | /** |
||
146 | * Writes the test manifest for the tests to use. |
||
147 | * |
||
148 | * @param string $autoload_type The type of manifest to generate. |
||
149 | * @param array $content The content to write a manifest using. |
||
150 | */ |
||
151 | private function write_test_manifest( $autoload_type, $content ) { |
||
157 | } |
||
158 |