| Conditions | 5 |
| Paths | 6 |
| Total Lines | 56 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 27 | public function testRenderWillRetrieveCorrectRegions($pageTypeName, $pageClassName, $region = null, $contentItemClassName = null) |
||
| 28 | { |
||
| 29 | $this->markTestSkipped(); |
||
| 30 | |||
| 31 | |||
| 32 | if (null === $contentItemClassName || null === $region) { |
||
| 33 | $this->markTestSkipped("{$pageClassName} has no content item matrix"); |
||
| 34 | } elseif (!class_exists($contentItemClassName)) { |
||
| 35 | $this->fail("{$contentItemClassName} does not exist"); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** @var \Zicht\Bundle\PageBundle\Model\PageInterface $p */ |
||
| 39 | $realPage = new $pageClassName; |
||
| 40 | |||
| 41 | $recorded = array(); |
||
| 42 | |||
| 43 | $pageUnderTest = clone $realPage; |
||
| 44 | |||
| 45 | $contentItem = new $contentItemClassName; |
||
| 46 | $contentItem->setRegion($region); |
||
| 47 | $pageUnderTest->addContentItem($contentItem); |
||
| 48 | |||
| 49 | $mockPage = $this->getMock($pageClassName, array('getContentItems', 'getTemplateName')); |
||
| 50 | $mockPage |
||
| 51 | ->expects($this->atLeastOnce()) |
||
| 52 | ->method('getContentItems') |
||
| 53 | ->will( |
||
| 54 | $this->returnCallback( |
||
| 55 | function () use (&$recorded, $pageUnderTest, $region) { |
||
| 56 | $args = func_get_args(); |
||
| 57 | $recorded[]= $args; |
||
| 58 | $ret = call_user_func_array(array($pageUnderTest, 'getContentItems'), $args); |
||
| 59 | return $ret; |
||
| 60 | } |
||
| 61 | ) |
||
| 62 | ); |
||
| 63 | |||
| 64 | $mockPage->expects($this->any()) |
||
| 65 | ->method('getTemplateName') |
||
| 66 | ->will( |
||
| 67 | $this->returnCallback( |
||
| 68 | function () use ($pageUnderTest) { |
||
| 69 | return $pageUnderTest->getTemplateName(); |
||
| 70 | } |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | |||
| 74 | /** @var \Zicht\Bundle\PageBundle\Entity\ContentItem $item */ |
||
| 75 | $pageController = $this->createPageController(); |
||
| 76 | $pageController->renderPage($mockPage)->getContent(); |
||
| 77 | |||
| 78 | $called = array(); |
||
| 79 | foreach ($recorded as $calls) { |
||
| 80 | $called[]= $calls[0]; |
||
| 81 | } |
||
| 82 | $this->assertContains($region, $called); |
||
| 83 | } |
||
| 117 |