|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature; |
| 4 | + |
| 5 | +use App\Coding\Issue; |
| 6 | +use Tests\TestCase; |
| 7 | + |
| 8 | +class IssueCreateCommandTest extends TestCase |
| 9 | +{ |
| 10 | + private string $codingToken; |
| 11 | + private string $codingTeamDomain; |
| 12 | + private string $codingProjectUri; |
| 13 | + |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + $this->codingToken = $this->faker->md5; |
| 18 | + config(['coding.token' => $this->codingToken]); |
| 19 | + $this->codingTeamDomain = $this->faker->domainWord; |
| 20 | + config(['coding.team_domain' => $this->codingTeamDomain]); |
| 21 | + $this->codingProjectUri = $this->faker->slug; |
| 22 | + config(['coding.project_uri' => $this->codingProjectUri]); |
| 23 | + } |
| 24 | + |
| 25 | + public function testCreateSuccess() |
| 26 | + { |
| 27 | + $mock = \Mockery::mock(Issue::class, [])->makePartial(); |
| 28 | + $this->instance(Issue::class, $mock); |
| 29 | + |
| 30 | + $mock->shouldReceive('create')->times(1)->andReturn(json_decode( |
| 31 | + file_get_contents($this->dataDir . 'coding/' . 'CreateIssueResponse.json'), |
| 32 | + true |
| 33 | + )['Response']['Issue']); |
| 34 | + |
| 35 | + $this->artisan('issue:create') |
| 36 | + ->expectsQuestion('类型:', 'REQUIREMENT') |
| 37 | + ->expectsQuestion('标题:', $this->faker->title) |
| 38 | + ->expectsOutput('创建成功') |
| 39 | + ->expectsOutput("https://$this->codingTeamDomain.coding.net/p/$this->codingProjectUri/all/issues/2742") |
| 40 | + ->assertExitCode(0); |
| 41 | + } |
| 42 | + |
| 43 | + public function testCreateFailed() |
| 44 | + { |
| 45 | + $mock = \Mockery::mock(Issue::class, [])->makePartial(); |
| 46 | + $this->instance(Issue::class, $mock); |
| 47 | + |
| 48 | + $mock->shouldReceive('create')->times(1)->andThrow(\Exception::class, json_decode( |
| 49 | + file_get_contents($this->dataDir . 'coding/' . 'CreateIssueFailedResponse.json'), |
| 50 | + true |
| 51 | + )['Response']['Error']['Message']); |
| 52 | + |
| 53 | + $this->artisan('issue:create') |
| 54 | + ->expectsQuestion('类型:', 'REQUIREMENT') |
| 55 | + ->expectsQuestion('标题:', $this->faker->title) |
| 56 | + ->expectsOutput('Error: issue_custom_field_required') |
| 57 | + ->assertExitCode(1); |
| 58 | + } |
| 59 | +} |
0 commit comments