|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Service\TaskHandler; |
| 6 | + |
| 7 | +use App\Api\Issue\NullIssueApi; |
| 8 | +use App\Api\Label\NullLabelApi; |
| 9 | +use App\Entity\Task; |
| 10 | +use App\Service\RepositoryProvider; |
| 11 | +use App\Service\StaleIssueCommentGenerator; |
| 12 | +use App\Service\TaskHandler\CloseStaleIssuesHandler; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class CloseStaleIssuesHandlerTest extends TestCase |
| 16 | +{ |
| 17 | + public function testHandleKeepOpen() |
| 18 | + { |
| 19 | + $labelApi = $this->getMockBuilder(NullLabelApi::class) |
| 20 | + ->disableOriginalConstructor() |
| 21 | + ->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot']) |
| 22 | + ->getMock(); |
| 23 | + $labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug', 'Keep open']); |
| 24 | + |
| 25 | + $issueApi = $this->getMockBuilder(NullIssueApi::class) |
| 26 | + ->disableOriginalConstructor() |
| 27 | + ->setMethods(['close', 'lastCommentWasMadeByBot']) |
| 28 | + ->getMock(); |
| 29 | + $issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true); |
| 30 | + $issueApi->expects($this->never())->method('close'); |
| 31 | + |
| 32 | + $repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]); |
| 33 | + |
| 34 | + $handler = new CloseStaleIssuesHandler($labelApi, $issueApi, $repoProvider, new StaleIssueCommentGenerator()); |
| 35 | + $handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_STALE, new \DateTimeImmutable())); |
| 36 | + } |
| 37 | + |
| 38 | + public function testHandleComments() |
| 39 | + { |
| 40 | + $labelApi = $this->getMockBuilder(NullLabelApi::class) |
| 41 | + ->disableOriginalConstructor() |
| 42 | + ->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot']) |
| 43 | + ->getMock(); |
| 44 | + $labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug']); |
| 45 | + |
| 46 | + $issueApi = $this->getMockBuilder(NullIssueApi::class) |
| 47 | + ->disableOriginalConstructor() |
| 48 | + ->setMethods(['close', 'lastCommentWasMadeByBot']) |
| 49 | + ->getMock(); |
| 50 | + $issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(false); |
| 51 | + $issueApi->expects($this->never())->method('close'); |
| 52 | + |
| 53 | + $repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]); |
| 54 | + |
| 55 | + $handler = new CloseStaleIssuesHandler($labelApi, $issueApi, $repoProvider, new StaleIssueCommentGenerator()); |
| 56 | + $handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_STALE, new \DateTimeImmutable())); |
| 57 | + } |
| 58 | + |
| 59 | + public function testHandleStale() |
| 60 | + { |
| 61 | + $labelApi = $this->getMockBuilder(NullLabelApi::class) |
| 62 | + ->disableOriginalConstructor() |
| 63 | + ->setMethods(['getIssueLabels']) |
| 64 | + ->getMock(); |
| 65 | + $labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug']); |
| 66 | + |
| 67 | + $issueApi = $this->getMockBuilder(NullIssueApi::class) |
| 68 | + ->disableOriginalConstructor() |
| 69 | + ->setMethods(['close', 'lastCommentWasMadeByBot']) |
| 70 | + ->getMock(); |
| 71 | + $issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true); |
| 72 | + $issueApi->expects($this->once())->method('close'); |
| 73 | + |
| 74 | + $repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]); |
| 75 | + |
| 76 | + $handler = new CloseStaleIssuesHandler($labelApi, $issueApi, $repoProvider, new StaleIssueCommentGenerator()); |
| 77 | + $handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_STALE, new \DateTimeImmutable())); |
| 78 | + } |
| 79 | +} |
0 commit comments