Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 240f90b

Browse files
feat: #78 create iteration
1 parent b2b1de4 commit 240f90b

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

‎app/Coding/Iteration.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Coding;
4+
5+
class Iteration extends Base
6+
{
7+
public function create($token, $projectName, $data)
8+
{
9+
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
10+
'headers' => [
11+
'Accept' => 'application/json',
12+
'Authorization' => "token ${token}",
13+
'Content-Type' => 'application/json'
14+
],
15+
'json' => array_merge([
16+
'Action' => 'CreateIteration',
17+
'ProjectName' => $projectName,
18+
], $data),
19+
]);
20+
$result = json_decode($response->getBody(), true);
21+
return $result['Response']['Iteration'];
22+
}
23+
}

‎tests/Unit/CodingIterationTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use App\Coding\Issue;
6+
use App\Coding\Iteration;
7+
use GuzzleHttp\Client;
8+
use GuzzleHttp\Psr7\Response;
9+
use Tests\TestCase;
10+
11+
class CodingIterationTest extends TestCase
12+
{
13+
public function testCreateSuccess()
14+
{
15+
$responseBody = file_get_contents($this->dataDir . 'coding/CreateIterationResponse.json');
16+
$codingToken = $this->faker->md5;
17+
$codingProjectUri = $this->faker->slug;
18+
$data = [
19+
'Name' => $this->faker->title,
20+
];
21+
22+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
23+
$clientMock->expects($this->once())
24+
->method('request')
25+
->with(
26+
'POST',
27+
'https://e.coding.net/open-api',
28+
[
29+
'headers' => [
30+
'Accept' => 'application/json',
31+
'Authorization' => "token ${codingToken}",
32+
'Content-Type' => 'application/json'
33+
],
34+
'json' => array_merge([
35+
'Action' => 'CreateIteration',
36+
'ProjectName' => $codingProjectUri,
37+
], $data)
38+
]
39+
)
40+
->willReturn(new Response(200, [], $responseBody));
41+
$coding = new Iteration($clientMock);
42+
$result = $coding->create($codingToken, $codingProjectUri, $data);
43+
$this->assertEquals(json_decode($responseBody, true)['Response']['Iteration'], $result);
44+
}
45+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"Response" : {
3+
"Iteration" : {
4+
"Assignee" : 0,
5+
"Code" : 2746,
6+
"CompletedCount" : 0,
7+
"CompletedPercent" : 0,
8+
"Completer" : 0,
9+
"CreatedAt" : 1634697259529,
10+
"Creator" : 183478,
11+
"Deleter" : 0,
12+
"EndAt" : -28800000,
13+
"Goal" : "",
14+
"Name" : "it by cli",
15+
"ProcessingCount" : 0,
16+
"StartAt" : -28800000,
17+
"Starter" : 0,
18+
"Status" : "WAIT_PROCESS",
19+
"UpdatedAt" : 1634697259529,
20+
"WaitProcessCount" : 0
21+
},
22+
"RequestId" : "58777aa6-e6e4-155a-c99f-415a33615ca6"
23+
}
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /