Skip to content
Permalink
Browse files

Merge pull request #151 from kubawerlos/fix-testing-with-tokens-cache

Fix testing with Tokens cache
  • Loading branch information...
kubawerlos committed Oct 11, 2019
2 parents 7e23e23 + 3505217 commit 3a4ce0006e71a490e8e113f332502a848b08da24
@@ -40,14 +40,21 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
continue;
}
$newContent = Preg::replace('/^(\/\/|#|\/\*+)((?!(?:\/|\*|\h)).+)$/', '$1 $2', $token->getContent());
$newContent = Preg::replace('/^(.+(?<!(?:\/|\*|\h)))(\*+\/)$/', '$1 $2', $newContent);
/** @var string $newContent */
$newContent = Preg::replace(
[
'/^(\/\/|#|\/\*+)((?!(?:\/|\*|\h)).+)$/',
'/^(.+(?<!(?:\/|\*|\h)))(\*+\/)$/',
],
'$1 $2',
$token->getContent()
);
if ($newContent === $token->getContent()) {
continue;
}
$tokens[$index] = new Token([$token->getId(), $newContent]);
$tokens[$index] = new Token([\strpos($newContent, '/** ') === 0 ? T_DOC_COMMENT : T_COMMENT, $newContent]);
}
}
No changes.
@@ -76,6 +76,7 @@ abstract class AbstractFixerTestCase extends TestCase
$this->fixer->configure($codeSample->getConfiguration());
}
Tokens::clearCache();
$tokens = Tokens::fromCode($codeSample->getCode());
$this->fixer->fix($this->createMock(\SplFileInfo::class), $tokens);
@@ -96,6 +97,7 @@ abstract class AbstractFixerTestCase extends TestCase
if ($input !== null) {
static::assertNull($linter->lintSource($input)->check());
Tokens::clearCache();
$tokens = Tokens::fromCode($input);
static::assertTrue($this->fixer->isCandidate($tokens));
@@ -105,9 +107,12 @@ abstract class AbstractFixerTestCase extends TestCase
$tokens->clearEmptyTokens();
static::assertSame($expected, $tokens->generateCode());
Tokens::clearCache();
static::assertTokens(Tokens::fromCode($expected), $tokens);
}
Tokens::clearCache();
$tokens = Tokens::fromCode($expected);
$this->fixer->fix($this->createMock(\SplFileInfo::class), $tokens);
@@ -26,6 +26,7 @@ final class TokenRemoverTest extends TestCase
*/
public function testFix(string $expected, ?string $input = null): void
{
Tokens::clearCache();
$tokens = Tokens::fromCode($input);
foreach ($tokens as $index => $token) {
@@ -37,6 +38,7 @@ public function testFix(string $expected, ?string $input = null): void
$tokens->clearEmptyTokens();
Tokens::clearCache();
static::assertTokens(Tokens::fromCode($expected), $tokens);
}

0 comments on commit 3a4ce00

Please sign in to comment.
You can’t perform that action at this time.