diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 500b3db7..b8fe65db 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,18 @@ - - + + + + ./src/ + + ./tests - - - - + + + - - - - ./src/ - - diff --git a/src/Command/DumpEnvCommand.php b/src/Command/DumpEnvCommand.php index 529bc9f0..69023a5f 100644 --- a/src/Command/DumpEnvCommand.php +++ b/src/Command/DumpEnvCommand.php @@ -33,7 +33,7 @@ public function __construct(Config $config, Options $options) parent::__construct(); } - protected function configure() + protected function configure(): void { $this->setName('symfony:dump-env') ->setAliases(['dump-env']) @@ -67,13 +67,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $vars = var_export($vars, true); $vars = <<getIO()->writeError('Successfully dumped .env files in .env.local.php'); diff --git a/src/Command/InstallRecipesCommand.php b/src/Command/InstallRecipesCommand.php index 1f43ece7..3f178470 100644 --- a/src/Command/InstallRecipesCommand.php +++ b/src/Command/InstallRecipesCommand.php @@ -38,7 +38,7 @@ public function __construct(/* cannot be type-hinted */ $flex, string $rootDir, parent::__construct(); } - protected function configure() + protected function configure(): void { $this->setName('symfony:recipes:install') ->setAliases(['recipes:install', 'symfony:sync-recipes', 'sync-recipes', 'fix-recipes']) diff --git a/src/Command/RecipesCommand.php b/src/Command/RecipesCommand.php index 8536c405..66f15af8 100644 --- a/src/Command/RecipesCommand.php +++ b/src/Command/RecipesCommand.php @@ -44,7 +44,7 @@ public function __construct(/* cannot be type-hinted */ $flex, Lock $symfonyLock parent::__construct(); } - protected function configure() + protected function configure(): void { $this->setName('symfony:recipes') ->setAliases(['recipes']) diff --git a/src/Command/UpdateRecipesCommand.php b/src/Command/UpdateRecipesCommand.php index 1b4491bb..bf47d672 100644 --- a/src/Command/UpdateRecipesCommand.php +++ b/src/Command/UpdateRecipesCommand.php @@ -51,7 +51,7 @@ public function __construct(/* cannot be type-hinted */ $flex, Downloader $downl parent::__construct(); } - protected function configure() + protected function configure(): void { $this->setName('symfony:recipes:update') ->setAliases(['recipes:update']) diff --git a/src/Configurator/MakefileConfigurator.php b/src/Configurator/MakefileConfigurator.php index b8b061af..5c1d9ca7 100644 --- a/src/Configurator/MakefileConfigurator.php +++ b/src/Configurator/MakefileConfigurator.php @@ -76,16 +76,16 @@ private function configureMakefile(Recipe $recipe, array $definitions, bool $upd file_put_contents( $this->options->get('root-dir').'/Makefile', <<add(new Command\RecipesCommand($this, $this->lock, $rfs)); - $app->add(new Command\InstallRecipesCommand($this, $this->options->get('root-dir'), $this->options->get('runtime')['dotenv_path'] ?? '.env')); - $app->add(new Command\UpdateRecipesCommand($this, $this->downloader, $rfs, $this->configurator, $this->options->get('root-dir'))); - $app->add(new Command\DumpEnvCommand($this->config, $this->options)); + $addCommand = 'add'.(method_exists($app, 'addCommand') ? 'Command' : ''); + $app->$addCommand(new Command\RecipesCommand($this, $this->lock, $rfs)); + $app->$addCommand(new Command\InstallRecipesCommand($this, $this->options->get('root-dir'), $this->options->get('runtime')['dotenv_path'] ?? '.env')); + $app->$addCommand(new Command\UpdateRecipesCommand($this, $this->downloader, $rfs, $this->configurator, $this->options->get('root-dir'))); + $app->$addCommand(new Command\DumpEnvCommand($this->config, $this->options)); break; } diff --git a/tests/Command/DumpEnvCommandTest.php b/tests/Command/DumpEnvCommandTest.php index 8859cf8d..c7756a64 100644 --- a/tests/Command/DumpEnvCommandTest.php +++ b/tests/Command/DumpEnvCommandTest.php @@ -210,7 +210,7 @@ private function createCommandDumpEnv(array $options = []) ); $application = new Application(); - $application->add($command); + $application->{'add'.(method_exists($application, 'addCommand') ? 'Command' : '')}($command); $command = $application->find('dump-env'); return new CommandTester($command); diff --git a/tests/Command/InstallRecipesCommandTest.php b/tests/Command/InstallRecipesCommandTest.php index 46216af1..41c520e9 100644 --- a/tests/Command/InstallRecipesCommandTest.php +++ b/tests/Command/InstallRecipesCommandTest.php @@ -30,7 +30,7 @@ public function testCommandFlagsPassedDown() $command = new InstallRecipesCommand($flex, __DIR__); $application = new Application(); - $application->add($command); + $application->{'add'.(method_exists($application, 'addCommand') ? 'Command' : '')}($command); $command = $application->find('symfony:recipes:install'); $tester = new CommandTester($command); diff --git a/tests/Command/UpdateRecipesCommandTest.php b/tests/Command/UpdateRecipesCommandTest.php index efd16f54..87d63493 100644 --- a/tests/Command/UpdateRecipesCommandTest.php +++ b/tests/Command/UpdateRecipesCommandTest.php @@ -112,7 +112,7 @@ private function createCommandUpdateRecipes(): CommandTester $command->setComposer($composer); $application = new Application(); - $application->add($command); + $application->{'add'.(method_exists($application, 'addCommand') ? 'Command' : '')}($command); $command = $application->find('recipes:update'); return new CommandTester($command); diff --git a/tests/Configurator/CopyDirectoryFromPackageConfiguratorTest.php b/tests/Configurator/CopyDirectoryFromPackageConfiguratorTest.php index 43f5f5de..4dd9acd5 100644 --- a/tests/Configurator/CopyDirectoryFromPackageConfiguratorTest.php +++ b/tests/Configurator/CopyDirectoryFromPackageConfiguratorTest.php @@ -32,6 +32,7 @@ class CopyDirectoryFromPackageConfiguratorTest extends TestCase private $targetDirectory; private $io; private $recipe; + private $composer; public function testConfigureDirectory() { diff --git a/tests/Configurator/CopyFromPackageConfiguratorTest.php b/tests/Configurator/CopyFromPackageConfiguratorTest.php index 8a5366b3..5dbc0814 100644 --- a/tests/Configurator/CopyFromPackageConfiguratorTest.php +++ b/tests/Configurator/CopyFromPackageConfiguratorTest.php @@ -31,6 +31,7 @@ class CopyFromPackageConfiguratorTest extends TestCase private $targetDirectory; private $io; private $recipe; + private $composer; public function testNoFilesCopied() { @@ -55,8 +56,8 @@ public function testConfigureAndOverwriteFiles() file_put_contents($this->targetFile, '-'); $lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock(); - $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']); - $this->io->expects($this->at(2))->method('writeError')->with([' Created "./public/file"']); + $ioCalls = []; + $this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); $this->io->method('askConfirmation')->with('File "build/public/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true); $this->assertFileExists($this->targetFile); @@ -68,6 +69,12 @@ public function testConfigureAndOverwriteFiles() ); $this->assertFileExists($this->targetFile); $this->assertFileEquals($this->sourceFile, $this->targetFile); + + $expected = [ + [' Copying files from package'], + [' Created "./public/file"'], + ]; + $this->assertSame($expected, $ioCalls); } public function testSourceFileNotExist() @@ -88,20 +95,26 @@ public function testConfigure() file_put_contents($this->sourceFile, ''); } - $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']); - $this->io->expects($this->at(1))->method('writeError')->with([' Created "./public/"']); - $this->io->expects($this->at(2))->method('writeError')->with([' Created "./public/file"']); + $ioCalls = []; + $this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); $this->assertFileDoesNotExist($this->targetFile); $lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock(); $this->createConfigurator()->configure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock); $this->assertFileExists($this->targetFile); + + $expected = [ + [' Copying files from package'], + [' Created "./public/"'], + [' Created "./public/file"'], + ]; + $this->assertSame($expected, $ioCalls); } public function testUnconfigure() { - $this->io->expects($this->at(0))->method('writeError')->with([' Removing files from package']); - $this->io->expects($this->at(1))->method('writeError')->with([' Removed "./public/file"']); + $ioCalls = []; + $this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); if (!file_exists($this->targetDirectory)) { mkdir($this->targetDirectory); @@ -115,6 +128,12 @@ public function testUnconfigure() $lock ); $this->assertFileDoesNotExist($this->targetFile); + + $expected = [ + [' Removing files from package'], + [' Removed "./public/file"'], + ]; + $this->assertSame($expected, $ioCalls); } public function testNoFilesRemoved() diff --git a/tests/Configurator/CopyFromRecipeConfiguratorTest.php b/tests/Configurator/CopyFromRecipeConfiguratorTest.php index 2d6ba3c5..d5e50d49 100644 --- a/tests/Configurator/CopyFromRecipeConfiguratorTest.php +++ b/tests/Configurator/CopyFromRecipeConfiguratorTest.php @@ -66,8 +66,8 @@ public function testConfigureAndOverwriteFiles() file_put_contents($this->targetFile, '-'); $lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock(); - $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from recipe']); - $this->io->expects($this->at(2))->method('writeError')->with([' Created "./config/file"']); + $ioCalls = []; + $this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); $this->io->method('askConfirmation')->with('File "build/config/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true); $this->assertFileExists($this->targetFile); @@ -79,12 +79,18 @@ public function testConfigureAndOverwriteFiles() ); $this->assertFileExists($this->targetFile); $this->assertSame('somecontent', file_get_contents($this->targetFile)); + + $expected = [ + [' Copying files from recipe'], + [' Created "./config/file"'], + ]; + $this->assertSame($expected, $ioCalls); } public function testConfigure() { - $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from recipe']); - $this->io->expects($this->at(1))->method('writeError')->with([' Created "./config/file"']); + $ioCalls = []; + $this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); $this->assertFileDoesNotExist($this->targetFile); $lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock(); @@ -94,6 +100,12 @@ public function testConfigure() $lock ); $this->assertFileExists($this->targetFile); + + $expected = [ + [' Copying files from recipe'], + [' Created "./config/file"'], + ]; + $this->assertSame($expected, $ioCalls); } public function testUnconfigureKeepsLockedFiles() @@ -119,8 +131,8 @@ public function testUnconfigureKeepsLockedFiles() public function testUnconfigure() { - $this->io->expects($this->at(0))->method('writeError')->with([' Removing files from recipe']); - $this->io->expects($this->at(1))->method('writeError')->with([' Removed "./config/file"']); + $ioCalls = []; + $this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; }); if (!file_exists($this->targetDirectory)) { @mkdir($this->targetDirectory, 0777, true); @@ -131,6 +143,12 @@ public function testUnconfigure() $this->recipe->method('getName')->willReturn('test-recipe'); $this->createConfigurator()->unconfigure($this->recipe, [$this->targetFileRelativePath], $lock); $this->assertFileDoesNotExist($this->targetFile); + + $expected = [ + [' Removing files from recipe'], + [' Removed "./config/file"'], + ]; + $this->assertSame($expected, $ioCalls); } public function testNoFilesRemoved() diff --git a/tests/FlexTest.php b/tests/FlexTest.php index 1bba9deb..2e53f3ee 100644 --- a/tests/FlexTest.php +++ b/tests/FlexTest.php @@ -97,11 +97,10 @@ public function testPostInstall() $this->assertSame( <<=1.0): From github.com/symfony/recipes:main + Symfony operations: 1 recipe () + - Configuring dummy/dummy (>=1.0): From github.com/symfony/recipes:main -EOF - , + EOF, str_replace("\r\n", "\n", $io->getOutput()) ); } @@ -506,15 +505,13 @@ private function mockManager(): RepositoryManager private function mockFlexCustom(BufferIO $io, Composer $composer, Configurator $configurator, Downloader $downloader, Lock $lock): Flex { - return \Closure::bind(function () use ($composer, $io, $configurator, $downloader, $lock) { + return \Closure::bind(static function () use ($composer, $io, $configurator, $downloader, $lock) { $flex = new Flex(); $flex->composer = $composer; $flex->config = $composer->getConfig(); $flex->io = $io; $flex->configurator = $configurator; $flex->downloader = $downloader; - $flex->runningCommand = function () { - }; $flex->options = new Options(['config-dir' => 'config', 'var-dir' => 'var', 'root-dir' => '.']); $flex->lock = $lock;