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