Skip to content

Commit cb24b1d

Browse files
committed
Add artifact to an existing package
1 parent 8568678 commit cb24b1d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
* [Create an artifact package file](#create-an-artifact-package-file)
7474
* [Create an artifact package](#create-an-artifact-package)
7575
* [Update artifact files of a package](#update-artifact-files-of-a-package)
76+
* [Add an artifact file to an existing package](#add-an-artifact-file-to-an-existing-package)
7677
* [Credential](#credential)
7778
* [List an organization's credentials](#list-an-organizations-credentials)
7879
* [Show a credential](#show-a-credential)
@@ -98,7 +99,7 @@
9899
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
99100
* [License](#license)
100101

101-
<!-- Added by: wissem, at: Tue Jul 21 10:32:47 CEST 2020 -->
102+
<!-- Added by: wissem, at: Thu Oct 15 10:37:57 CEST 2020 -->
102103

103104
<!--te-->
104105

@@ -604,6 +605,15 @@ $result = $client->packages()->artifacts()->showPackageArtifacts('acme-website/p
604605
$artifactFileIds = [42, 43];
605606
$client->packages()->editArtifactPackage('acme-website/package', $artifactFileIds);
606607
```
608+
609+
#### Add an artifact file to an existing package
610+
611+
```php
612+
$packageId = 1;
613+
$fileName = 'package1.zip';
614+
$file = file_get_contents($fileName);
615+
$client->packages()->artifacts()->add($packageId, $file, 'application/zip', $fileName);
616+
```
607617
### Credential
608618

609619
#### List an organization's credentials

src/Api/Packages/Artifacts.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public function create($file, $contentType, $fileName)
2121
]));
2222
}
2323

24+
public function add($packageId, $file, $contentType, $fileName)
25+
{
26+
return $this->postFile('/packages/'.$packageId.'/artifacts/', $file, array_filter([
27+
'Content-Type' => $contentType,
28+
'X-FILENAME' => $fileName
29+
]));
30+
}
31+
2432
public function show($artifactId)
2533
{
2634
return $this->get(sprintf('/packages/artifacts/%s/', $artifactId));

tests/Api/Packages/ArtifactsTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ public function testCreate()
3535
$this->assertSame($expected, $api->create($rawFileContent, $headers['Content-Type'], $headers['X-FILENAME']));
3636
}
3737

38+
public function testAdd()
39+
{
40+
$packageId = 10;
41+
$expected = [
42+
'id' => 1,
43+
];
44+
$rawFileContent = 'foobar';
45+
$headers = [
46+
'Content-Type' => 'application/zip',
47+
'X-FILENAME' => 'file.zip'
48+
];
49+
50+
/** @var Artifacts&\PHPUnit_Framework_MockObject_MockObject $api */
51+
$api = $this->getApiMock();
52+
$api->expects($this->once())
53+
->method('postFile')
54+
->with($this->equalTo('/packages/'.$packageId.'/artifacts/'), $rawFileContent, $headers)
55+
->willReturn($expected);
56+
57+
58+
$this->assertSame($expected, $api->add($packageId,$rawFileContent, $headers['Content-Type'], $headers['X-FILENAME']));
59+
}
60+
3861
public function testShow()
3962
{
4063
$expected = [

0 commit comments

Comments
 (0)