From 9ca3cb37b22d449816022c1dad314cfc2943bcc2 Mon Sep 17 00:00:00 2001 From: Alex Raputa Date: Sat, 2 Oct 2021 12:43:45 +0300 Subject: [PATCH 1/3] Closes #147: Add test for `CreateMilestones` command Signed-off-by: Alex Raputa --- .../unit/Application/CreateMilestonesTest.php | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 test/unit/Application/CreateMilestonesTest.php diff --git a/test/unit/Application/CreateMilestonesTest.php b/test/unit/Application/CreateMilestonesTest.php new file mode 100644 index 00000000..95a285f5 --- /dev/null +++ b/test/unit/Application/CreateMilestonesTest.php @@ -0,0 +1,133 @@ +loadEvent = $this->createMock(LoadCurrentGithubEvent::class); + $this->createMilestone = $this->createMock(CreateMilestone::class); + + $this->command = new CreateMilestones( + $this->loadEvent, + $this->createMilestone + ); + + $this->event = MilestoneClosedEvent::fromEventJson(<<<'JSON' + { + "milestone": { + "title": "1.2.3", + "number": 123 + }, + "repository": { + "full_name": "foo/bar" + }, + "action": "closed" + } + JSON + ); + + $this->releaseVersion = SemVerVersion::fromMilestoneName('1.2.3'); + } + + public function testCommandName(): void + { + self::assertSame('laminas:automatic-releases:create-milestones', $this->command->getName()); + } + + public function testWillCreate(): void + { + $this->loadEvent + ->expects(self::once()) + ->method('__invoke') + ->willReturn($this->event); + + $this->createMilestone + ->expects(self::exactly(3)) + ->method('__invoke') + ->withConsecutive( + [ + self::equalTo(RepositoryName::fromFullName('foo/bar')), + self::equalTo($this->releaseVersion->nextPatch()), + ], + [ + self::equalTo(RepositoryName::fromFullName('foo/bar')), + self::equalTo($this->releaseVersion->nextMinor()), + ], + [ + self::equalTo(RepositoryName::fromFullName('foo/bar')), + self::equalTo($this->releaseVersion->nextMajor()), + ], + ); + + self::assertSame(0, $this->command->run(new ArrayInput([]), new NullOutput())); + } + + public function testWillFailed(): void + { + $this->loadEvent + ->expects(self::once()) + ->method('__invoke') + ->willReturn($this->event); + + $this->createMilestone + ->expects(self::exactly(3)) + ->method('__invoke') + ->withConsecutive( + [ + self::equalTo(RepositoryName::fromFullName('foo/bar')), + self::equalTo($this->releaseVersion->nextPatch()), + ], + [ + self::equalTo(RepositoryName::fromFullName('foo/bar')), + self::equalTo($this->releaseVersion->nextMinor()), + ], + [ + self::equalTo(RepositoryName::fromFullName('foo/bar')), + self::equalTo($this->releaseVersion->nextMajor()), + ], + ) + ->willReturnOnConsecutiveCalls( + self::throwException( + CreateMilestoneFailed::forVersion($this->releaseVersion->nextPatch()->fullReleaseName()), + ), + self::throwException( + CreateMilestoneFailed::forVersion($this->releaseVersion->nextMinor()->fullReleaseName()), + ), + self::throwException( + CreateMilestoneFailed::forVersion($this->releaseVersion->nextMajor()->fullReleaseName()), + ), + ); + + self::assertSame(0, $this->command->run(new ArrayInput([]), new NullOutput())); + } +} From c6b02a133ae64d016e9cb0e6230d7e93fdf38782 Mon Sep 17 00:00:00 2001 From: Alex Raputa Date: Sat, 2 Oct 2021 23:53:46 +0300 Subject: [PATCH 2/3] `execute` instead of `run` for fix mutations Signed-off-by: Alex Raputa --- test/unit/Application/CreateMilestonesTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/Application/CreateMilestonesTest.php b/test/unit/Application/CreateMilestonesTest.php index 95a285f5..75dc4918 100644 --- a/test/unit/Application/CreateMilestonesTest.php +++ b/test/unit/Application/CreateMilestonesTest.php @@ -89,7 +89,7 @@ public function testWillCreate(): void ], ); - self::assertSame(0, $this->command->run(new ArrayInput([]), new NullOutput())); + self::assertSame(0, $this->command->execute(new ArrayInput([]), new NullOutput())); } public function testWillFailed(): void @@ -128,6 +128,6 @@ public function testWillFailed(): void ), ); - self::assertSame(0, $this->command->run(new ArrayInput([]), new NullOutput())); + self::assertSame(0, $this->command->execute(new ArrayInput([]), new NullOutput())); } } From 6d66bd387c15b3d83f4a66a0d9b8ae473dbf292a Mon Sep 17 00:00:00 2001 From: Alex Raputa Date: Sun, 3 Oct 2021 05:52:46 +0300 Subject: [PATCH 3/3] add `@covers` to `CreateMilestonesTest` Signed-off-by: Alex Raputa --- test/unit/Application/CreateMilestonesTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/Application/CreateMilestonesTest.php b/test/unit/Application/CreateMilestonesTest.php index 75dc4918..3aedb865 100644 --- a/test/unit/Application/CreateMilestonesTest.php +++ b/test/unit/Application/CreateMilestonesTest.php @@ -16,6 +16,9 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; +/** + * @covers \Laminas\AutomaticReleases\Application\Command\CreateMilestones + */ final class CreateMilestonesTest extends TestCase { /** @var LoadCurrentGithubEvent&MockObject */