|
18 | 18 | use PhpCsFixer\Fixer\DeprecatedFixerInterface; |
19 | 19 | use PhpCsFixer\Fixer\FixerInterface; |
20 | 20 | use PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer; |
| 21 | +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; |
| 22 | +use PhpCsFixer\FixerConfiguration\FixerOptionInterface; |
21 | 23 | use PhpCsFixer\FixerDefinition\CodeSampleInterface; |
22 | 24 | use PhpCsFixer\FixerDefinition\FileSpecificCodeSampleInterface; |
23 | 25 | use PhpCsFixer\FixerDefinition\VersionSpecificCodeSampleInterface; |
@@ -52,16 +54,13 @@ final class FixerTest extends TestCase |
52 | 54 | */ |
53 | 55 | public function testFixerDefinitions(AbstractFixer $fixer) |
54 | 56 | { |
55 | | - static::assertInstanceOf(\PhpCsFixer\Fixer\DefinedFixerInterface::class, $fixer); |
| 57 | + static::assertInstanceOf(DefinedFixerInterface::class, $fixer); |
56 | 58 |
|
57 | 59 | $fixerName = $fixer->getName(); |
58 | 60 | $definition = $fixer->getDefinition(); |
59 | 61 | $fixerIsConfigurable = $fixer instanceof ConfigurationDefinitionFixerInterface; |
60 | 62 |
|
61 | | - static::assertRegExp('/^[A-Z`].*\.$/', $definition->getSummary(), sprintf('[%s] Description must start with capital letter or a ` and end with dot.', $fixerName)); |
62 | | - static::assertNotContains('phpdocs', $definition->getSummary(), sprintf('[%s] `PHPDoc` must not be in the plural in description.', $fixerName), true); |
63 | | - static::assertCorrectCasing($definition->getSummary(), 'PHPDoc', sprintf('[%s] `PHPDoc` must be in correct casing in description.', $fixerName)); |
64 | | - static::assertCorrectCasing($definition->getSummary(), 'PHPUnit', sprintf('[%s] `PHPUnit` must be in correct casing in description.', $fixerName)); |
| 63 | + self::assertValidDescription($fixerName, 'summary', $definition->getSummary()); |
65 | 64 |
|
66 | 65 | $samples = $definition->getCodeSamples(); |
67 | 66 | static::assertNotEmpty($samples, sprintf('[%s] Code samples are required.', $fixerName)); |
@@ -169,10 +168,7 @@ public function testFixerDefinitions(AbstractFixer $fixer) |
169 | 168 | } |
170 | 169 |
|
171 | 170 | if ($fixer->isRisky()) { |
172 | | - static::assertStringIsNotEmpty($definition->getRiskyDescription(), sprintf('[%s] Risky reasoning is required.', $fixerName)); |
173 | | - static::assertNotContains('phpdocs', $definition->getRiskyDescription(), sprintf('[%s] `PHPDoc` must not be in the plural in risky reasoning.', $fixerName), true); |
174 | | - static::assertCorrectCasing($definition->getRiskyDescription(), 'PHPDoc', sprintf('[%s] `PHPDoc` must be in correct casing in risky reasoning.', $fixerName)); |
175 | | - static::assertCorrectCasing($definition->getRiskyDescription(), 'PHPUnit', sprintf('[%s] `PHPUnit` must be in correct casing in risky reasoning.', $fixerName)); |
| 171 | + self::assertValidDescription($fixerName, 'risky description', $definition->getRiskyDescription()); |
176 | 172 | } else { |
177 | 173 | static::assertNull($definition->getRiskyDescription(), sprintf('[%s] Fixer is not risky so no description of it expected.', $fixerName)); |
178 | 174 | } |
@@ -210,7 +206,7 @@ public function testFixersAreFinal(FixerInterface $fixer) |
210 | 206 | */ |
211 | 207 | public function testFixersAreDefined(FixerInterface $fixer) |
212 | 208 | { |
213 | | - static::assertInstanceOf(\PhpCsFixer\Fixer\DefinedFixerInterface::class, $fixer); |
| 209 | + static::assertInstanceOf(DefinedFixerInterface::class, $fixer); |
214 | 210 | } |
215 | 211 |
|
216 | 212 | /** |
@@ -248,10 +244,10 @@ public function testFixerConfigurationDefinitions(ConfigurationDefinitionFixerIn |
248 | 244 | { |
249 | 245 | $configurationDefinition = $fixer->getConfigurationDefinition(); |
250 | 246 |
|
251 | | - static::assertInstanceOf(\PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface::class, $configurationDefinition); |
| 247 | + static::assertInstanceOf(FixerConfigurationResolverInterface::class, $configurationDefinition); |
252 | 248 |
|
253 | 249 | foreach ($configurationDefinition->getOptions() as $option) { |
254 | | - static::assertInstanceOf(\PhpCsFixer\FixerConfiguration\FixerOptionInterface::class, $option); |
| 250 | + static::assertInstanceOf(FixerOptionInterface::class, $option); |
255 | 251 | static::assertNotEmpty($option->getDescription()); |
256 | 252 |
|
257 | 253 | static::assertSame( |
@@ -339,4 +335,19 @@ private static function assertCorrectCasing($needle, $haystack, $message) |
339 | 335 | { |
340 | 336 | static::assertSame(substr_count(strtolower($haystack), strtolower($needle)), substr_count($haystack, $needle), $message); |
341 | 337 | } |
| 338 | + |
| 339 | + /** |
| 340 | + * @param string $fixerName |
| 341 | + * @param string $descriptionType |
| 342 | + * @param mixed $description |
| 343 | + */ |
| 344 | + private static function assertValidDescription($fixerName, $descriptionType, $description) |
| 345 | + { |
| 346 | + static::assertInternalType('string', $description); |
| 347 | + static::assertRegExp('/^[A-Z`][^"]+\.$/', $description, sprintf('[%s] The %s must start with capital letter or a ` and end with dot.', $fixerName, $descriptionType)); |
| 348 | + static::assertNotContains('phpdocs', $description, sprintf('[%s] `PHPDoc` must not be in the plural in %s.', $fixerName, $descriptionType), true); |
| 349 | + static::assertCorrectCasing($description, 'PHPDoc', sprintf('[%s] `PHPDoc` must be in correct casing in %s.', $fixerName, $descriptionType)); |
| 350 | + static::assertCorrectCasing($description, 'PHPUnit', sprintf('[%s] `PHPUnit` must be in correct casing in %s.', $fixerName, $descriptionType)); |
| 351 | + static::assertFalse(strpos($descriptionType, '``'), sprintf('[%s] The %s must no contain sequential backticks.', $fixerName, $descriptionType)); |
| 352 | + } |
342 | 353 | } |
0 commit comments