From b52e6b4a74a8e24812355f1a63c0f90b960703b1 Mon Sep 17 00:00:00 2001 From: Jesper Skytte Marcussen Date: Thu, 13 Oct 2022 10:42:03 +0200 Subject: [PATCH] Add tests for BumpCommand (#11097) I've added tests for the BumpCommand to increase the test coverage. See #10796 Signed-off-by: Jesper Skytte Signed-off-by: Jesper Skytte --- .../Composer/Test/Command/BumpCommandTest.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/Composer/Test/Command/BumpCommandTest.php b/tests/Composer/Test/Command/BumpCommandTest.php index 2953c8971..2b13c8cd5 100644 --- a/tests/Composer/Test/Command/BumpCommandTest.php +++ b/tests/Composer/Test/Command/BumpCommandTest.php @@ -47,6 +47,30 @@ class BumpCommandTest extends TestCase $this->assertSame($expected, $json->read()); } + public function testBumpFailsOnNonExistingComposerFile(): void + { + $dir = $this->initTempComposer([]); + $composerJsonPath = $dir . '/composer.json'; + unlink($composerJsonPath); + + $appTester = $this->getApplicationTester(); + $this->assertSame(1, $appTester->run(['command' => 'bump'], ['capture_stderr_separately' => true])); + + $this->assertStringContainsString("./composer.json is not readable.", $appTester->getErrorOutput()); + } + + public function testBumpFailsOnWriteErrorToComposerFile(): void + { + $dir = $this->initTempComposer([]); + $composerJsonPath = $dir . '/composer.json'; + chmod($composerJsonPath, 0444); + + $appTester = $this->getApplicationTester(); + $this->assertSame(1, $appTester->run(['command' => 'bump'], ['capture_stderr_separately' => true])); + + $this->assertStringContainsString("./composer.json is not writable.", $appTester->getErrorOutput()); + } + public function provideTests(): \Generator { yield 'bump all by default' => [ @@ -201,5 +225,63 @@ class BumpCommandTest extends TestCase true, 0, ]; + + yield 'bump works with non-standard package' => [ + [ + 'require' => [ + 'php' => '>=5.3', + 'first/pkg' => '^2.3.4', + 'second/pkg' => '^3.4', + ], + 'require-dev' => [ + 'dev/pkg' => '^2.3.4.5', + ], + ], + [], + [ + 'require' => [ + 'php' => '>=5.3', + 'first/pkg' => '^2.3.4', + 'second/pkg' => '^3.4', + ], + 'require-dev' => [ + 'dev/pkg' => '^2.3.4.5', + ], + ], + ]; + + yield 'bump works with unknown package' => [ + [ + 'require' => [ + 'first/pkg' => '^2.3.4', + 'second/pkg' => '^3.4', + 'third/pkg' => '^1.2', + ], + ], + [], + [ + 'require' => [ + 'first/pkg' => '^2.3.4', + 'second/pkg' => '^3.4', + 'third/pkg' => '^1.2', + ], + ], + ]; + + yield 'bump works with aliased package' => [ + [ + 'require' => [ + 'first/pkg' => '^2.3.4', + 'second/pkg' => 'dev-bugfix as 3.4.x-dev', + ], + ], + [], + [ + 'require' => [ + 'first/pkg' => '^2.3.4', + 'second/pkg' => 'dev-bugfix as 3.4.x-dev', + ], + ], + ]; } }