-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Coding; | ||
|
||
class Iteration extends Base | ||
{ | ||
public function create($token, $projectName, $data) | ||
{ | ||
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => "token ${token}", | ||
'Content-Type' => 'application/json' | ||
], | ||
'json' => array_merge([ | ||
'Action' => 'CreateIteration', | ||
'ProjectName' => $projectName, | ||
], $data), | ||
]); | ||
$result = json_decode($response->getBody(), true); | ||
return $result['Response']['Iteration']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use App\Coding\Issue; | ||
use App\Coding\Iteration; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Psr7\Response; | ||
use Tests\TestCase; | ||
|
||
class CodingIterationTest extends TestCase | ||
{ | ||
public function testCreateSuccess() | ||
{ | ||
$responseBody = file_get_contents($this->dataDir . 'coding/CreateIterationResponse.json'); | ||
$codingToken = $this->faker->md5; | ||
$codingProjectUri = $this->faker->slug; | ||
$data = [ | ||
'Name' => $this->faker->title, | ||
]; | ||
|
||
$clientMock = $this->getMockBuilder(Client::class)->getMock(); | ||
$clientMock->expects($this->once()) | ||
->method('request') | ||
->with( | ||
'POST', | ||
'https://e.coding.net/open-api', | ||
[ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => "token ${codingToken}", | ||
'Content-Type' => 'application/json' | ||
], | ||
'json' => array_merge([ | ||
'Action' => 'CreateIteration', | ||
'ProjectName' => $codingProjectUri, | ||
], $data) | ||
] | ||
) | ||
->willReturn(new Response(200, [], $responseBody)); | ||
$coding = new Iteration($clientMock); | ||
$result = $coding->create($codingToken, $codingProjectUri, $data); | ||
$this->assertEquals(json_decode($responseBody, true)['Response']['Iteration'], $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"Response" : { | ||
"Iteration" : { | ||
"Assignee" : 0, | ||
"Code" : 2746, | ||
"CompletedCount" : 0, | ||
"CompletedPercent" : 0, | ||
"Completer" : 0, | ||
"CreatedAt" : 1634697259529, | ||
"Creator" : 183478, | ||
"Deleter" : 0, | ||
"EndAt" : -28800000, | ||
"Goal" : "", | ||
"Name" : "it by cli", | ||
"ProcessingCount" : 0, | ||
"StartAt" : -28800000, | ||
"Starter" : 0, | ||
"Status" : "WAIT_PROCESS", | ||
"UpdatedAt" : 1634697259529, | ||
"WaitProcessCount" : 0 | ||
}, | ||
"RequestId" : "58777aa6-e6e4-155a-c99f-415a33615ca6" | ||
} | ||
} |