github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/clients/php/test/Api/UploadsApiTest.php (about) 1 <?php 2 /** 3 * UploadsApiTest 4 * PHP version 5 5 * 6 * @category Class 7 * @package Phrase 8 * @author OpenAPI Generator team 9 * @link https://openapi-generator.tech 10 */ 11 12 /** 13 * Phrase Strings API Reference 14 * 15 * The version of the OpenAPI document: 2.0.0 16 * Contact: support@phrase.com 17 * Generated by: https://openapi-generator.tech 18 * OpenAPI Generator version: 4.3.1 19 */ 20 21 /** 22 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). 23 * https://openapi-generator.tech 24 * Please update the test case below to test the endpoint. 25 */ 26 27 namespace Phrase; 28 29 use \Phrase\Configuration as Configuration; 30 use \Phrase\ApiException; 31 use \Phrase\ObjectSerializer; 32 33 use \Phrase\Api\UploadsApi as Api; 34 use \Phrase\Model\UploadCreateParameters; 35 36 use PHPUnit\Framework\TestCase; 37 38 use GuzzleHttp\Client; 39 use GuzzleHttp\Handler\MockHandler; 40 use GuzzleHttp\HandlerStack; 41 use GuzzleHttp\Middleware; 42 use GuzzleHttp\Psr7\Response; 43 44 /** 45 * UploadsApiTest Class Doc Comment 46 * 47 * @category Class 48 * @package Phrase 49 * @author OpenAPI Generator team 50 * @link https://openapi-generator.tech 51 */ 52 class UploadsApiTest extends TestCase 53 { 54 private $apiInstance; 55 private $mock; 56 private $history = []; 57 58 /** 59 * Setup before running any test cases 60 */ 61 public static function setUpBeforeClass() 62 { 63 } 64 65 /** 66 * Setup before running each test case 67 */ 68 public function setUp() 69 { 70 $this->mock = new MockHandler(); 71 $history = Middleware::history($this->history); 72 $handlerStack = HandlerStack::create($this->mock); 73 $handlerStack->push($history); 74 $client = new Client(['handler' => $handlerStack]); 75 76 $config = Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY'); 77 $config = Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'token'); 78 79 $this->apiInstance = new Api($client, $config); 80 } 81 82 /** 83 * Clean up after running each test case 84 */ 85 public function tearDown() 86 { 87 } 88 89 /** 90 * Clean up after running all test cases 91 */ 92 public static function tearDownAfterClass() 93 { 94 } 95 96 /** 97 * Test case for uploadCreate 98 * 99 * Upload a new file. 100 * 101 */ 102 public function testUploadCreate() 103 { 104 $fileName = '/tmp/test.txt'; 105 $this->mock->append(new Response(200, [], '{"id": "dGVzdA","filename": "my_file.yml","state": "pending","format": "yml","upload_tags": [{"name": "my_tag","priority": 1}],"created_at": "2018-02-19T15:47:30Z","updated_at": "2018-02-19T15:47:30Z","file_size": 0,"source_locale": "en","target_locales": ["de","fr"],"file": {"id": "dGVzdA","name": "my_file.yml","content_type": "application/x-yaml","encoding": "UTF-8","created_at": "2018-02-19T15:47:30Z","updated_at": "2018-02-19T15:47:30Z","file_size": 0,"format": "yml","hash": "3cfd3b8d7c7a1d6c9f6d2f6c7d6b6c3c"} }')); 106 $projectId = "projectId_example"; 107 $file = new \SplFileObject($fileName, 'w+'); 108 $file->fwrite('test'); 109 110 $result = $this->apiInstance->uploadCreate($projectId, $file, "yml", "en", null, null); 111 $file = null; 112 unlink($fileName); 113 114 $this->assertEquals('dGVzdA', $result->getId()); 115 $this->assertEquals('my_file.yml', $result->getFilename()); 116 $this->assertEquals('pending', $result->getState()); 117 $this->assertEquals('yml', $result->getFormat()); 118 $this->assertEquals(new \DateTime('2018-02-19T15:47:30Z'), $result->getCreatedAt()); 119 $this->assertEquals(new \DateTime('2018-02-19T15:47:30Z'), $result->getUpdatedAt()); 120 121 $lastRequest = $this->history[count($this->history) - 1]['request']; 122 $this->assertEquals('POST', $lastRequest->getMethod()); 123 $this->assertEquals('/v2/projects/'.$projectId.'/uploads', $lastRequest->getUri()->getPath()); 124 $this->assertContains('multipart/form-data', $lastRequest->getHeader('Content-Type')[0]); 125 } 126 127 /** 128 * Test case for uploadShow 129 * 130 * Get a single upload. 131 * 132 */ 133 public function testUploadShow() 134 { 135 } 136 137 /** 138 * Test case for uploadsList 139 * 140 * List uploads. 141 * 142 */ 143 public function testUploadsList() 144 { 145 } 146 }