diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 536b4744..6dbce83c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,5 +10,19 @@ 'fopen_flags' => false, 'protected_to_private' => false, ]) + ->setRuleCustomisationPolicy(new class implements PhpCsFixer\Config\RuleCustomisationPolicyInterface { + public function getPolicyVersionForCache(): string + { + return hash_file('xxh128', __FILE__); + } + + public function getRuleCustomisers(): array + { + return [ + // test methods must not have a return type + 'void_return' => static fn (SplFileInfo $file) => !str_starts_with($file->getPathname(), __DIR__.'/tests/'), + ]; + } + }) ->setRiskyAllowed(true) ; diff --git a/tests/Configurator/CopyFromPackageConfiguratorTest.php b/tests/Configurator/CopyFromPackageConfiguratorTest.php index 71fccb36..7756ab1d 100644 --- a/tests/Configurator/CopyFromPackageConfiguratorTest.php +++ b/tests/Configurator/CopyFromPackageConfiguratorTest.php @@ -57,9 +57,9 @@ public function testConfigureAndOverwriteFiles() $lock = $this->createStub(Lock::class); $ioCalls = []; - $io = $this->createStub(IOInterface::class); + $io = $this->createMock(IOInterface::class); $io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); - $io->method('askConfirmation')->with('File "build/public/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true); + $io->expects($this->once())->method('askConfirmation')->with('File "build/public/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true); $this->assertFileExists($this->targetFile); $this->createConfigurator($io)->configure( diff --git a/tests/Configurator/CopyFromRecipeConfiguratorTest.php b/tests/Configurator/CopyFromRecipeConfiguratorTest.php index c7d6b72f..ca63e5d8 100644 --- a/tests/Configurator/CopyFromRecipeConfiguratorTest.php +++ b/tests/Configurator/CopyFromRecipeConfiguratorTest.php @@ -68,9 +68,9 @@ public function testConfigureAndOverwriteFiles() $lock = $this->createStub(Lock::class); $ioCalls = []; - $io = $this->createStub(IOInterface::class); + $io = $this->createMock(IOInterface::class); $io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); - $io->method('askConfirmation')->with('File "build/config/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true); + $io->expects($this->once())->method('askConfirmation')->with('File "build/config/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true); $this->assertFileExists($this->targetFile); $this->createConfigurator($io)->configure( diff --git a/tests/Configurator/DockerComposeConfiguratorTest.php b/tests/Configurator/DockerComposeConfiguratorTest.php index efaa9f32..6c5e582a 100644 --- a/tests/Configurator/DockerComposeConfiguratorTest.php +++ b/tests/Configurator/DockerComposeConfiguratorTest.php @@ -213,7 +213,7 @@ public function testReconfigureDoesNotDuplicateLaterTopLevelKey() { $this->configurator->configure($this->recipeDb, self::CONFIG_DB, $this->lock); - $servicesOnlyRecipe = $this->getMockBuilder(Recipe::class)->disableOriginalConstructor()->getMock(); + $servicesOnlyRecipe = $this->createStub(Recipe::class); $servicesOnlyRecipe->method('getName')->willReturn('acme/services-only'); $servicesOnlyConfig = [ 'services' => [ diff --git a/tests/Configurator/MakefileConfiguratorTest.php b/tests/Configurator/MakefileConfiguratorTest.php index 5ac46df9..5ba2c642 100644 --- a/tests/Configurator/MakefileConfiguratorTest.php +++ b/tests/Configurator/MakefileConfiguratorTest.php @@ -235,14 +235,14 @@ public function testUpdate() public function testConfigureCreatesBoilerplateWithTabIndentation() { $configurator = new MakefileConfigurator( - $this->getMockBuilder(Composer::class)->getMock(), - $this->getMockBuilder(IOInterface::class)->getMock(), + $this->createStub(Composer::class), + $this->createStub(IOInterface::class), new Options(['root-dir' => FLEX_TEST_DIR]) ); - $lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock(); + $lock = $this->createStub(Lock::class); - $recipe = $this->getMockBuilder(Recipe::class)->disableOriginalConstructor()->getMock(); - $recipe->expects($this->any())->method('getName')->willReturn('FooBundle'); + $recipe = $this->createStub(Recipe::class); + $recipe->method('getName')->willReturn('FooBundle'); $makefile = FLEX_TEST_DIR.'/Makefile'; @unlink($makefile); diff --git a/tests/FlexTest.php b/tests/FlexTest.php index ef82da5b..2f870e24 100644 --- a/tests/FlexTest.php +++ b/tests/FlexTest.php @@ -45,11 +45,6 @@ class FlexTest extends TestCase { - protected function tearDown(): void - { - @unlink(__DIR__.'/Fixtures/symfony.lock'); - } - public function testPostInstall() { $data = [ @@ -165,7 +160,7 @@ public function testContribRecipeNotApprovedIsRemovedFromLock() // Recipe should NOT be installed $configurator->expects($this->never())->method('install'); - $lock = new Lock(__DIR__.'/Fixtures/symfony.lock'); + $lock = new Lock('php://memory'); $composer = $this->mockComposer($this->mockLocker(), $rootPackage); $flex = $this->mockFlexCustom($io, $composer, $configurator, $downloader, $lock); diff --git a/tests/ScriptExecutorTest.php b/tests/ScriptExecutorTest.php index fcca2f30..524ec779 100644 --- a/tests/ScriptExecutorTest.php +++ b/tests/ScriptExecutorTest.php @@ -16,7 +16,6 @@ use Composer\Util\ProcessExecutor; use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\TestCase; -use PHPUnit\Runner\Version; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Flex\Options; use Symfony\Flex\ScriptExecutor; @@ -29,8 +28,8 @@ public function testMemoryLimit() $command = './command.php'; $memoryLimit = '32M'; putenv("COMPOSER_MEMORY_LIMIT={$memoryLimit}"); - $executorStub = $this->createStub(ProcessExecutor::class); - $scriptExecutor = new ScriptExecutor(new Composer(), new NullIO(), new Options(), $executorStub); + $executorMock = $this->createMock(ProcessExecutor::class); + $scriptExecutor = new ScriptExecutor(new Composer(), new NullIO(), new Options(), $executorMock); $phpFinder = new PhpExecutableFinder(); if (!$php = $phpFinder->find(false)) { @@ -50,16 +49,13 @@ public function testMemoryLimit() $expectedCommand = ProcessExecutor::escape($php).($phpArgs ? ' '.$phpArgs : '').' '.$command; - $executorStub + $executorMock + ->expects($this->once()) ->method('execute') ->with($expectedCommand) ->willReturn(0) ; - if (10 === Version::majorVersionNumber()) { - $this->expectNotToPerformAssertions(); - } - $scriptExecutor->execute('php-script', $command); } } diff --git a/tests/Update/RecipePatcherTest.php b/tests/Update/RecipePatcherTest.php index 1b51e957..0ccd2ec2 100644 --- a/tests/Update/RecipePatcherTest.php +++ b/tests/Update/RecipePatcherTest.php @@ -68,11 +68,11 @@ public function testGeneratePatch(array $originalFiles, array $newFiles, string preg_match_all('/index\ ([0-9|a-z]+)\.\./', $patch->getPatch(), $matches); $expectedBlobs = $matches[1]; // new files (0000000) do not need a blob - $expectedBlobs = array_values(array_filter($expectedBlobs, function ($blob) { + $expectedBlobs = array_values(array_filter($expectedBlobs, static function ($blob) { return '0000000' !== $blob; })); - $actualShortenedBlobs = array_map(function ($blob) { + $actualShortenedBlobs = array_map(static function ($blob) { return substr($blob, 0, 7); }, array_keys($patch->getBlobs())); @@ -380,7 +380,7 @@ public static function getApplyPatchTests(string $projectRootPath): iterable [ $dotEnvClean['hash'] => $dotEnvClean['blob'], $packageJsonConflict['hash'] => $packageJsonConflict['blob'], - $webpackEncoreAdded['hash'] => $webpackEncoreAdded['blob'], + // no blob needed for the new webpack_encore.yaml file $securityRemoved['hash'] => $securityRemoved['blob'], ], [