Skip to content

Commit 4dc14ed

Browse files
committed
Added test
1 parent 2e07e94 commit 4dc14ed

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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\InformAboutClosingStaleIssuesHandler;
13+
use App\Service\TaskScheduler;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class InformAboutClosingStaleIssuesHandlerTest extends TestCase
17+
{
18+
public function testHandleKeepOpen()
19+
{
20+
$labelApi = $this->getMockBuilder(NullLabelApi::class)
21+
->disableOriginalConstructor()
22+
->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot'])
23+
->getMock();
24+
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug', 'Keep open']);
25+
26+
$issueApi = $this->getMockBuilder(NullIssueApi::class)
27+
->disableOriginalConstructor()
28+
->setMethods(['close', 'lastCommentWasMadeByBot'])
29+
->getMock();
30+
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
31+
$issueApi->expects($this->never())->method('close');
32+
33+
$scheduler = $this->getMockBuilder(TaskScheduler::class)
34+
->disableOriginalConstructor()
35+
->setMethods(['runLater'])
36+
->getMock();
37+
$scheduler->expects($this->never())->method('runLater');
38+
39+
$repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]);
40+
41+
$handler = new InformAboutClosingStaleIssuesHandler($labelApi, $issueApi, $repoProvider, new StaleIssueCommentGenerator(), $scheduler);
42+
$handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_STALE, new \DateTimeImmutable()));
43+
}
44+
45+
public function testHandleComments()
46+
{
47+
$labelApi = $this->getMockBuilder(NullLabelApi::class)
48+
->disableOriginalConstructor()
49+
->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot'])
50+
->getMock();
51+
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug']);
52+
53+
$issueApi = $this->getMockBuilder(NullIssueApi::class)
54+
->disableOriginalConstructor()
55+
->setMethods(['close', 'lastCommentWasMadeByBot'])
56+
->getMock();
57+
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(false);
58+
$issueApi->expects($this->never())->method('close');
59+
60+
$scheduler = $this->getMockBuilder(TaskScheduler::class)
61+
->disableOriginalConstructor()
62+
->setMethods(['runLater'])
63+
->getMock();
64+
$scheduler->expects($this->never())->method('runLater');
65+
66+
$repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]);
67+
68+
$handler = new InformAboutClosingStaleIssuesHandler($labelApi, $issueApi, $repoProvider, new StaleIssueCommentGenerator(), $scheduler);
69+
$handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_STALE, new \DateTimeImmutable()));
70+
}
71+
72+
public function testHandleStale()
73+
{
74+
$labelApi = $this->getMockBuilder(NullLabelApi::class)
75+
->disableOriginalConstructor()
76+
->setMethods(['getIssueLabels'])
77+
->getMock();
78+
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug']);
79+
80+
$issueApi = $this->getMockBuilder(NullIssueApi::class)
81+
->disableOriginalConstructor()
82+
->setMethods(['close', 'lastCommentWasMadeByBot'])
83+
->getMock();
84+
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
85+
$issueApi->expects($this->never())->method('close');
86+
87+
$scheduler = $this->getMockBuilder(TaskScheduler::class)
88+
->disableOriginalConstructor()
89+
->setMethods(['runLater'])
90+
->getMock();
91+
$scheduler->expects($this->once())->method('runLater');
92+
93+
$repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]);
94+
95+
$handler = new InformAboutClosingStaleIssuesHandler($labelApi, $issueApi, $repoProvider, new StaleIssueCommentGenerator(), $scheduler);
96+
$handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_STALE, new \DateTimeImmutable()));
97+
}
98+
}

0 commit comments

Comments
 (0)