Skip to content

Commit 5e46613

Browse files
committed
Fix Tests for Integrations API
1 parent 3d60d65 commit 5e46613

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

tests/Api/IntegrationsTest.php

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
namespace Gitlab\Tests\Api;
1616

1717
use Gitlab\Api\Integrations;
18+
use PHPUnit\Framework\Attributes\Test;
1819
use PHPUnit\Framework\MockObject\MockObject;
1920

2021
class IntegrationsTest extends TestCase
2122
{
22-
/**
23-
* @test
24-
*/
23+
#[Test]
2524
public function shouldGetAllIntegrations(): void
2625
{
2726
$expectedArray = $this->getMultipleIntegrationsData();
@@ -30,6 +29,7 @@ public function shouldGetAllIntegrations(): void
3029
$this->assertEquals($expectedArray, $api->all(1));
3130
}
3231

32+
#[Test]
3333
public function shouldCreateMicrosoftTeams(): void
3434
{
3535
$expectedArray = [
@@ -40,14 +40,15 @@ public function shouldCreateMicrosoftTeams(): void
4040
$api = $this->getApiMock();
4141
$api->expects($this->once())
4242
->method('put')
43-
->with('projects/1/integrations')
44-
->will($this->returnValue($expectedArray));
43+
->with('projects/1/integrations/microsoft-teams')
44+
->willReturn($expectedArray);
4545

4646
$this->assertEquals($expectedArray, $api->createMicrosoftTeams(1, [
47-
'webroot' => 'https://test.org/',
47+
'webhook' => 'https://test.org/',
4848
]));
4949
}
5050

51+
#[Test]
5152
public function shouldUpdateMicrosoftTeams(): void
5253
{
5354
$expectedArray = [
@@ -58,14 +59,15 @@ public function shouldUpdateMicrosoftTeams(): void
5859
$api = $this->getApiMock();
5960
$api->expects($this->once())
6061
->method('put')
61-
->with('projects/1/integrations')
62-
->will($this->returnValue($expectedArray));
62+
->with('projects/1/integrations/microsoft-teams')
63+
->willReturn($expectedArray);
6364

6465
$this->assertEquals($expectedArray, $api->updateMicrosoftTeams(1, [
65-
'webroot' => 'https://test.org/',
66+
'webhook' => 'https://test.org/',
6667
]));
6768
}
6869

70+
#[Test]
6971
public function shouldGetMicrosoftTeams(): void
7072
{
7173
$expectedArray = [
@@ -76,25 +78,27 @@ public function shouldGetMicrosoftTeams(): void
7678
$api = $this->getApiMock();
7779
$api->expects($this->once())
7880
->method('get')
79-
->with('projects/1/integrations')
80-
->will($this->returnValue($expectedArray));
81+
->with('projects/1/integrations/microsoft-teams')
82+
->willReturn($expectedArray);
8183

8284
$this->assertEquals($expectedArray, $api->getMicrosoftTeams(1));
8385
}
8486

87+
#[Test]
8588
public function shouldRemoveMicrosoftTeams(): void
8689
{
8790
$expectedBool = true;
8891

8992
$api = $this->getApiMock();
9093
$api->expects($this->once())
9194
->method('delete')
92-
->with('projects/1/integrations')
93-
->will($this->returnValue($expectedBool));
95+
->with('projects/1/integrations/microsoft-teams')
96+
->willReturn($expectedBool);
9497

9598
$this->assertEquals($expectedBool, $api->removeMicrosoftTeams(1));
9699
}
97100

101+
#[Test]
98102
public function shouldCreateJira(): void
99103
{
100104
$expectedArray = [
@@ -105,15 +109,16 @@ public function shouldCreateJira(): void
105109
$api = $this->getApiMock();
106110
$api->expects($this->once())
107111
->method('put')
108-
->with('projects/1/integrations')
109-
->will($this->returnValue($expectedArray));
112+
->with('projects/1/integrations/jira')
113+
->willReturn($expectedArray);
110114

111115
$this->assertEquals($expectedArray, $api->createJira(1, [
112-
'url' => 'http://test.org/',
116+
'url' => 'https://test.org/',
113117
'password' => '123',
114118
]));
115119
}
116120

121+
#[Test]
117122
public function shouldUpdateJira(): void
118123
{
119124
$expectedArray = [
@@ -124,15 +129,16 @@ public function shouldUpdateJira(): void
124129
$api = $this->getApiMock();
125130
$api->expects($this->once())
126131
->method('put')
127-
->with('projects/1/integrations')
128-
->will($this->returnValue($expectedArray));
132+
->with('projects/1/integrations/jira')
133+
->willReturn($expectedArray);
129134

130135
$this->assertEquals($expectedArray, $api->updateJira(1, [
131-
'url' => 'http://test.org/',
136+
'url' => 'https://test.org/',
132137
'password' => '123',
133138
]));
134139
}
135140

141+
#[Test]
136142
public function shouldGetJira(): void
137143
{
138144
$expectedArray = [
@@ -143,40 +149,45 @@ public function shouldGetJira(): void
143149
$api = $this->getApiMock();
144150
$api->expects($this->once())
145151
->method('get')
146-
->with('projects/1/integrations')
147-
->will($this->returnValue($expectedArray));
152+
->with('projects/1/integrations/jira')
153+
->willReturn($expectedArray);
148154

149155
$this->assertEquals($expectedArray, $api->getJira(1));
150156
}
151157

158+
#[Test]
152159
public function shouldRemoveJira(): void
153160
{
154161
$expectedBool = true;
155162

156163
$api = $this->getApiMock();
157164
$api->expects($this->once())
158165
->method('delete')
159-
->with('projects/1/integrations')
160-
->will($this->returnValue($expectedBool));
166+
->with('projects/1/integrations/jira')
167+
->willReturn($expectedBool);
161168

162169
$this->assertEquals($expectedBool, $api->removeJira(1));
163170
}
164171

165-
protected function getMultipleIntegrationsData(): array
172+
// This method is used to create an array of multiple integrations data.
173+
// NOT A TEST
174+
private function getMultipleIntegrationsData(): array
166175
{
167176
return [
168177
['id' => 1, 'title' => 'Microsoft Teams notifications', 'slug' => 'microsoft-teams'],
169178
['id' => 2, 'title' => 'Jira', 'slug' => 'jira'],
170179
];
171180
}
172181

173-
protected function getMultipleIntegrationsRequestMock($path, $expectedArray = [], $expectedParameters = []): MockObject
182+
// This method is used to create a mock for the Integrations class.
183+
// NOT A TEST
184+
private function getMultipleIntegrationsRequestMock($path, $expectedArray = [], $expectedParameters = []): MockObject
174185
{
175186
$api = $this->getApiMock();
176187
$api->expects($this->once())
177188
->method('get')
178189
->with($path, $expectedParameters)
179-
->will($this->returnValue($expectedArray));
190+
->willReturn($expectedArray);
180191

181192
return $api;
182193
}

tests/Api/ProjectsTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,14 +2769,17 @@ public function shouldSearchGroups(): void
27692769
#[Test]
27702770
public function shouldGetIntegrations(): void
27712771
{
2772+
$expectedArray = [
2773+
['id' => 1, 'title' => 'Microsoft Teams notifications', 'slug' => 'microsoft-teams'],
2774+
];
27722775
$api = $this->getApiMock();
27732776
$api->expects($this->once())
2774-
->method('put')
2777+
->method('get')
27752778
->with(
27762779
'projects/1/integrations'
27772780
)
2778-
->willReturn([]);
2781+
->willReturn($expectedArray);
27792782

2780-
$this->assertEquals([], $api->integrations(1));
2783+
$this->assertEquals($expectedArray, $api->integrations(1));
27812784
}
27822785
}

0 commit comments

Comments
 (0)