From 27bf9be93361124336f76f253c873729afe28d27 Mon Sep 17 00:00:00 2001 From: sinkcup Date: Thu, 21 Oct 2021 15:37:24 +0800 Subject: [PATCH] refactor: #72 rename to project setting --- app/Coding/{Project.php => ProjectSetting.php} | 2 +- app/Commands/IssueImportCommand.php | 14 +++++++------- app/Commands/ProjectGetIssueTypesCommand.php | 6 +++--- tests/Feature/IssueImportCommandTest.php | 18 +++++++++--------- .../ProjectGetIssueTypesCommandTest.php | 6 +++--- tests/Unit/CodingProjectTest.php | 4 ++-- 6 files changed, 25 insertions(+), 25 deletions(-) rename app/Coding/{Project.php => ProjectSetting.php} (95%) diff --git a/app/Coding/Project.php b/app/Coding/ProjectSetting.php similarity index 95% rename from app/Coding/Project.php rename to app/Coding/ProjectSetting.php index 49eebc0..ecfaa48 100644 --- a/app/Coding/Project.php +++ b/app/Coding/ProjectSetting.php @@ -2,7 +2,7 @@ namespace App\Coding; -class Project extends Base +class ProjectSetting extends Base { public function getIssueTypes($token, $projectName) { diff --git a/app/Commands/IssueImportCommand.php b/app/Commands/IssueImportCommand.php index 01bd96c..5049e0a 100644 --- a/app/Commands/IssueImportCommand.php +++ b/app/Commands/IssueImportCommand.php @@ -4,7 +4,7 @@ use App\Coding\Issue; use App\Coding\Iteration; -use App\Coding\Project; +use App\Coding\ProjectSetting; use Exception; use LaravelZero\Framework\Commands\Command; use Rap2hpoutre\FastExcel\Facades\FastExcel; @@ -41,7 +41,7 @@ class IssueImportCommand extends Command * Execute the console command. * */ - public function handle(Issue $codingIssue, Project $codingProject, Iteration $iteration): int + public function handle(Issue $codingIssue, ProjectSetting $projectSetting, Iteration $iteration): int { $this->setCodingApi(); @@ -57,7 +57,7 @@ public function handle(Issue $codingIssue, Project $codingProject, Iteration $it } foreach ($rows as $row) { try { - $issueResult = $this->createIssueByRow($codingProject, $codingIssue, $iteration, $row); + $issueResult = $this->createIssueByRow($projectSetting, $codingIssue, $iteration, $row); } catch (Exception $e) { $this->error('Error: ' . $e->getMessage()); return 1; @@ -70,10 +70,10 @@ public function handle(Issue $codingIssue, Project $codingProject, Iteration $it return 0; } - private function getIssueTypes(Project $codingProject, $row): void + private function getIssueTypes(ProjectSetting $projectSetting, array $row): void { if (empty($this->issueTypes)) { - $result = $codingProject->getIssueTypes($this->codingToken, $this->codingProjectUri); + $result = $projectSetting->getIssueTypes($this->codingToken, $this->codingProjectUri); foreach ($result as $item) { $this->issueTypes[$item['Name']] = $item; } @@ -83,9 +83,9 @@ private function getIssueTypes(Project $codingProject, $row): void } } - private function createIssueByRow(Project $codingProject, Issue $issue, Iteration $iteration, array $row) + private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue, Iteration $iteration, array $row) { - $this->getIssueTypes($codingProject, $row); + $this->getIssueTypes($projectSetting, $row); $data = [ 'Type' => $this->issueTypes[$row['事项类型']]['IssueType'], 'IssueTypeId' => $this->issueTypes[$row['事项类型']]['Id'], diff --git a/app/Commands/ProjectGetIssueTypesCommand.php b/app/Commands/ProjectGetIssueTypesCommand.php index 011b3e8..10e1abd 100644 --- a/app/Commands/ProjectGetIssueTypesCommand.php +++ b/app/Commands/ProjectGetIssueTypesCommand.php @@ -3,7 +3,7 @@ namespace App\Commands; use App\Coding\Issue; -use App\Coding\Project; +use App\Coding\ProjectSetting; use LaravelZero\Framework\Commands\Command; class ProjectGetIssueTypesCommand extends Command @@ -32,11 +32,11 @@ class ProjectGetIssueTypesCommand extends Command * Execute the console command. * */ - public function handle(Project $codingProject): int + public function handle(ProjectSetting $projectSetting): int { $this->setCodingApi(); - $result = $codingProject->getIssueTypes($this->codingToken, $this->codingProjectUri); + $result = $projectSetting->getIssueTypes($this->codingToken, $this->codingProjectUri); foreach ($result as $item) { $this->info($item['Id'] . ' ' . $item['Name']); diff --git a/tests/Feature/IssueImportCommandTest.php b/tests/Feature/IssueImportCommandTest.php index 13f6990..7d7d501 100755 --- a/tests/Feature/IssueImportCommandTest.php +++ b/tests/Feature/IssueImportCommandTest.php @@ -4,7 +4,7 @@ use App\Coding\Issue; use App\Coding\Iteration; -use App\Coding\Project; +use App\Coding\ProjectSetting; use Tests\TestCase; class IssueImportCommandTest extends TestCase @@ -26,8 +26,8 @@ protected function setUp(): void public function testImportSuccess() { - $mock = \Mockery::mock(Project::class, [])->makePartial(); - $this->instance(Project::class, $mock); + $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $mock); $mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'), @@ -66,8 +66,8 @@ public function testImportSuccess() public function testImportUserStorySuccess() { - $mock = \Mockery::mock(Project::class, [])->makePartial(); - $this->instance(Project::class, $mock); + $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $mock); $mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'), @@ -113,8 +113,8 @@ public function testImportUserStorySuccess() public function testImportSubTask() { - $mock = \Mockery::mock(Project::class, [])->makePartial(); - $this->instance(Project::class, $mock); + $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $mock); $mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'), @@ -179,8 +179,8 @@ public function testImportSubTask() public function testImportFailedIssueTypeNotExists() { - $mock = \Mockery::mock(Project::class, [])->makePartial(); - $this->instance(Project::class, $mock); + $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $mock); $mock->shouldReceive('getIssueTypes')->times(1)->andReturn([]); $this->artisan('issue:import', ['file' => $this->dataDir . 'coding/scrum-issues.csv']) diff --git a/tests/Feature/ProjectGetIssueTypesCommandTest.php b/tests/Feature/ProjectGetIssueTypesCommandTest.php index 1e8b18f..e900124 100755 --- a/tests/Feature/ProjectGetIssueTypesCommandTest.php +++ b/tests/Feature/ProjectGetIssueTypesCommandTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use App\Coding\Project; +use App\Coding\ProjectSetting; use Tests\TestCase; class ProjectGetIssueTypesCommandTest extends TestCase @@ -20,8 +20,8 @@ protected function setUp(): void public function testCreateSuccess() { - $mock = \Mockery::mock(Project::class, [])->makePartial(); - $this->instance(Project::class, $mock); + $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $mock); $mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'), diff --git a/tests/Unit/CodingProjectTest.php b/tests/Unit/CodingProjectTest.php index 5052483..c49ba83 100644 --- a/tests/Unit/CodingProjectTest.php +++ b/tests/Unit/CodingProjectTest.php @@ -2,7 +2,7 @@ namespace Tests\Unit; -use App\Coding\Project; +use App\Coding\ProjectSetting; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Response; use Tests\TestCase; @@ -34,7 +34,7 @@ public function testCreateSuccess() ] ) ->willReturn(new Response(200, [], $responseBody)); - $coding = new Project($clientMock); + $coding = new ProjectSetting($clientMock); $result = $coding->getIssueTypes($codingToken, $codingProjectUri); $this->assertEquals(json_decode($responseBody, true)['Response']['IssueTypes'], $result); }