|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * (c) Packagist Conductors GmbH <contact@packagist.com> |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PrivatePackagist\ApiClient\Api\Suborganizations\Packages; |
| 11 | + |
| 12 | +use PHPUnit\Framework\MockObject\MockObject; |
| 13 | +use PrivatePackagist\ApiClient\Api\ApiTestCase; |
| 14 | + |
| 15 | +class ArtifactsTest extends ApiTestCase |
| 16 | +{ |
| 17 | + public function testCreate() |
| 18 | + { |
| 19 | + $suborganizationName = 'suborganization'; |
| 20 | + $expected = [ |
| 21 | + 'id' => 1, |
| 22 | + ]; |
| 23 | + $rawFileContent = 'foobar'; |
| 24 | + $headers = [ |
| 25 | + 'Content-Type' => 'application/zip', |
| 26 | + 'X-FILENAME' => 'file.zip' |
| 27 | + ]; |
| 28 | + |
| 29 | + /** @var Artifacts&MockObject $api */ |
| 30 | + $api = $this->getApiMock(); |
| 31 | + $api->expects($this->once()) |
| 32 | + ->method('postFile') |
| 33 | + ->with($this->equalTo('/suborganizations/suborganization/packages/artifacts/'), $rawFileContent, $headers) |
| 34 | + ->willReturn($expected); |
| 35 | + |
| 36 | + |
| 37 | + $this->assertSame($expected, $api->create($suborganizationName, $rawFileContent, $headers['Content-Type'], $headers['X-FILENAME'])); |
| 38 | + } |
| 39 | + |
| 40 | + public function testAdd() |
| 41 | + { |
| 42 | + $suborganizationName = 'suborganization'; |
| 43 | + $packageName = 'acme/artifact'; |
| 44 | + $expected = [ |
| 45 | + 'id' => 1, |
| 46 | + ]; |
| 47 | + $rawFileContent = 'foobar'; |
| 48 | + $headers = [ |
| 49 | + 'Content-Type' => 'application/zip', |
| 50 | + 'X-FILENAME' => 'file.zip' |
| 51 | + ]; |
| 52 | + |
| 53 | + /** @var Artifacts&MockObject $api */ |
| 54 | + $api = $this->getApiMock(); |
| 55 | + $api->expects($this->once()) |
| 56 | + ->method('postFile') |
| 57 | + ->with($this->equalTo('/suborganizations/'.$suborganizationName.'/packages/'.$packageName.'/artifacts/'), $rawFileContent, $headers) |
| 58 | + ->willReturn($expected); |
| 59 | + |
| 60 | + |
| 61 | + $this->assertSame($expected, $api->add($suborganizationName, $packageName, $rawFileContent, $headers['Content-Type'], $headers['X-FILENAME'])); |
| 62 | + } |
| 63 | + |
| 64 | + public function testShow() |
| 65 | + { |
| 66 | + $suborganizationName = 'suborganization'; |
| 67 | + $expected = [ |
| 68 | + 'repoType' => 'artifact', |
| 69 | + 'artifactPackageFileIds' =>[1, 2], |
| 70 | + ]; |
| 71 | + |
| 72 | + /** @var Artifacts&MockObject $api */ |
| 73 | + $api = $this->getApiMock(); |
| 74 | + $api->expects($this->once()) |
| 75 | + ->method('get') |
| 76 | + ->with($this->equalTo('/suborganizations/suborganization/packages/artifacts/1/')) |
| 77 | + ->willReturn($expected); |
| 78 | + |
| 79 | + $this->assertSame($expected, $api->show($suborganizationName, '1')); |
| 80 | + } |
| 81 | + |
| 82 | + public function testShowPackageArtifacts() |
| 83 | + { |
| 84 | + $suborganizationName = 'suborganization'; |
| 85 | + $expected = [ |
| 86 | + 'name' => 'acme-website/package', |
| 87 | + 'repoType' => 'artifact', |
| 88 | + 'artifactFiles' => 'artifact', |
| 89 | + ]; |
| 90 | + |
| 91 | + /** @var Artifacts&MockObject $api */ |
| 92 | + $api = $this->getApiMock(); |
| 93 | + $api->expects($this->once()) |
| 94 | + ->method('getCollection') |
| 95 | + ->with($this->equalTo('/suborganizations/suborganization/packages/acme-website/package/artifacts/')) |
| 96 | + ->willReturn($expected); |
| 97 | + |
| 98 | + $this->assertSame($expected, $api->showPackageArtifacts($suborganizationName, 'acme-website/package')); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * @return string |
| 103 | + */ |
| 104 | + protected function getApiClass() |
| 105 | + { |
| 106 | + return Artifacts::class; |
| 107 | + } |
| 108 | +} |
0 commit comments