| Conditions | 1 |
| Paths | 1 |
| Total Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 65 | public function testShouldReturnErrorIfThereIsFilesWithWrongStyle() |
||
| 66 | { |
||
| 67 | /* @var \Behat\Gherkin\Parser|\PHPUnit_Framework_MockObject_MockObject $parser */ |
||
| 68 | $parser = $this->getMockBuilder(Parser::class) |
||
| 69 | ->disableOriginalConstructor() |
||
| 70 | ->getMock(); |
||
| 71 | |||
| 72 | /* @var \Behat\Gherkin\Node\FeatureNode|\PHPUnit_Framework_MockObject_MockObject $feature */ |
||
| 73 | $feature = $this->getMockBuilder(FeatureNode::class) |
||
| 74 | ->disableOriginalConstructor() |
||
| 75 | ->getMock(); |
||
| 76 | |||
| 77 | $feature->expects(self::once()) |
||
| 78 | ->method('hasTags') |
||
| 79 | ->willReturn(true); |
||
| 80 | |||
| 81 | $feature->expects(self::once()) |
||
| 82 | ->method('getKeyword') |
||
| 83 | ->willReturn('Feature'); |
||
| 84 | |||
| 85 | $feature->expects(self::once()) |
||
| 86 | ->method('getTags') |
||
| 87 | ->willReturn( |
||
| 88 | ['users', 'another-feature', 'another-tag'] |
||
| 89 | ); |
||
| 90 | |||
| 91 | $feature->expects(self::once()) |
||
| 92 | ->method('getTitle') |
||
| 93 | ->willReturn( |
||
| 94 | 'User registration' |
||
| 95 | ); |
||
| 96 | |||
| 97 | $feature->expects(self::once()) |
||
| 98 | ->method('hasDescription') |
||
| 99 | ->willReturn(true); |
||
| 100 | |||
| 101 | $feature->expects(self::once()) |
||
| 102 | ->method('getDescription') |
||
| 103 | ->willReturn( |
||
| 104 | "In order to order products\n" . |
||
| 105 | "As a visitor\n" . |
||
| 106 | "I need to be able to create an account in the store" |
||
| 107 | ); |
||
| 108 | |||
| 109 | $feature->expects(self::once()) |
||
| 110 | ->method('hasBackground') |
||
| 111 | ->willReturn(true); |
||
| 112 | |||
| 113 | $feature->expects(self::once()) |
||
| 114 | ->method('getBackground') |
||
| 115 | ->willReturn($this->getBackground()); |
||
| 116 | |||
| 117 | $feature->expects(self::once()) |
||
| 118 | ->method('hasScenarios') |
||
| 119 | ->willReturn(false); |
||
| 120 | |||
| 121 | $parser->expects(self::once()) |
||
| 122 | ->method('parse') |
||
| 123 | ->willReturn($feature); |
||
| 124 | |||
| 125 | $application = new Application('test'); |
||
| 126 | $application->add(new CheckGherkinCodeStyle(null, $parser)); |
||
| 127 | |||
| 128 | $command = $application->find('gherkin:check'); |
||
| 129 | $commandTester = new CommandTester($command); |
||
| 130 | $commandTester->execute( |
||
| 131 | [ |
||
| 132 | 'directory' => __DIR__ . '/../assets/left-aligned.feature', |
||
| 133 | ] |
||
| 134 | ); |
||
| 135 | |||
| 136 | self::assertRegExp('/Wrong style/', $commandTester->getDisplay()); |
||
| 137 | self::assertNotRegExp('/I need to be able to create an account in the store/', $commandTester->getDisplay()); |
||
| 138 | } |
||
| 139 | |||
| 168 |