Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .dev-tools/src/Readme/ReadmeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
use PhpCsFixer\FixerDefinition\CodeSampleInterface;
use PhpCsFixer\StdinFileInfo;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Utils;
use PhpCsFixer\WhitespacesFixerConfig;
Expand Down Expand Up @@ -236,7 +235,7 @@ private function fixers(): string
$fixer->configure($codeSample->getConfiguration() ?? []);
}
$tokens = Tokens::fromCode($originalCode);
$fixer->fix(new StdinFileInfo(), $tokens);
$fixer->fix($this->createSplFileInfoDouble(), $tokens);
$fixedCode = $tokens->generateCode();

$output .= \sprintf(
Expand Down Expand Up @@ -268,6 +267,21 @@ private function diff(string $from, string $to): string
return \substr($diff, $start + 1, -1);
}

private function createSplFileInfoDouble(): \SplFileInfo
{
return new class (\getcwd() . '/file.php') extends \SplFileInfo {
public function __construct(string $filename)
{
parent::__construct($filename);
}

public function getRealPath(): string
{
return $this->getPathname();
}
};
}

private function contributing(): string
{
return \sprintf(
Expand Down
12 changes: 11 additions & 1 deletion tests/Fixer/AbstractFixerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ final protected function assertSuccessorName(string $successorName): void

private function createSplFileInfoDouble(): \SplFileInfo
{
return new class ('') extends \SplFileInfo {};
return new class (\getcwd() . '/src/file.php') extends \SplFileInfo {
public function __construct(string $filename)
{
parent::__construct($filename);
}

public function getRealPath(): string
{
return $this->getPathname();
}
};
}
}