Skip to content

Commit 8e06ea2

Browse files
committed
revised SprintService
1 parent a27079b commit 8e06ea2

3 files changed

Lines changed: 148 additions & 52 deletions

File tree

src/Sprint/Sprint.php

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,64 @@
1-
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: meshulam
5-
* Date: 23/09/2017
6-
* Time: 14:17.
7-
*/
1+
<?php declare(strict_types=1);
82

93
namespace JiraCloud\Sprint;
104

5+
use DateTimeInterface;
116
use JiraCloud\JsonSerializableTrait;
127

138
class Sprint implements \JsonSerializable
149
{
1510
use JsonSerializableTrait;
1611

17-
/* @var string */
18-
public $self;
12+
public string $self;
1913

20-
/* @var int */
21-
public $id;
14+
public int $id;
2215

23-
/* @var string */
24-
public $name;
16+
public string $name;
2517

26-
/* @var string */
27-
public $state;
18+
public string $state;
19+
public string $startDate;
2820

29-
/* @var string */
30-
public $startDate;
21+
public string $endDate;
3122

32-
/* @var string */
33-
public $endDate;
23+
public string $activatedDate;
3424

35-
/* @var string */
36-
public $completeDate;
25+
public string $completeDate;
3726

38-
/* @var int */
39-
public $originBoardId;
27+
public int $originBoardId;
4028

41-
/** @var string */
42-
public $goal;
29+
public string $goal;
4330

44-
public function setName(string $sprintName): string
31+
public function setNameAsString(string $sprintName): self
4532
{
4633
$this->name = $sprintName;
4734

48-
return $sprintName;
35+
return $this;
4936
}
5037

51-
public function getName(): string
38+
public function setGoalAsString(string $sprintGoal): self
5239
{
53-
return $this->name;
40+
$this->goal = $sprintGoal;
41+
42+
return $this;
43+
}
44+
45+
public function setOriginBoardIdAsStringOrInt(string|int $originBoardId) : self
46+
{
47+
$this->originBoardId = $originBoardId;
48+
49+
return $this;
50+
}
51+
public function setStartDateAsDateTime(DateTimeInterface $startDate, $format = 'Y-m-d'): static
52+
{
53+
$this->startDate = $startDate->format($format);
54+
55+
return $this;
56+
}
57+
58+
public function setEndDateAsDateTime(DateTimeInterface $endDate, $format = 'Y-m-d'): static
59+
{
60+
$this->endDate = $endDate->format($format);
61+
62+
return $this;
5463
}
5564
}

src/Sprint/SprintService.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: meshulam
5-
* Date: 11/08/2017
6-
* Time: 17:28.
7-
*/
2+
3+
declare(strict_types=1);
84

95
namespace JiraCloud\Sprint;
106

@@ -16,7 +12,6 @@
1612

1713
class SprintService extends JiraClient
1814
{
19-
//https://jira01.devtools.intel.com/rest/agile/1.0/board?projectKeyOrId=34012
2015
private $uri = '/sprint';
2116

2217
public function __construct(ConfigurationInterface $configuration = null, LoggerInterface $logger = null, $path = './')
@@ -32,7 +27,7 @@ public function __construct(ConfigurationInterface $configuration = null, Logger
3227
*
3328
* @return Sprint
3429
*/
35-
public function getSprintFromJSON($json)
30+
public function getSprintFromJSON(object $json) : Sprint
3631
{
3732
$sprint = $this->json_mapper->map(
3833
$json,
@@ -42,38 +37,26 @@ public function getSprintFromJSON($json)
4237
return $sprint;
4338
}
4439

45-
/**
46-
* get all Sprint list.
47-
*
48-
* @param string $sprintId
49-
*
50-
* @throws JiraException
51-
* @throws \JsonMapper_Exception
52-
*
53-
* @return Sprint
54-
*/
55-
public function getSprint(string $sprintId)
40+
public function getSprint(string|int $sprintId) :Sprint
5641
{
5742
$ret = $this->exec($this->uri.'/'.$sprintId, null);
5843

5944
$this->log->info("Result=\n".$ret);
6045

61-
return $sprint = $this->json_mapper->map(
46+
return $this->json_mapper->map(
6247
json_decode($ret),
6348
new Sprint()
6449
);
6550
}
6651

6752
/**
68-
* @param string|int $sprintId
69-
* @param array $paramArray
7053
*
7154
* @throws JiraException
7255
* @throws \JsonMapper_Exception
7356
*
7457
* @return Issue[] array of Issue
7558
*/
76-
public function getSprintIssues($sprintId, $paramArray = [])
59+
public function getSprintIssues(string|int $sprintId, array $paramArray = [])
7760
{
7861
$json = $this->exec($this->uri.'/'.$sprintId.'/issue'.$this->toHttpQueryParameter($paramArray), null);
7962

@@ -85,4 +68,18 @@ public function getSprintIssues($sprintId, $paramArray = [])
8568

8669
return $issues;
8770
}
71+
72+
public function createSprint(Sprint $sprint) : Sprint
73+
{
74+
$data = json_encode($sprint);
75+
76+
$ret = $this->exec($this->uri, $data);
77+
78+
$this->log->debug('createSprint result='.var_export($ret, true));
79+
80+
return $this->json_mapper->map(
81+
json_decode($ret),
82+
new Sprint()
83+
);
84+
}
8885
}

tests/SPrintTest.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace JiraCloud\Test;
4+
5+
use DateInterval;
6+
use DateTime;
7+
use JiraCloud\Sprint\Sprint;
8+
use JiraCloud\Sprint\SprintService;
9+
use PHPUnit\Framework\TestCase;
10+
use JiraCloud\Dumper;
11+
use JiraCloud\Issue\Comment;
12+
use JiraCloud\Issue\IssueService;
13+
use JiraCloud\JiraException;
14+
15+
class SPrintTest extends TestCase
16+
{
17+
/**
18+
* @test
19+
*
20+
*/
21+
public function create_sprint() : int
22+
{
23+
$start = (new DateTime('NOW'))->add(DateInterval::createFromDateString('1 month 5 day'));
24+
25+
$sp = (new Sprint())
26+
->setNameAsString("My Sprint 1")
27+
->setGoalAsString("goal")
28+
->setOriginBoardIdAsStringOrInt(2)
29+
->setStartDateAsDateTime($start)
30+
->setEndDateAsDateTime($start->add(DateInterval::createFromDateString('3 week')))
31+
;
32+
33+
try {
34+
$sps = new SprintService();
35+
36+
$sprint = $sps->createSprint($sp);
37+
38+
$this->assertNotNull($sprint->name);
39+
40+
return $sprint->id;
41+
42+
} catch (JiraException $e) {
43+
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
44+
}
45+
}
46+
47+
/**
48+
* @test
49+
*
50+
* @depends create_sprint
51+
*
52+
* @throws \JsonMapper_Exception
53+
*/
54+
public function get_sprints(int $sprintId) : int
55+
{
56+
try {
57+
$sps = new SprintService();
58+
59+
$sprint = $sps->getSprint($sprintId);
60+
61+
$this->assertNotNull($sprint->name);
62+
Dumper::dump($sprint);
63+
64+
return $sprintId;
65+
} catch (JiraException $e) {
66+
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
67+
}
68+
}
69+
70+
/**
71+
* @test
72+
* @depends get_sprints
73+
*
74+
* @param int $sprintId
75+
* @return void
76+
*/
77+
public function get_issues_in_sprints(int $sprintId)
78+
{
79+
try {
80+
$sps = new SprintService();
81+
82+
$sprint = $sps->getSprintIssues($sprintId);
83+
84+
$this->assertNotNull($sprint);
85+
Dumper::dump($sprint);
86+
} catch (JiraException $e) {
87+
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)