From 1684f82a43e1bec230938ae0c7ce5770d1c79e4f Mon Sep 17 00:00:00 2001 From: Mohamed Hubail Date: Thu, 22 Aug 2024 11:49:55 +0300 Subject: [PATCH] Add `InitCommand.php` Interactive test case (#12068) * Add single test case for interactive `init` command * Fix spelling + use single quotes * Fix test expectations --------- Co-authored-by: Jordi Boggiano --- .../Composer/Test/Command/InitCommandTest.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/Composer/Test/Command/InitCommandTest.php b/tests/Composer/Test/Command/InitCommandTest.php index 18847c1e4..41860f628 100644 --- a/tests/Composer/Test/Command/InitCommandTest.php +++ b/tests/Composer/Test/Command/InitCommandTest.php @@ -696,4 +696,43 @@ class InitCommandTest extends TestCase $file = new JsonFile($dir . '/composer.json'); self::assertEquals($expected, $file->read()); } + + public function testInteractiveRun(): void + { + $dir = $this->initTempComposer(); + unlink($dir . '/composer.json'); + unlink($dir . '/auth.json'); + + $appTester = $this->getApplicationTester(); + + $appTester->setInputs([ + 'vendor/pkg', // Pkg name + 'my desciption', // Description + 'Mr. Test ', // Author + 'stable', // Minimum stability + 'library', // Type + 'Custom License', // License + 'no', // Define dependencies + 'no', // Define dev dependencies + 'n', // Add PSR-4 autoload mapping + '', // Confirm generation + ]); + + $appTester->run(['command' => 'init']); + + self::assertSame(0, $appTester->getStatusCode()); + + $expected = [ + 'name' => 'vendor/pkg', + 'description' => 'my desciption', + 'type' => 'library', + 'license' => 'Custom License', + 'authors' => [['name' => 'Mr. Test', 'email' => 'test@example.org']], + 'minimum-stability' => 'stable', + 'require' => [], + ]; + + $file = new JsonFile($dir . '/composer.json'); + self::assertEquals($expected, $file->read()); + } }