|
@@ -13,6 +13,7 @@
|
|
|
namespace PhpCsFixer\Tests\Test;
|
|
|
|
|
|
use PhpCsFixer\AbstractFixer;
|
|
|
+use PhpCsFixer\AbstractProxyFixer;
|
|
|
use PhpCsFixer\Linter\CachingLinter;
|
|
|
use PhpCsFixer\Linter\Linter;
|
|
|
use PhpCsFixer\Linter\LinterInterface;
|
|
@@ -66,6 +67,29 @@ abstract class AbstractFixerTestCase extends TestCase
|
|
|
Tokens::setLegacyMode(false);
|
|
|
}
|
|
|
|
|
|
+ final public function testIsRisky()
|
|
|
+ {
|
|
|
+ static::assertInternalType('bool', $this->fixer->isRisky(), sprintf('Return type for ::isRisky of "%s" is invalid.', $this->fixer->getName()));
|
|
|
+
|
|
|
+ if ($this->fixer->isRisky()) {
|
|
|
+ self::assertValidDescription($this->fixer->getName(), 'risky description', $this->fixer->getDefinition()->getRiskyDescription());
|
|
|
+ } else {
|
|
|
+ static::assertNull($this->fixer->getDefinition()->getRiskyDescription(), sprintf('[%s] Fixer is not risky so no description of it expected.', $this->fixer->getName()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->fixer instanceof AbstractProxyFixer) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $reflection = new \ReflectionMethod($this->fixer, 'isRisky');
|
|
|
+
|
|
|
+ // If fixer is not risky then the method `isRisky` from `AbstractFixer` must be used
|
|
|
+ static::assertSame(
|
|
|
+ !$this->fixer->isRisky(),
|
|
|
+ AbstractFixer::class === $reflection->getDeclaringClass()->getName()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return AbstractFixer
|
|
|
*/
|
|
@@ -207,4 +231,29 @@ abstract class AbstractFixerTestCase extends TestCase
|
|
|
|
|
|
return $linter;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $fixerName
|
|
|
+ * @param string $descriptionType
|
|
|
+ * @param mixed $description
|
|
|
+ */
|
|
|
+ private static function assertValidDescription($fixerName, $descriptionType, $description)
|
|
|
+ {
|
|
|
+ static::assertInternalType('string', $description);
|
|
|
+ static::assertRegExp('/^[A-Z`][^"]+\.$/', $description, sprintf('[%s] The %s must start with capital letter or a ` and end with dot.', $fixerName, $descriptionType));
|
|
|
+ static::assertNotContains('phpdocs', $description, sprintf('[%s] `PHPDoc` must not be in the plural in %s.', $fixerName, $descriptionType), true);
|
|
|
+ static::assertCorrectCasing($description, 'PHPDoc', sprintf('[%s] `PHPDoc` must be in correct casing in %s.', $fixerName, $descriptionType));
|
|
|
+ static::assertCorrectCasing($description, 'PHPUnit', sprintf('[%s] `PHPUnit` must be in correct casing in %s.', $fixerName, $descriptionType));
|
|
|
+ static::assertFalse(strpos($descriptionType, '``'), sprintf('[%s] The %s must no contain sequential backticks.', $fixerName, $descriptionType));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $needle
|
|
|
+ * @param string $haystack
|
|
|
+ * @param string $message
|
|
|
+ */
|
|
|
+ private static function assertCorrectCasing($needle, $haystack, $message)
|
|
|
+ {
|
|
|
+ static::assertSame(substr_count(strtolower($haystack), strtolower($needle)), substr_count($haystack, $needle), $message);
|
|
|
+ }
|
|
|
}
|