|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit; |
| 4 | + |
| 5 | +use App\Coding\ProjectSetting; |
| 6 | +use GuzzleHttp\Client; |
| 7 | +use GuzzleHttp\Psr7\Response; |
| 8 | +use Tests\TestCase; |
| 9 | + |
| 10 | +class CodingProjectSettingTest extends TestCase |
| 11 | +{ |
| 12 | + public function testGetIssueTypesSuccess() |
| 13 | + { |
| 14 | + $responseBody = file_get_contents($this->dataDir . 'coding/DescribeProjectIssueTypeListResponse.json'); |
| 15 | + $codingToken = $this->faker->md5; |
| 16 | + $codingProjectUri = $this->faker->slug; |
| 17 | + |
| 18 | + $clientMock = $this->getMockBuilder(Client::class)->getMock(); |
| 19 | + $clientMock->expects($this->once()) |
| 20 | + ->method('request') |
| 21 | + ->with( |
| 22 | + 'POST', |
| 23 | + 'https://e.coding.net/open-api', |
| 24 | + [ |
| 25 | + 'headers' => [ |
| 26 | + 'Accept' => 'application/json', |
| 27 | + 'Authorization' => "token ${codingToken}", |
| 28 | + 'Content-Type' => 'application/json' |
| 29 | + ], |
| 30 | + 'json' => array_merge([ |
| 31 | + 'Action' => 'DescribeProjectIssueTypeList', |
| 32 | + 'ProjectName' => $codingProjectUri, |
| 33 | + ]) |
| 34 | + ] |
| 35 | + ) |
| 36 | + ->willReturn(new Response(200, [], $responseBody)); |
| 37 | + $coding = new ProjectSetting($clientMock); |
| 38 | + $result = $coding->getIssueTypes($codingToken, $codingProjectUri); |
| 39 | + $this->assertEquals(json_decode($responseBody, true)['Response']['IssueTypes'], $result); |
| 40 | + } |
| 41 | + |
| 42 | + public function testGetIssueTypeStatusSuccess() |
| 43 | + { |
| 44 | + $responseBody = file_get_contents($this->dataDir . 'coding/DescribeProjectIssueStatusListResponse.json'); |
| 45 | + $codingToken = $this->faker->md5; |
| 46 | + $codingProjectUri = $this->faker->slug; |
| 47 | + |
| 48 | + $issueType = $this->faker->randomElement(['DEFECT', 'REQUIREMENT', 'MISSION', 'EPIC', 'SUB_TASK']); |
| 49 | + $clientMock = $this->getMockBuilder(Client::class)->getMock(); |
| 50 | + $clientMock->expects($this->once()) |
| 51 | + ->method('request') |
| 52 | + ->with( |
| 53 | + 'POST', |
| 54 | + 'https://e.coding.net/open-api', |
| 55 | + [ |
| 56 | + 'headers' => [ |
| 57 | + 'Accept' => 'application/json', |
| 58 | + 'Authorization' => "token ${codingToken}", |
| 59 | + 'Content-Type' => 'application/json' |
| 60 | + ], |
| 61 | + 'json' => array_merge([ |
| 62 | + 'Action' => 'DescribeProjectIssueStatusList', |
| 63 | + 'ProjectName' => $codingProjectUri, |
| 64 | + 'IssueType' => $issueType, |
| 65 | + ]) |
| 66 | + ] |
| 67 | + ) |
| 68 | + ->willReturn(new Response(200, [], $responseBody)); |
| 69 | + $coding = new ProjectSetting($clientMock); |
| 70 | + $result = $coding->getIssueTypeStatus($codingToken, $codingProjectUri, $issueType); |
| 71 | + $this->assertEquals(json_decode($responseBody, true)['Response']['ProjectIssueStatusList'], $result); |
| 72 | + } |
| 73 | +} |
0 commit comments