Skip to content

Commit 04ca283

Browse files
committed
Customer: add show customer
1 parent 04866bd commit 04ca283

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ $customers = $client->customers()->all();
4242
```
4343
Returns an array of customers.
4444

45+
##### Show a customer
46+
```php
47+
$customerId = 42;
48+
$customer = $client->customers()->show($customerId);
49+
```
50+
Returns a single customer.
4551

4652
##### Create a customer
4753
```php

src/Api/Customers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public function all()
1111
return $this->get('/customers/');
1212
}
1313

14+
public function show($customerId)
15+
{
16+
return $this->get(sprintf('/customers/%s/', $customerId));
17+
}
18+
1419
public function create($name)
1520
{
1621
return $this->post('/customers/', ['name' => $name]);

src/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(HttpPluginClientBuilder $httpClientBuilder = null, $
2626

2727
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($privatePackagistUrl)));
2828
$builder->addPlugin(new PathPrepend('/api'));
29+
$builder->addPlugin(new Plugin\RedirectPlugin());
2930
$builder->addPlugin(new Plugin\HeaderDefaultsPlugin([
3031
'User-Agent' => 'php-private-packagist-api (https://github.com/packagist/private-packagist-api-client)',
3132
]));

tests/Api/CustomersTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ public function testAll()
2424
$this->assertSame($expected, $api->all());
2525
}
2626

27+
public function testShow()
28+
{
29+
$expected = [
30+
'id' => 1,
31+
'type' => 'composer-repo',
32+
'name' => $name = 'Customer',
33+
];
34+
35+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
36+
$api = $this->getApiMock();
37+
$api->expects($this->once())
38+
->method('get')
39+
->with($this->equalTo('/customers/1/'))
40+
->will($this->returnValue($expected));
41+
42+
$this->assertSame($expected, $api->show(1));
43+
}
44+
2745
public function testCreate()
2846
{
2947
$expected = [

0 commit comments

Comments
 (0)