|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature; |
| 4 | + |
| 5 | +use App\Coding\Iteration; |
| 6 | +use Carbon\Carbon; |
| 7 | +use Tests\TestCase; |
| 8 | + |
| 9 | +class IterationCreateCommandTest extends TestCase |
| 10 | +{ |
| 11 | + private string $teamDomain; |
| 12 | + private string $projectUri; |
| 13 | + |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + $codingToken = $this->faker->md5; |
| 18 | + config(['coding.token' => $codingToken]); |
| 19 | + $this->teamDomain = $this->faker->domainWord; |
| 20 | + config(['coding.team_domain' => $this->teamDomain]); |
| 21 | + $this->projectUri = $this->faker->slug; |
| 22 | + config(['coding.project_uri' => $this->projectUri]); |
| 23 | + } |
| 24 | + |
| 25 | + public function testCreateSuccess() |
| 26 | + { |
| 27 | + $mock = \Mockery::mock(Iteration::class, [])->makePartial(); |
| 28 | + $this->instance(Iteration::class, $mock); |
| 29 | + |
| 30 | + $mock->shouldReceive('create')->times(1)->andReturn(json_decode( |
| 31 | + file_get_contents($this->dataDir . 'coding/' . 'CreateIterationResponse.json'), |
| 32 | + true |
| 33 | + )['Response']['Iteration']); |
| 34 | + |
| 35 | + $startAt = $this->faker->date(); |
| 36 | + $endAt = Carbon::parse($startAt)->addDays($this->faker->randomNumber())->toDateString(); |
| 37 | + $this->artisan('iteration:create', [ |
| 38 | + '--goal' => $this->faker->text(), |
| 39 | + '--assignee' => $this->faker->randomNumber(), |
| 40 | + ]) |
| 41 | + ->expectsQuestion('开始时间:', $startAt) |
| 42 | + ->expectsQuestion('结束时间:', $endAt) |
| 43 | + ->expectsQuestion('标题:', $startAt . '~' . $endAt . ' 迭代') |
| 44 | + ->expectsOutput('创建成功') |
| 45 | + ->expectsOutput("https://$this->teamDomain.coding.net/p/$this->projectUri/iterations/2746/issues") |
| 46 | + ->assertExitCode(0); |
| 47 | + } |
| 48 | +} |
0 commit comments