Skip to content

Commit

Permalink
refactor: #72 rename to project setting
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 21, 2021
1 parent 1a31bd8 commit a3576b5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/Coding/Project.php → app/Coding/ProjectSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Coding;

class Project extends Base
class ProjectSetting extends Base
{
public function getIssueTypes($token, $projectName)
{
Expand Down
14 changes: 7 additions & 7 deletions app/Commands/IssueImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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'],
Expand Down
6 changes: 3 additions & 3 deletions app/Commands/ProjectGetIssueTypesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']);
Expand Down
18 changes: 9 additions & 9 deletions tests/Feature/IssueImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'])
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/ProjectGetIssueTypesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature;

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

class ProjectGetIssueTypesCommandTest extends TestCase
Expand All @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/CodingProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a3576b5

Please sign in to comment.