Complex classes like TestBase 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 TestBase, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class TestBase extends WebTestCase |
||
28 | { |
||
29 | /** |
||
30 | * |
||
31 | * @var \Doctrine\ORM\EntityManager |
||
32 | */ |
||
33 | protected $em; |
||
34 | |||
35 | /** |
||
36 | * |
||
37 | * @var $container |
||
38 | */ |
||
39 | private $container; |
||
40 | |||
41 | /** |
||
42 | * |
||
43 | * @access public |
||
44 | */ |
||
45 | public function setUp() |
||
57 | |||
58 | /* |
||
59 | * |
||
60 | * Close doctrine connections to avoid having a 'too many connections' |
||
61 | * message when running many tests |
||
62 | */ |
||
63 | public function tearDown(){ |
||
68 | |||
69 | protected function purge() |
||
75 | |||
76 | protected function addNewUser($username, $email, $password, $persist = true, $andFlush = true) |
||
93 | |||
94 | protected function addFixturesForUsers() |
||
106 | |||
107 | protected function addNewForum($forumName, $persist = true, $andFlush = true) |
||
122 | |||
123 | protected function addFixturesForForums() |
||
135 | |||
136 | protected function addNewCategory($categoryName, $order, Forum $forum = null, $persist = true, $andFlush = true) |
||
153 | |||
154 | protected function addFixturesForCategories($forums) |
||
168 | |||
169 | protected function addNewBoard($boardName, $boardDescription, $order, Category $category = null, $persist = true, $andFlush = true) |
||
187 | |||
188 | protected function addFixturesForBoards($categories) |
||
202 | |||
203 | protected function addNewTopic($title, Board $board = null, $persist = true, $andFlush = true) |
||
219 | |||
220 | protected function addFixturesForTopics($boards) |
||
234 | |||
235 | protected function addNewPost($body, $topic, $user, \Datetime $createdDate = null, $persist = true, $andFlush = true) |
||
262 | |||
263 | protected function addFixturesForPosts($topics, $user) |
||
285 | |||
286 | protected function addNewSubscription($forum, $topic, $user, $isRead = false, $persist = true, $andFlush = true) |
||
305 | |||
306 | protected function addFixturesForSubscriptions($forum, $topics, $user, $isRead = false) |
||
317 | |||
318 | /** |
||
319 | * |
||
320 | * @var \CCDNForum\ForumBundle\Model\FrontModel\ForumModel $forumModel |
||
321 | */ |
||
322 | private $forumModel; |
||
323 | |||
324 | /** |
||
325 | * |
||
326 | * @var \CCDNForum\ForumBundle\Model\FrontModel\CategoryModel $categoryModel |
||
327 | */ |
||
328 | private $categoryModel; |
||
329 | |||
330 | /** |
||
331 | * |
||
332 | * @var \CCDNForum\ForumBundle\Model\FrontModel\BoardModel $boardModel |
||
333 | */ |
||
334 | private $boardModel; |
||
335 | |||
336 | /** |
||
337 | * |
||
338 | * @var \CCDNForum\ForumBundle\Model\FrontModel\TopicModel $topicModel |
||
339 | */ |
||
340 | private $topicModel; |
||
341 | |||
342 | /** |
||
343 | * |
||
344 | * @var \CCDNForum\ForumBundle\Model\FrontModel\PostModel $postModel |
||
345 | */ |
||
346 | private $postModel; |
||
347 | |||
348 | /** |
||
349 | * |
||
350 | * @var \CCDNForum\ForumBundle\Model\FrontModel\RegistryModel $registryModel |
||
351 | */ |
||
352 | private $registryModel; |
||
353 | |||
354 | /** |
||
355 | * |
||
356 | * @var \CCDNForum\ForumBundle\Model\FrontModel\SubscriptionModel $subscriptionModel |
||
357 | */ |
||
358 | private $subscriptionModel; |
||
359 | |||
360 | /** |
||
361 | * |
||
362 | * @access protected |
||
363 | * @return \CCDNForum\ForumBundle\Model\FrontModel\ForumModel |
||
364 | */ |
||
365 | protected function getForumModel() |
||
373 | |||
374 | /** |
||
375 | * |
||
376 | * @access protected |
||
377 | * @return \CCDNForum\ForumBundle\Model\FrontModel\CategoryModel |
||
378 | */ |
||
379 | protected function getCategoryModel() |
||
387 | |||
388 | /** |
||
389 | * |
||
390 | * @access protected |
||
391 | * @return \CCDNForum\ForumBundle\Model\FrontModel\BoardModel |
||
392 | */ |
||
393 | protected function getBoardModel() |
||
401 | |||
402 | /** |
||
403 | * |
||
404 | * @access protected |
||
405 | * @return \CCDNForum\ForumBundle\Model\FrontModel\TopicModel |
||
406 | */ |
||
407 | protected function getTopicModel() |
||
415 | |||
416 | /** |
||
417 | * |
||
418 | * @access protected |
||
419 | * @return \CCDNForum\ForumBundle\Model\FrontModel\PostModel |
||
420 | */ |
||
421 | protected function getPostModel() |
||
429 | |||
430 | /** |
||
431 | * |
||
432 | * @access protected |
||
433 | * @return \CCDNForum\ForumBundle\Model\FrontModel\RegistryModel |
||
434 | */ |
||
435 | protected function getRegistryModel() |
||
443 | |||
444 | /** |
||
445 | * |
||
446 | * @access protected |
||
447 | * @return \CCDNForum\ForumBundle\Model\FrontModel\SubscriptionModel |
||
448 | */ |
||
449 | protected function getSubscriptionModel() |
||
457 | } |
||
458 |