-
Notifications
You must be signed in to change notification settings - Fork 4
/
AddLabelByAapprovalCountCommandHandlerTest.php
119 lines (109 loc) · 4.33 KB
/
AddLabelByAapprovalCountCommandHandlerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
namespace App\Tests\PullRequest\Application\CommandHandler;
use App\PullRequest\Application\Command\AddLabelByApprovalCountCommand;
use App\PullRequest\Application\CommandHandler\AddLabelByApprovalCountCommandHandler;
use App\PullRequest\Domain\Aggregate\PullRequest\Approval;
use App\PullRequest\Domain\Aggregate\PullRequest\PullRequest;
use App\PullRequest\Domain\Aggregate\PullRequest\PullRequestId;
use App\PullRequest\Domain\Exception\PullRequestNotFoundException;
use App\PullRequest\Infrastructure\Adapter\InMemoryPullRequestRepository;
use App\Shared\Infrastructure\Adapter\InMemoryCommitterRepository;
use PHPUnit\Framework\TestCase;
class AddLabelByAapprovalCountCommandHandlerTest extends TestCase
{
private AddLabelByApprovalCountCommandHandler $addLabelByApprovalCountCommandHandler;
private InMemoryPullRequestRepository $prRepository;
private InMemoryCommitterRepository $committerRepository;
protected function setUp(): void
{
$this->prRepository = new InMemoryPullRequestRepository();
$this->committerRepository = new InMemoryCommitterRepository();
$this->addLabelByApprovalCountCommandHandler = new AddLabelByApprovalCountCommandHandler($this->prRepository, $this->committerRepository);
}
/**
* @param string[] $originalLabels
* @param Approval[] $approvals
* @param string[] $expectedLabels
*
* @dataProvider provideTestHandle
*/
public function testHandle(array $originalLabels, PullRequestId $pullRequestId, array $approvals, array $expectedLabels): void
{
$this->prRepository->feed([
PullRequest::create(
id: $pullRequestId,
labels: $originalLabels,
approvals: $approvals,
targetBranch: 'main'
),
]);
$this->addLabelByApprovalCountCommandHandler->__invoke(new AddLabelByApprovalCountCommand(
repositoryOwner: $pullRequestId->repositoryOwner,
repositoryName: $pullRequestId->repositoryName,
pullRequestNumber: $pullRequestId->pullRequestNumber,
));
/** @var PullRequest $pr */
$pr = $this->prRepository->find(
new PullRequestId(repositoryOwner: $pullRequestId->repositoryOwner, repositoryName: $pullRequestId->repositoryName, pullRequestNumber: $pullRequestId->pullRequestNumber)
);
$this->assertEquals($expectedLabels, $pr->getLabels());
}
/**
* @return array<array<int, array<int, string>|PullRequestId|Approval[]>>
*/
public static function provideTestHandle(): array
{
return [
[
[],
new PullRequestId(
repositoryOwner: 'PrestaShop',
repositoryName: 'PrestaShop',
pullRequestNumber: 'pullRequestNumber'
),
[new Approval('lartist')],
[],
],
[
[],
new PullRequestId(
repositoryOwner: 'PrestaShop',
repositoryName: 'PrestaShop',
pullRequestNumber: 'pullRequestNumber'
),
[new Approval('lartist'), new Approval('nicosomb')],
['Waiting for QA'],
],
[
[],
new PullRequestId(
repositoryOwner: 'PrestaShop',
repositoryName: 'OtherThanPrestaShop',
pullRequestNumber: 'pullRequestNumber'
),
[new Approval('lartist')],
['Waiting for QA'],
],
[
[],
new PullRequestId(
repositoryOwner: 'PrestaShop',
repositoryName: 'OtherThanPrestaShop',
pullRequestNumber: 'pullRequestNumber'
),
[new Approval('no_committer')],
[],
],
];
}
public function testPullRequestNotFound(): void
{
$this->expectException(PullRequestNotFoundException::class);
$this->addLabelByApprovalCountCommandHandler->__invoke(new AddLabelByApprovalCountCommand(
repositoryOwner: 'fake',
repositoryName: 'fake',
pullRequestNumber: 'fake'
));
}
}