|
@@ -12,15 +12,14 @@
|
|
|
|
|
|
namespace PhpCsFixer\Fixer\PhpUnit;
|
|
|
|
|
|
-use PhpCsFixer\AbstractFixer;
|
|
|
use PhpCsFixer\DocBlock\DocBlock;
|
|
|
use PhpCsFixer\DocBlock\Line;
|
|
|
+use PhpCsFixer\Fixer\AbstractPhpUnitFixer;
|
|
|
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
|
|
|
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
|
|
|
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
|
|
|
use PhpCsFixer\FixerDefinition\CodeSample;
|
|
|
use PhpCsFixer\FixerDefinition\FixerDefinition;
|
|
|
-use PhpCsFixer\Indicator\PhpUnitTestCaseIndicator;
|
|
|
use PhpCsFixer\Preg;
|
|
|
use PhpCsFixer\Tokenizer\Token;
|
|
|
use PhpCsFixer\Tokenizer\Tokens;
|
|
@@ -30,7 +29,7 @@ use PhpCsFixer\Utils;
|
|
|
/**
|
|
|
* @author Filippo Tessarotto <zoeslam@gmail.com>
|
|
|
*/
|
|
|
-final class PhpUnitMethodCasingFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
|
|
|
+final class PhpUnitMethodCasingFixer extends AbstractPhpUnitFixer implements ConfigurationDefinitionFixerInterface
|
|
|
{
|
|
|
/**
|
|
|
* @internal
|
|
@@ -81,25 +80,6 @@ class MyTest extends \\PhpUnit\\FrameWork\\TestCase
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * {@inheritdoc}
|
|
|
- */
|
|
|
- public function isCandidate(Tokens $tokens)
|
|
|
- {
|
|
|
- return $tokens->isAllTokenKindsFound([T_CLASS, T_FUNCTION]);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * {@inheritdoc}
|
|
|
- */
|
|
|
- protected function applyFix(\SplFileInfo $file, Tokens $tokens)
|
|
|
- {
|
|
|
- $phpUnitTestCaseIndicator = new PhpUnitTestCaseIndicator();
|
|
|
- foreach ($phpUnitTestCaseIndicator->findPhpUnitClasses($tokens) as $indexes) {
|
|
|
- $this->applyCasing($tokens, $indexes[0], $indexes[1]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
@@ -114,10 +94,9 @@ class MyTest extends \\PhpUnit\\FrameWork\\TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param int $startIndex
|
|
|
- * @param int $endIndex
|
|
|
+ * {@inheritdoc}
|
|
|
*/
|
|
|
- private function applyCasing(Tokens $tokens, $startIndex, $endIndex)
|
|
|
+ protected function applyPhpUnitClassFix(Tokens $tokens, $startIndex, $endIndex)
|
|
|
{
|
|
|
for ($index = $endIndex - 1; $index > $startIndex; --$index) {
|
|
|
if (!$this->isTestMethod($tokens, $index)) {
|
|
@@ -133,7 +112,8 @@ class MyTest extends \\PhpUnit\\FrameWork\\TestCase
|
|
|
}
|
|
|
|
|
|
$docBlockIndex = $this->getDocBlockIndex($tokens, $index);
|
|
|
- if ($this->hasDocBlock($tokens, $index)) {
|
|
|
+
|
|
|
+ if ($this->isPHPDoc($tokens, $docBlockIndex)) {
|
|
|
$this->updateDocBlock($tokens, $docBlockIndex);
|
|
|
}
|
|
|
}
|
|
@@ -177,18 +157,13 @@ class MyTest extends \\PhpUnit\\FrameWork\\TestCase
|
|
|
if ($this->startsWith('test', $functionName)) {
|
|
|
return true;
|
|
|
}
|
|
|
- // If the function doesn't have test in its name, and no doc block, it's not a test
|
|
|
- if (!$this->hasDocBlock($tokens, $index)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
$docBlockIndex = $this->getDocBlockIndex($tokens, $index);
|
|
|
- $doc = $tokens[$docBlockIndex]->getContent();
|
|
|
- if (false === strpos($doc, '@test')) {
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
- return true;
|
|
|
+ return
|
|
|
+ $this->isPHPDoc($tokens, $docBlockIndex) // If the function doesn't have test in its name, and no doc block, it's not a test
|
|
|
+ && false !== strpos($tokens[$docBlockIndex]->getContent(), '@test')
|
|
|
+ ;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -214,32 +189,6 @@ class MyTest extends \\PhpUnit\\FrameWork\\TestCase
|
|
|
return substr($haystack, 0, \strlen($needle)) === $needle;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param int $index
|
|
|
- *
|
|
|
- * @return bool
|
|
|
- */
|
|
|
- private function hasDocBlock(Tokens $tokens, $index)
|
|
|
- {
|
|
|
- $docBlockIndex = $this->getDocBlockIndex($tokens, $index);
|
|
|
-
|
|
|
- return $tokens[$docBlockIndex]->isGivenKind(T_DOC_COMMENT);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param int $index
|
|
|
- *
|
|
|
- * @return int
|
|
|
- */
|
|
|
- private function getDocBlockIndex(Tokens $tokens, $index)
|
|
|
- {
|
|
|
- do {
|
|
|
- $index = $tokens->getPrevNonWhitespace($index);
|
|
|
- } while ($tokens[$index]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_COMMENT]));
|
|
|
-
|
|
|
- return $index;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @param int $docBlockIndex
|
|
|
*/
|