|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * @package PHP Prefixer REST API CLI |
| 5 | + * |
| 6 | + * @author Desarrollos Inteligentes Virtuales, SL. <team@div.com.es> |
| 7 | + * @copyright Copyright (c)2019-2021 Desarrollos Inteligentes Virtuales, SL. All rights reserved. |
| 8 | + * @license MIT |
| 9 | + * |
| 10 | + * @see https://php-prefixer.com |
| 11 | + */ |
| 12 | + |
| 13 | +namespace Tests\Commands; |
| 14 | + |
| 15 | +use App\Support\PrefixerClient; |
| 16 | +use Tests\TestCase; |
| 17 | + |
| 18 | +/** |
| 19 | + * @coversNothing |
| 20 | + */ |
| 21 | +final class PrefixerClientTest extends TestCase |
| 22 | +{ |
| 23 | + public function testIsAuthenticated() |
| 24 | + { |
| 25 | + $this->assertTrue($this->apiClient()->IsAuthenticated()); |
| 26 | + |
| 27 | + $personalAccessToken = env('INVALID_PERSONAL_ACCESS_TOKEN'); |
| 28 | + $prefixerClient = (new PrefixerClient())->authenticate($personalAccessToken); |
| 29 | + $this->expectExceptionCode(401); |
| 30 | + $prefixerClient->IsAuthenticated(); |
| 31 | + } |
| 32 | + |
| 33 | + public function testUser() |
| 34 | + { |
| 35 | + $response = $this->apiClient()->user(); |
| 36 | + $this->assertGreaterThan(0, $response->user->id); |
| 37 | + } |
| 38 | + |
| 39 | + public function testProject() |
| 40 | + { |
| 41 | + $projectId = (int) env('PROJECT_ID'); |
| 42 | + |
| 43 | + $response = $this->apiClient()->project($projectId); |
| 44 | + $this->assertSame($projectId, $response->project->id); |
| 45 | + |
| 46 | + $this->expectExceptionCode(404); |
| 47 | + $this->apiClient()->project(404); |
| 48 | + } |
| 49 | + |
| 50 | + public function testCreateBuild() |
| 51 | + { |
| 52 | + } |
| 53 | + |
| 54 | + public function testBuild() |
| 55 | + { |
| 56 | + $projectId = (int) env('PROJECT_ID'); |
| 57 | + $buildId = (int) env('TEST_BUILD_ID'); |
| 58 | + $response = $this->apiClient()->build($projectId, $buildId); |
| 59 | + |
| 60 | + $this->assertSame($buildId, $response->build->id); |
| 61 | + |
| 62 | + $this->expectExceptionCode(404); |
| 63 | + $this->apiClient()->build($projectId, 404); |
| 64 | + } |
| 65 | + |
| 66 | + public function testDownload() |
| 67 | + { |
| 68 | + $projectId = (int) env('PROJECT_ID'); |
| 69 | + $buildId = (int) env('TEST_BUILD_ID'); |
| 70 | + $response = $this->apiClient()->download($projectId, $buildId); |
| 71 | + |
| 72 | + $this->assertSame(200, $response->getStatusCode()); |
| 73 | + $this->assertTrue(\in_array('application/x-zip', $response->getHeader('Content-Type'), true)); |
| 74 | + |
| 75 | + $this->expectExceptionCode(404); |
| 76 | + $this->apiClient()->download($projectId, 404); |
| 77 | + } |
| 78 | + |
| 79 | + public function testLogDownload() |
| 80 | + { |
| 81 | + $projectId = (int) env('PROJECT_ID'); |
| 82 | + $buildId = (int) env('TEST_BUILD_ID'); |
| 83 | + |
| 84 | + $tmpFile = tempnam(getcwd(), 'ppp'); |
| 85 | + $response = $this->apiClient()->downloadLog($projectId, $buildId, $tmpFile); |
| 86 | + |
| 87 | + $this->assertSame(200, $response->getStatusCode()); |
| 88 | + $this->assertTrue(\in_array('application/x-zip', $response->getHeader('Content-Type'), true)); |
| 89 | + |
| 90 | + $contentDisposition = $response->getHeader('Content-Disposition'); |
| 91 | + list(, $filename) = explode('filename=', $contentDisposition[0]); |
| 92 | + $this->assertStringEndsWith('.log.zip', $filename); |
| 93 | + |
| 94 | + unlink($tmpFile); |
| 95 | + |
| 96 | + $this->expectExceptionCode(404); |
| 97 | + $this->apiClient()->downloadLog($projectId, 404, $tmpFile); |
| 98 | + } |
| 99 | + |
| 100 | + private function apiClient() |
| 101 | + { |
| 102 | + $personalAccessToken = env('PERSONAL_ACCESS_TOKEN'); |
| 103 | + |
| 104 | + return (new PrefixerClient())->authenticate($personalAccessToken); |
| 105 | + } |
| 106 | +} |
0 commit comments