Skip to content

Commit 8daa2dd

Browse files
B8Ym1guelpf
authored andcommitted
Add GroupMilestone Model
1 parent cabc645 commit 8daa2dd

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

lib/Gitlab/Model/GroupMilestone.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Gitlab\Model;
4+
5+
use Gitlab\Client;
6+
7+
/**
8+
* Class GroupMilestone
9+
*
10+
* @property-read int $id
11+
* @property-read int $iid
12+
* @property-read Group $group
13+
* @property-read int $group_id
14+
* @property-read string $title
15+
* @property-read string $description
16+
* @property-read string $state
17+
* @property-read string $created_at
18+
* @property-read string $updated_at
19+
* @property-read string $due_date
20+
* @property-read string $start_date
21+
*/
22+
class GroupMilestone extends AbstractModel
23+
{
24+
/**
25+
* @var array
26+
*/
27+
protected static $properties = array(
28+
'id',
29+
'iid',
30+
'group',
31+
'group_id',
32+
'title',
33+
'description',
34+
'state',
35+
'created_at',
36+
'updated_at',
37+
'due_date',
38+
'start_date'
39+
);
40+
41+
/**
42+
* @param Client $client
43+
* @param Group $group
44+
* @param array $data
45+
* @return GroupMilestone
46+
*/
47+
public static function fromArray(Client $client, Group $group, array $data)
48+
{
49+
$milestone = new static($group, $data['id'], $client);
50+
51+
return $milestone->hydrate($data);
52+
}
53+
54+
/**
55+
* GroupMilestone constructor.
56+
* @param Group $group
57+
* @param $id
58+
* @param Client|null $client
59+
*/
60+
public function __construct(Group $group, $id, Client $client = null)
61+
{
62+
$this->setClient($client);
63+
$this->setData('id', $id);
64+
$this->setData('group', $group);
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Gitlab\Tests\Model;
4+
5+
use Gitlab\Client;
6+
use Gitlab\Model\Group;
7+
use Gitlab\Model\GroupMilestone;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class GroupMilestoneTest extends TestCase
11+
{
12+
public function testConstruct()
13+
{
14+
$client = $this->getMockBuilder(Client::class)
15+
->disableOriginalConstructor()
16+
->getMock();
17+
18+
$group = $this->getMockBuilder(Group::class)
19+
->disableOriginalConstructor()
20+
->getMock();
21+
22+
$groupMilestone = new GroupMilestone($group, 1, $client);
23+
24+
$this->assertSame(1, $groupMilestone->id);
25+
$this->assertSame($group, $groupMilestone->group);
26+
$this->assertSame($client, $groupMilestone->getClient());
27+
}
28+
29+
public function testFromArray()
30+
{
31+
$client = $this->getMockBuilder(Client::class)
32+
->disableOriginalConstructor()
33+
->getMock();
34+
35+
$group = $this->getMockBuilder(Group::class)
36+
->disableOriginalConstructor()
37+
->getMock();
38+
39+
$data = [
40+
'id' => 1,
41+
'iid' => 2,
42+
'group_id' => 3,
43+
'title' => 'Title',
44+
'description' => 'My Group Milestone',
45+
'state' => 'open',
46+
'created_at' => '2019-04-30T23:59:59.000Z',
47+
'updated_at' => '2019-04-30T23:59:59.000Z',
48+
'due_date' => '2019-05-10',
49+
'start_date' => '2019-05-03'
50+
];
51+
52+
$groupMilestone = GroupMilestone::fromArray($client, $group, $data);
53+
54+
$this->assertInstanceOf(GroupMilestone::class, $groupMilestone);
55+
$this->assertSame($data['id'], $groupMilestone->id);
56+
$this->assertSame($data['iid'], $groupMilestone->iid);
57+
$this->assertSame($data['group_id'], $groupMilestone->group_id);
58+
$this->assertSame($data['title'], $groupMilestone->title);
59+
$this->assertSame($data['description'], $groupMilestone->description);
60+
$this->assertSame($data['state'], $groupMilestone->state);
61+
$this->assertSame($data['created_at'], $groupMilestone->created_at);
62+
$this->assertSame($data['updated_at'], $groupMilestone->updated_at);
63+
$this->assertSame($data['due_date'], $groupMilestone->due_date);
64+
$this->assertSame($data['start_date'], $groupMilestone->start_date);
65+
}
66+
}

0 commit comments

Comments
 (0)