Skip to content

Commit 38ce4f5

Browse files
authored
Merge pull request #17 from packagist/t/convert-package-json
Package: automatically convert custom package data
2 parents d9df32c + 8e1a67b commit 38ce4f5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Diff for: src/Api/Packages.php

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function createVcsPackage($url, $credentials = null)
4343

4444
public function createCustomPackage($customJson, $credentials = null)
4545
{
46+
if (is_array($customJson) || is_object($customJson)) {
47+
$customJson = json_encode($customJson);
48+
}
49+
4650
return $this->post('/packages/', ['repoType' => 'package', 'repoConfig' => $customJson, 'credentials' => $credentials]);
4751
}
4852

Diff for: tests/Api/PackagesTest.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ public function testCreateVcsPackage()
9797
$this->assertSame($expected, $api->createVcsPackage('localhost'));
9898
}
9999

100-
public function testCreateCustomPackage()
100+
/**
101+
* @dataProvider customProvider
102+
*/
103+
public function testCreateCustomPackage($customJson)
101104
{
102105
$expected = [
103106
'id' => 'job-id',
@@ -109,9 +112,17 @@ public function testCreateCustomPackage()
109112
$api->expects($this->once())
110113
->method('post')
111114
->with($this->equalTo('/packages/'), $this->equalTo(['repoType' => 'package', 'repoConfig' => '{}', 'credentials' => null]))
112-
->will($this->returnValue($expected));
115+
->willReturn($expected);
113116

114-
$this->assertSame($expected, $api->createCustomPackage('{}'));
117+
$this->assertSame($expected, $api->createCustomPackage($customJson));
118+
}
119+
120+
public function customProvider()
121+
{
122+
return [
123+
['{}'],
124+
[new \stdClass()],
125+
];
115126
}
116127

117128
public function testEditVcsPackage()

0 commit comments

Comments
 (0)