Complex classes like PHPUnit_Stakx_TestCase often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PHPUnit_Stakx_TestCase, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
41 | abstract class PHPUnit_Stakx_TestCase extends \PHPUnit_Framework_TestCase |
||
42 | { |
||
43 | const FM_OBJ_TEMPLATE = "---\n%s\n---\n\n%s"; |
||
44 | |||
45 | /** @var string */ |
||
46 | protected $assetFolder; |
||
47 | /** @var vfsStreamFile */ |
||
48 | protected $dummyFile; |
||
49 | /** @var vfsStreamDirectory */ |
||
50 | protected $rootDir; |
||
51 | |||
52 | public function setUp() |
||
65 | |||
66 | public function tearDown() |
||
73 | |||
74 | /// |
||
75 | // Assertion Functions |
||
76 | /// |
||
77 | |||
78 | /** |
||
79 | * @param string $needle |
||
80 | * @param string $haystack |
||
81 | * @param string $message |
||
82 | */ |
||
83 | protected function assertStringContains($needle, $haystack, $message = '') |
||
87 | |||
88 | /** |
||
89 | * @param string $fileContent |
||
90 | * @param string $filePath |
||
91 | * @param string $message |
||
92 | */ |
||
93 | protected function assertFileContains($fileContent, $filePath, $message = '') |
||
101 | |||
102 | /// |
||
103 | // Filesystem Functions |
||
104 | /// |
||
105 | |||
106 | /** |
||
107 | * Create a temporary folder where temporary file writes will be made to. |
||
108 | * |
||
109 | * @param string $folderName |
||
110 | */ |
||
111 | protected function createAssetFolder($folderName) |
||
117 | |||
118 | /** |
||
119 | * Write a file to the asset folder. |
||
120 | * |
||
121 | * This file will be written to the actual filesystem and not the virtual filesystem. This file will be deleted at |
||
122 | * each tearDown(). |
||
123 | * |
||
124 | * @param string $fileName |
||
125 | * @param string $content |
||
126 | * |
||
127 | * @return string Path to the temporary file; relative to the project's root |
||
128 | */ |
||
129 | protected function createPhysicalFile($fileName, $content) |
||
136 | |||
137 | /** |
||
138 | * Write a file to the virtual filesystem. |
||
139 | * |
||
140 | * This file will be deleted at each tearDown(). |
||
141 | * |
||
142 | * @param string $filename |
||
143 | * @param string $content |
||
144 | * |
||
145 | * @return string the URL of the file on the virtual filesystem |
||
146 | */ |
||
147 | protected function createVirtualFile($filename, $content) |
||
157 | |||
158 | /** |
||
159 | * Create an object of a given type. |
||
160 | * |
||
161 | * This will create a virtual file and then create an object of the specified type for the created file. |
||
162 | * |
||
163 | * @param string $classType |
||
164 | * @param string $filename |
||
165 | * @param string $content |
||
166 | * |
||
167 | * @return object An instance of $classType |
||
168 | */ |
||
169 | protected function createDocumentOfType($classType, $filename, $content) |
||
175 | |||
176 | /** |
||
177 | * Create an object of a given type following the Front Matter format. |
||
178 | * |
||
179 | * @param string $classType |
||
180 | * @param string $filename |
||
181 | * @param array $frontMatter |
||
182 | * @param string $content |
||
183 | * |
||
184 | * @return object An instance of $classType |
||
185 | */ |
||
186 | protected function createFrontMatterDocumentOfType($classType, $filename = null, $frontMatter = [], $content = 'Body Text') |
||
197 | |||
198 | /** |
||
199 | * Create multiple virtual files from a given array of information. |
||
200 | * |
||
201 | * ```php |
||
202 | * $elements = [ |
||
203 | * [ |
||
204 | * 'filename' => '<string>', |
||
205 | * 'frontmatter' => [], |
||
206 | * 'body' => '<string>', |
||
207 | * ], |
||
208 | * ]; |
||
209 | * ``` |
||
210 | * |
||
211 | * @param string $classType |
||
212 | * @param array $elements |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | protected function createMultipleFrontMatterDocumentsOfType($classType, $elements) |
||
235 | |||
236 | /** |
||
237 | * Create a File object from a given path. |
||
238 | * |
||
239 | * @deprecated |
||
240 | * |
||
241 | * @param string $filePath |
||
242 | * |
||
243 | * @return File |
||
244 | */ |
||
245 | protected function createFileObjectFromPath($filePath) |
||
249 | |||
250 | /// |
||
251 | // Mock Objects |
||
252 | /// |
||
253 | |||
254 | /** |
||
255 | * @return AssetEngineManager|\PHPUnit_Framework_MockObject_MockBuilder |
||
256 | */ |
||
257 | protected function getMockAssetEngineManager() |
||
261 | |||
262 | /** |
||
263 | * @return AssetManager |
||
264 | */ |
||
265 | protected function getMockAssetManager() |
||
269 | |||
270 | /** |
||
271 | * @return Configuration|\PHPUnit_Framework_MockObject_MockObject |
||
272 | */ |
||
273 | protected function getMockConfiguration() |
||
285 | |||
286 | /** |
||
287 | * @return PageManager|\PHPUnit_Framework_MockObject_MockObject |
||
288 | */ |
||
289 | protected function getMockPageManager() |
||
300 | |||
301 | /** |
||
302 | * @return MenuManager|\PHPUnit_Framework_MockObject_MockObject |
||
303 | */ |
||
304 | protected function getMockMenuManager() |
||
315 | |||
316 | /** |
||
317 | * @return CollectionManager|\PHPUnit_Framework_MockObject_MockObject |
||
318 | */ |
||
319 | protected function getMockCollectionManager() |
||
330 | |||
331 | /** |
||
332 | * @return DataManager|\PHPUnit_Framework_MockObject_MockObject |
||
333 | */ |
||
334 | protected function getMockDataManager() |
||
345 | |||
346 | /** |
||
347 | * @return TwigExtension |
||
348 | */ |
||
349 | protected function getMockTwigExtension() |
||
355 | |||
356 | /** |
||
357 | * @return TwigStakxBridge |
||
358 | */ |
||
359 | protected function getMockTemplateBridge() |
||
367 | |||
368 | /** |
||
369 | * @return MarkupEngineManager |
||
370 | */ |
||
371 | protected function getMockMarkupEngineManager() |
||
385 | |||
386 | /** |
||
387 | * @return RedirectMapper|\PHPUnit_Framework_MockObject_MockObject |
||
388 | */ |
||
389 | protected function getMockRedirectMapper() |
||
399 | |||
400 | /** |
||
401 | * Get a mock EventDispatcher. |
||
402 | * |
||
403 | * @return EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject |
||
404 | */ |
||
405 | protected function getMockEventDistpatcher() |
||
409 | |||
410 | /** |
||
411 | * Get a mock logger. |
||
412 | * |
||
413 | * @return LoggerInterface|\PHPUnit_Framework_MockObject_MockObject |
||
414 | */ |
||
415 | protected function getMockLogger() |
||
419 | |||
420 | /** |
||
421 | * Get a real logger instance that will save output to the console. |
||
422 | * |
||
423 | * @return Logger |
||
424 | */ |
||
425 | protected function getReadableLogger() |
||
433 | |||
434 | /// |
||
435 | // Utility Functions |
||
436 | /// |
||
437 | |||
438 | /** |
||
439 | * Get the directory of the unit tests. |
||
440 | * |
||
441 | * @return string |
||
442 | */ |
||
443 | protected static function getTestRoot() |
||
447 | |||
448 | /** |
||
449 | * Generate a FrontMatter-ready syntax to be used as a file's content. |
||
450 | * |
||
451 | * @param array $frontMatter |
||
452 | * @param string $body |
||
453 | * |
||
454 | * @return string |
||
455 | */ |
||
456 | protected function buildFrontMatterTemplate(array $frontMatter = [], $body = 'Body text') |
||
462 | |||
463 | /** |
||
464 | * @param string $cls |
||
465 | * @param string $method |
||
466 | * @param array<string, mixed> $namedParams |
||
467 | * |
||
468 | * @throws \ReflectionException |
||
469 | * |
||
470 | * @return mixed |
||
471 | */ |
||
472 | protected function invokeClassFunctionWithNamedParams($cls, $method, $namedParams = []) |
||
509 | |||
510 | /// |
||
511 | // Misc Functions |
||
512 | /// |
||
513 | |||
514 | protected function bookCollectionProvider($jailed = false) |
||
532 | } |
||
533 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.