From fb2c17d69669f6b8ab0c208b91b8c4a727d3b7d3 Mon Sep 17 00:00:00 2001 From: Alex Theobold <44616505+theoboldalex@users.noreply.github.com> Date: Sun, 14 May 2023 13:15:44 +0100 Subject: [PATCH] Test install command (#11277) * Adds test class boilerplate * test: Tests warning returned with dev flag * test: warning returned with no-suggest flag * test: packages passed is invalid * test: no-install flag passed --------- Co-authored-by: alex.theobold --- .../Test/Command/InstallCommandTest.php | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 tests/Composer/Test/Command/InstallCommandTest.php diff --git a/tests/Composer/Test/Command/InstallCommandTest.php b/tests/Composer/Test/Command/InstallCommandTest.php new file mode 100644 index 000000000..e5983cc07 --- /dev/null +++ b/tests/Composer/Test/Command/InstallCommandTest.php @@ -0,0 +1,182 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test\Command; + +use Composer\Test\TestCase; +use Generator; + +class InstallCommandTest extends TestCase +{ + /** + * @dataProvider useCaseProvider + * @param array $composerJson + * @param array $command + */ + public function testInstallCommand( + array $composerJson, + array $command, + string $expected, + bool $lock = false + ): void { + $this->initTempComposer($composerJson); + + $packages = [ + self::getPackage('vendor/package', '1.2.3'), + ]; + $devPackages = [ + self::getPackage('vendor/devpackage', '2.3.4'), + ]; + + if ($lock) { + $this->createComposerLock($packages, $devPackages); + } + + $this->createInstalledJson($packages, $devPackages); + + $appTester = $this->getApplicationTester(); + $appTester->run(array_merge(['command' => 'install'], $command)); + + $this->assertSame(trim($expected), trim($appTester->getDisplay(true))); + } + + public function useCaseProvider(): Generator + { + yield 'it writes an error when the dev flag is passed' => [ + [ + 'repositories' => [ + 'packages' => [ + 'type' => 'package', + 'package' => [ + [ + 'name' => 'vendor/package', + 'description' => 'generic description', + 'version' => '1.0.0', + 'dist' => [ + 'url' => 'https://example.org', + 'type' => 'zip' + ] + ], + ] + ] + ], + 'require' => [ + 'vendor/package' => '^1.0' + ] + ], + ['--dev' => true], + <<You are using the deprecated option "--dev". It has no effect and will break in Composer 3. +Installing dependencies from lock file (including require-dev) +Verifying lock file contents can be installed on current platform. +Nothing to install, update or remove +Generating autoload files +OUTPUT + , + true + ]; + + yield 'it writes an error when no-suggest flag passed' => [ + [ + 'repositories' => [ + 'packages' => [ + 'type' => 'package', + 'package' => [ + [ + 'name' => 'vendor/package', + 'description' => 'generic description', + 'version' => '1.0.0', + 'dist' => [ + 'url' => 'https://example.org', + 'type' => 'zip' + ] + ], + ] + ] + ], + 'require' => [ + 'vendor/package' => '^1.0' + ] + ], + ['--no-suggest' => true], + <<You are using the deprecated option "--no-suggest". It has no effect and will break in Composer 3. +Installing dependencies from lock file (including require-dev) +Verifying lock file contents can be installed on current platform. +Nothing to install, update or remove +Generating autoload files +OUTPUT + , + true + ]; + + yield 'it writes an error when packages passed' => [ + [ + 'repositories' => [ + 'packages' => [ + 'type' => 'package', + 'package' => [ + [ + 'name' => 'vendor/package', + 'description' => 'generic description', + 'version' => '1.0.0', + 'dist' => [ + 'url' => 'https://example.org', + 'type' => 'zip' + ] + ], + ] + ] + ], + 'require' => [ + 'vendor/package' => '^1.0' + ] + ], + ['packages' => ['vendor/package']], + << [ + [ + 'repositories' => [ + 'packages' => [ + 'type' => 'package', + 'package' => [ + [ + 'name' => 'vendor/package', + 'description' => 'generic description', + 'version' => '1.0.0', + 'dist' => [ + 'url' => 'https://example.org', + 'type' => 'zip' + ] + ], + ] + ] + ], + 'require' => [ + 'vendor/package' => '^1.0' + ] + ], + ['--no-install' => true], + <<