Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/Api/GroupsEpics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <[email protected]>
* (c) Graham Campbell <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gitlab\Api;

class GroupsEpics extends AbstractApi
{
/**
* @var string
*/
public const STATE_ACTIVE = 'active';

/**
* @var string
*/
public const STATE_CLOSED = 'closed';

/**
* @param int|string $group_id
* @param array $parameters {
*
* @var int[] $iids return only the epics having the given iids
* @var string $state return only active or closed epics
* @var string $search Return only epics with a title or description matching the provided string.
* }
*
* @return mixed
*/
public function all($group_id, array $parameters = [])
{
$resolver = $this->createOptionsResolver();
$resolver->setDefined('iids')
->setAllowedTypes('iids', 'array')
->setAllowedValues('iids', function (array $value) {
return \count($value) === \count(\array_filter($value, 'is_int'));
})
;
$resolver->setDefined('state')
->setAllowedValues('state', [self::STATE_ACTIVE, self::STATE_CLOSED])
;
$resolver->setDefined('search');

return $this->get('groups/'.self::encodePath($group_id).'/epics', $resolver->resolve($parameters));
}

/**
* @param int|string $group_id
* @param int $epic_id
*
* @return mixed
*/
public function show($group_id, int $epic_id)
{
return $this->get('groups/'.self::encodePath($group_id).'/epics/'.self::encodePath($epic_id));
}

/**
* @param int|string $group_id
* @param array $params
*
* @return mixed
*/
public function create($group_id, array $params)
{
return $this->post('groups/'.self::encodePath($group_id).'/epics', $params);
}

/**
* @param int|string $group_id
* @param int $epic_id
* @param array $params
*
* @return mixed
*/
public function update($group_id, int $epic_id, array $params)
{
return $this->put('groups/'.self::encodePath($group_id).'/epics/'.self::encodePath($epic_id), $params);
}

/**
* @param int|string $group_id
* @param int $epic_id
*
* @return mixed
*/
public function remove($group_id, int $epic_id)
{
return $this->delete('groups/'.self::encodePath($group_id).'/epics/'.self::encodePath($epic_id));
}
}
9 changes: 9 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Gitlab\Api\Environments;
use Gitlab\Api\Groups;
use Gitlab\Api\GroupsBoards;
use Gitlab\Api\GroupsEpics;
use Gitlab\Api\GroupsMilestones;
use Gitlab\Api\IssueBoards;
use Gitlab\Api\IssueLinks;
Expand Down Expand Up @@ -177,6 +178,14 @@ public function groupsBoards(): GroupsBoards
return new GroupsBoards($this);
}

/**
* @return GroupsEpics
*/
public function groupsEpics(): GroupsEpics
{
return new GroupsEpics($this);
}

/**
* @return GroupsMilestones
*/
Expand Down
113 changes: 113 additions & 0 deletions tests/Api/GroupsEpicsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <[email protected]>
* (c) Graham Campbell <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gitlab\Tests\Api;

use Gitlab\Api\GroupsEpics;

class GroupsEpicsTest extends TestCase
{
/**
* @test
*/
public function shouldGetAllEpics(): void
{
$expectedArray = [
['id' => 1, 'title' => 'A epic'],
['id' => 2, 'title' => 'Another epic'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('groups/1/epics')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->all(1));
}

/**
* @test
*/
public function shouldShowEpic(): void
{
$expectedArray = ['id' => 1, 'name' => 'A epic'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('groups/1/epics/2')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->show(1, 2));
}

/**
* @test
*/
public function shouldCreateEpic(): void
{
$expectedArray = ['id' => 3, 'title' => 'A new epic'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('groups/1/epics', ['description' => 'Some text', 'title' => 'A new epic'])
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->create(1, ['description' => 'Some text', 'title' => 'A new epic']));
}

/**
* @test
*/
public function shouldUpdateEpic(): void
{
$expectedArray = ['id' => 3, 'title' => 'Updated epic'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('groups/1/epics/3', ['title' => 'Updated epic', 'description' => 'Updated description', 'state_event' => 'close'])
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->update(1, 3, ['title' => 'Updated epic', 'description' => 'Updated description', 'state_event' => 'close']));
}

/**
* @test
*/
public function shouldRemoveEpic(): void
{
$expectedBool = true;

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('groups/1/epics/2')
->will($this->returnValue($expectedBool))
;

$this->assertEquals($expectedBool, $api->remove(1, 2));
}

protected function getApiClass()
{
return GroupsEpics::class;
}
}