|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Acceptance; |
| 4 | + |
| 5 | +use Coding\Core; |
| 6 | +use Coding\Issue; |
| 7 | +use GuzzleHttp\Client; |
| 8 | +use GuzzleHttp\Psr7; |
| 9 | + |
| 10 | +class ArtifactTest extends TestCase |
| 11 | +{ |
| 12 | + public function testUploadAndDownload() |
| 13 | + { |
| 14 | + $teamDomain = getenv('CODING_TEAM_DOMAIN'); |
| 15 | + $projectName = $this->projectName; |
| 16 | + $package = 'status.txt'; |
| 17 | + $version = date('Ymd.Hi.s', time()); |
| 18 | + file_put_contents($package, $version); |
| 19 | + $client = new Client(); |
| 20 | + $body = Psr7\Utils::tryFopen($package, 'r'); |
| 21 | + $url = "https://${teamDomain}-generic.pkg.coding.net/${projectName}/generic/${package}?version=${version}"; |
| 22 | + $auth = [ |
| 23 | + getenv('CODING_USERNAME'), |
| 24 | + getenv('CODING_PASSWORD'), |
| 25 | + ]; |
| 26 | + $response = $client->request('PUT', $url, [ |
| 27 | + 'auth' => $auth, |
| 28 | + 'body' => $body, |
| 29 | + ]); |
| 30 | + $this->assertEquals(200, $response->getStatusCode()); |
| 31 | + |
| 32 | + // Download |
| 33 | + $tmpfname = tempnam(sys_get_temp_dir(), $package); |
| 34 | + $client->request('GET', $url, [ |
| 35 | + 'auth' => $auth, |
| 36 | + 'sink' => $tmpfname, |
| 37 | + ]); |
| 38 | + $this->assertFileEquals($package, $tmpfname); |
| 39 | + } |
| 40 | +} |
0 commit comments