Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX: use anonymous function over concrete classes #7553

Merged
merged 1 commit into from
Dec 12, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 39 additions & 4 deletions tests/Console/ConfigurationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use PhpCsFixer\Linter\LinterInterface;
use PhpCsFixer\Tests\TestCase;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\ToolInfo;
use PhpCsFixer\ToolInfoInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public function testResolveRulesWithConfigAndOption(): void

public function testResolveCommandLineInputOverridesDefault(): void
{
$command = new FixCommand(new ToolInfo());
$command = new FixCommand($this->createToolInfoDouble());
$definition = $command->getDefinition();
$arguments = $definition->getArguments();
self::assertCount(1, $arguments, 'Expected one argument, possibly test needs updating.');
Expand Down Expand Up @@ -1228,7 +1228,7 @@ public function testGetDirectory(?string $cacheFile, string $file, string $expec
$config->setCacheFile($cacheFile);
}

$resolver = new ConfigurationResolver($config, [], $this->normalizePath('/my/path'), new TestToolInfo());
$resolver = new ConfigurationResolver($config, [], $this->normalizePath('/my/path'), $this->createToolInfoDouble());
$directory = $resolver->getDirectory();

self::assertSame($expectedPathRelativeToFile, $directory->getRelativePathTo($file));
Expand Down Expand Up @@ -1269,7 +1269,7 @@ private function createConfigurationResolver(array $options, Config $config = nu
$config,
$options,
$cwdPath,
new TestToolInfo()
$this->createToolInfoDouble()
);
}

Expand Down Expand Up @@ -1306,4 +1306,39 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
}
};
}

private function createToolInfoDouble(): ToolInfoInterface
{
return new class() implements ToolInfoInterface {
public function getComposerInstallationDetails(): array
{
throw new \BadMethodCallException();
}

public function getComposerVersion(): string
{
throw new \BadMethodCallException();
}

public function getVersion(): string
{
throw new \BadMethodCallException();
}

public function isInstalledAsPhar(): bool
{
return true;
}

public function isInstalledByComposer(): bool
{
throw new \BadMethodCallException();
}

public function getPharDownloadUri(string $version): string
{
throw new \BadMethodCallException();
}
};
}
}
54 changes: 0 additions & 54 deletions tests/Console/TestToolInfo.php

This file was deleted.

23 changes: 0 additions & 23 deletions tests/Differ/DummyTestSplFileInfo.php

This file was deleted.

12 changes: 11 additions & 1 deletion tests/Differ/UnifiedDifferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testDiffAddsQuotes(): void
-a
+b
',
$differ->diff("a\n", "b\n", new DummyTestSplFileInfo('/foo/bar/test test test.txt'))
$differ->diff("a\n", "b\n", $this->createSplFileInfoDouble('/foo/bar/test test test.txt'))
);
}

Expand All @@ -74,4 +74,14 @@ public function testDiffWithoutFile(): void
$differ->diff('a', 'b')
);
}

private function createSplFileInfoDouble(string $filename): \SplFileInfo
{
return new class($filename) extends \SplFileInfo {
public function getRealPath(): string
{
return $this->getFilename();
}
};
}
}