Skip to content

Commit bb604f5

Browse files
Seretosm1guelpf
authored andcommitted
add environment & deployment class to api + add stop environment function
1 parent 34809fa commit bb604f5

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

lib/Gitlab/Api/Environments.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@ public function remove($project_id, $environment_id)
4545
{
4646
return $this->delete($this->getProjectPath($project_id, 'environments/' . $environment_id));
4747
}
48+
49+
/**
50+
* @param int $project_id
51+
* @param string $environment_id
52+
* @return mixed
53+
*/
54+
public function stop($project_id, $environment_id)
55+
{
56+
return $this->post($this->getProjectPath($project_id, 'environments/'.$this->encodePath($environment_id).'/stop'));
57+
}
4858
}

lib/Gitlab/Client.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@ public function version()
262262
return new Api\Version($this);
263263
}
264264

265+
/**
266+
* @return Api\Deployments
267+
*/
268+
public function deployments()
269+
{
270+
return new Api\Deployments($this);
271+
}
272+
273+
/**
274+
* @return Api\Environments
275+
*/
276+
public function environments()
277+
{
278+
return new Api\Environments($this);
279+
}
280+
265281
/**
266282
* @param string $name
267283
*
@@ -331,6 +347,12 @@ public function api($name)
331347
case 'version':
332348
return $this->version();
333349

350+
case 'environments':
351+
return $this->environments();
352+
353+
case 'deployments':
354+
return $this->deployments();
355+
334356
default:
335357
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');
336358
}

test/Gitlab/Tests/Api/EnvironmentsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ public function shouldRemoveEnvironment()
7373
$this->assertEquals($expectedBool, $api->remove(1, 3));
7474
}
7575

76+
/**
77+
* @test
78+
*/
79+
public function shouldStopEnvironment()
80+
{
81+
$expectedBool = true;
82+
83+
$api = $this->getApiMock();
84+
$api->expects($this->once())
85+
->method('post')
86+
->with('projects/1/environments/3/stop')
87+
->will($this->returnValue($expectedBool));
88+
$this->assertEquals($expectedBool, $api->stop(1, 3));
89+
}
90+
7691
protected function getApiClass()
7792
{
7893
return 'Gitlab\Api\Environments';

0 commit comments

Comments
 (0)