feat: #75 get project issue types by shaunthegeek · Pull Request #76 · coding/coding-cli · GitHub
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
25 changes: 25 additions & 0 deletions app/Coding/Project.php
47 changes: 47 additions & 0 deletions app/Commands/ProjectGetIssueTypesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Commands;

use App\Coding\Issue;
use App\Coding\Project;
use LaravelZero\Framework\Commands\Command;

class ProjectGetIssueTypesCommand extends Command
{
use WithCoding;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'project:get-issue-types
{--coding_token= : CODING 令牌}
{--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx}
{--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy}
';

/**
* The description of the command.
*
* @var string
*/
protected $description = '获取项目下的事项类型';

/**
* Execute the console command.
*
*/
public function handle(Project $codingProject): int
{
$this->setCodingApi();

$result = $codingProject->getIssueTypes($this->codingToken, $this->codingProjectUri);

foreach ($result as $item) {
$this->info($item['Id'] . ' ' . $item['Name']);
}

return 0;
}
}
39 changes: 39 additions & 0 deletions tests/Feature/ProjectGetIssueTypesCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Tests\Feature;

use App\Coding\Project;
use Tests\TestCase;

class ProjectGetIssueTypesCommandTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$codingToken = $this->faker->md5;
config(['coding.token' => $codingToken]);
$codingTeamDomain = $this->faker->domainWord;
config(['coding.team_domain' => $codingTeamDomain]);
$codingProjectUri = $this->faker->slug;
config(['coding.project_uri' => $codingProjectUri]);
}

public function testCreateSuccess()
{
$mock = \Mockery::mock(Project::class, [])->makePartial();
$this->instance(Project::class, $mock);

$mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode(
file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'),
true
)['Response']['IssueTypes']);

$this->artisan('project:get-issue-types')
->expectsOutput('213217 史诗')
->expectsOutput('213218 用户故事')
->expectsOutput('213220 任务')
->expectsOutput('213221 缺陷')
->expectsOutput('213222 子工作项')
->assertExitCode(0);
}
}
41 changes: 41 additions & 0 deletions tests/Unit/CodingProjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Tests\Unit;

use App\Coding\Project;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Tests\TestCase;

class CodingProjectTest extends TestCase
{
public function testCreateSuccess()
{
$responseBody = file_get_contents($this->dataDir . 'coding/DescribeProjectIssueTypeListResponse.json');
$codingToken = $this->faker->md5;
$codingProjectUri = $this->faker->slug;

$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' => 'DescribeProjectIssueTypeList',
'ProjectName' => $codingProjectUri,
])
]
)
->willReturn(new Response(200, [], $responseBody));
$coding = new Project($clientMock);
$result = $coding->getIssueTypes($codingToken, $codingProjectUri);
$this->assertEquals(json_decode($responseBody, true)['Response']['IssueTypes'], $result);
}
}
52 changes: 52 additions & 0 deletions tests/data/coding/DescribeProjectIssueTypeListResponse.json