diff --git a/test/unit/Application/CreateMilestonesTest.php b/test/unit/Application/CreateMilestonesTest.php new file mode 100644 index 00000000..3aedb865 --- /dev/null +++ b/test/unit/Application/CreateMilestonesTest.php @@ -0,0 +1,136 @@ +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->execute(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->execute(new ArrayInput([]), new NullOutput())); + } +}