Skip to content

Commit 04866bd

Browse files
committed
Customer: update addPackages to addOrUpdatePackages
1 parent ba73e96 commit 04866bd

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ $packages = $client->customers()->listPackages();
6161
```
6262
Returns an array of customer packages.
6363

64-
##### Grant a customer access to a package
64+
##### Grant a customer access to a package or update the limitations
6565
```php
6666
$customerId = 42;
6767
$packages = [
@@ -71,7 +71,7 @@ $packages = [
7171
'expirationDate' => (new \DateTime())->add(new \DateInterval('P1Y'))->format('c'), // optional expiration date to limit updades the customer receives
7272
],
7373
];
74-
$packages = $client->customers()->addPackages($customerId, $packages);
74+
$packages = $client->customers()->addOrUpdatePackages($customerId, $packages);
7575
```
7676
Returns an array of added customer packages.
7777

src/Api/Customers.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function listPackages($customerId)
2626
return $this->get(sprintf('/customers/%s/packages/', $customerId));
2727
}
2828

29-
public function addPackages($customerId, array $packages)
29+
public function addOrUpdatePackages($customerId, array $packages)
3030
{
3131
foreach ($packages as $package) {
3232
if (!isset($package['name'])) {
@@ -37,6 +37,14 @@ public function addPackages($customerId, array $packages)
3737
return $this->post(sprintf('/customers/%s/packages/', $customerId), $packages);
3838
}
3939

40+
/**
41+
* @deprecated Use addOrUpdatePackages instead
42+
*/
43+
public function addPackages($customerId, array $packages)
44+
{
45+
return $this->addOrUpdatePackages($customerId, $packages);
46+
}
47+
4048
public function removePackage($customerId, $packageName)
4149
{
4250
return $this->delete(sprintf('/customers/%s/packages/%s/', $customerId, $packageName));

tests/Api/CustomersTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testListPackages()
7979
$this->assertSame($expected, $api->listPackages(1));
8080
}
8181

82-
public function testAddPackages()
82+
public function testAddOrUpdatePackages()
8383
{
8484
$expected = [
8585
[
@@ -99,19 +99,19 @@ public function testAddPackages()
9999
->with($this->equalTo('/customers/1/packages/'), $this->equalTo($packages))
100100
->will($this->returnValue($expected));
101101

102-
$this->assertSame($expected, $api->addPackages(1, $packages));
102+
$this->assertSame($expected, $api->addOrUpdatePackages(1, $packages));
103103
}
104104

105105
/**
106106
* @expectedException \PrivatePackagist\ApiClient\Exception\InvalidArgumentException
107107
* @expectedExceptionMessage Parameter "name" is requried.
108108
*/
109-
public function testAddPackagesMissingName()
109+
public function testAddOrUpdatePackagesMissingName()
110110
{
111111
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
112112
$api = $this->getApiMock();
113113

114-
$api->addPackages(1, [[]]);
114+
$api->addOrUpdatePackages(1, [[]]);
115115
}
116116

117117
public function testRemovePackage()

0 commit comments

Comments
 (0)