|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit; |
| 4 | + |
| 5 | +use App\Coding\Issue; |
| 6 | +use App\Coding\Iteration; |
| 7 | +use GuzzleHttp\Client; |
| 8 | +use GuzzleHttp\Psr7\Response; |
| 9 | +use Tests\TestCase; |
| 10 | + |
| 11 | +class CodingIterationTest extends TestCase |
| 12 | +{ |
| 13 | + public function testCreateSuccess() |
| 14 | + { |
| 15 | + $responseBody = file_get_contents($this->dataDir . 'coding/CreateIterationResponse.json'); |
| 16 | + $codingToken = $this->faker->md5; |
| 17 | + $codingProjectUri = $this->faker->slug; |
| 18 | + $data = [ |
| 19 | + 'Name' => $this->faker->title, |
| 20 | + ]; |
| 21 | + |
| 22 | + $clientMock = $this->getMockBuilder(Client::class)->getMock(); |
| 23 | + $clientMock->expects($this->once()) |
| 24 | + ->method('request') |
| 25 | + ->with( |
| 26 | + 'POST', |
| 27 | + 'https://e.coding.net/open-api', |
| 28 | + [ |
| 29 | + 'headers' => [ |
| 30 | + 'Accept' => 'application/json', |
| 31 | + 'Authorization' => "token ${codingToken}", |
| 32 | + 'Content-Type' => 'application/json' |
| 33 | + ], |
| 34 | + 'json' => array_merge([ |
| 35 | + 'Action' => 'CreateIteration', |
| 36 | + 'ProjectName' => $codingProjectUri, |
| 37 | + ], $data) |
| 38 | + ] |
| 39 | + ) |
| 40 | + ->willReturn(new Response(200, [], $responseBody)); |
| 41 | + $coding = new Iteration($clientMock); |
| 42 | + $result = $coding->create($codingToken, $codingProjectUri, $data); |
| 43 | + $this->assertEquals(json_decode($responseBody, true)['Response']['Iteration'], $result); |
| 44 | + } |
| 45 | +} |
0 commit comments