Skip to content

Commit f8a84e1

Browse files
authoredOct 14, 2019
Merge pull request #26 from packagist/t/customer-enable-endpoints
Customers: add endpoints to enable/disable them
2 parents 099042e + 6b954f5 commit f8a84e1

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed
 

‎README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ $customerId = 42;
9494
$client->customers()->remove($customerId);
9595
```
9696

97+
##### Enable a customer
98+
```php
99+
$customerId = 42;
100+
$customer = $client->customers()->enable($customerId);
101+
```
102+
103+
##### Disable a customer
104+
```php
105+
$customerId = 42;
106+
$customer = $client->customers()->disable($customerId);
107+
```
108+
97109
##### List a customer's packages
98110
```php
99111
$customerId = 42;
@@ -409,7 +421,7 @@ Returns a new job.
409421

410422
##### Edit a custom package
411423
```php
412-
$packageDefinition = '{...}'
424+
$packageDefinition = '{...}';
413425
$job = $client->packages()->editCustomPackage('acme-website/package', $packageDefinition);
414426
```
415427
Returns a new job.

‎src/Api/Customers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public function remove($customerIdOrUrlName)
5555
return $this->delete(sprintf('/customers/%s/', $customerIdOrUrlName));
5656
}
5757

58+
public function enable($customerIdOrUrlName)
59+
{
60+
return $this->put(sprintf('/customers/%s/enable', $customerIdOrUrlName));
61+
}
62+
63+
public function disable($customerIdOrUrlName)
64+
{
65+
return $this->put(sprintf('/customers/%s/disable', $customerIdOrUrlName));
66+
}
67+
5868
public function listPackages($customerIdOrUrlName)
5969
{
6070
return $this->get(sprintf('/customers/%s/packages/', $customerIdOrUrlName));

‎tests/Api/CustomersTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,48 @@ public function testRemove()
133133
$this->assertSame($expected, $api->remove(1));
134134
}
135135

136+
public function testEnable()
137+
{
138+
$expected = [
139+
'id' => 1,
140+
'type' => 'composer-repo',
141+
'name' => $name = 'Customer',
142+
'urlName' => 'customer',
143+
'accessToVersionControlSource' => false,
144+
'enabled' => true,
145+
];
146+
147+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
148+
$api = $this->getApiMock();
149+
$api->expects($this->once())
150+
->method('put')
151+
->with($this->equalTo('/customers/1/enable'))
152+
->willReturn($expected);
153+
154+
$this->assertSame($expected, $api->enable(1));
155+
}
156+
157+
public function testDisable()
158+
{
159+
$expected = [
160+
'id' => 1,
161+
'type' => 'composer-repo',
162+
'name' => $name = 'Customer',
163+
'urlName' => 'customer',
164+
'accessToVersionControlSource' => false,
165+
'enabled' => false,
166+
];
167+
168+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
169+
$api = $this->getApiMock();
170+
$api->expects($this->once())
171+
->method('put')
172+
->with($this->equalTo('/customers/1/disable'))
173+
->willReturn($expected);
174+
175+
$this->assertSame($expected, $api->disable(1));
176+
}
177+
136178
public function testListPackages()
137179
{
138180
$expected = [

0 commit comments

Comments
 (0)
Failed to load comments.