From 4fac272f0f3cdd6bcf71469c1e2dbd6f42759d27 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Wed, 5 Dec 2018 17:02:05 +0000 Subject: [PATCH] Customer: add endpoint to update customer settings --- README.md | 12 ++++++++++++ src/Api/Customers.php | 9 +++++++-- tests/Api/CustomersTest.php | 31 ++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b66ac8f..a0d163a 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,18 @@ $customer = $client->customers()->create('New customer name'); ``` Returns the customer. +##### Update a customer +```php +$customerId = 42; +$customerData = [ + 'name' => $name, + 'urlName' => 'customer', + 'accessToVersionControlSource' => false, +]; +$customer = $client->customers()->update($customerId, $customerData); +``` +Returns the customer. + ##### Delete a customer ```php $customerId = 42; diff --git a/src/Api/Customers.php b/src/Api/Customers.php index 8e999c8..e724029 100644 --- a/src/Api/Customers.php +++ b/src/Api/Customers.php @@ -16,9 +16,14 @@ public function show($customerId) return $this->get(sprintf('/customers/%s/', $customerId)); } - public function create($name) + public function create($name, $accessToVersionControlSource = false) { - return $this->post('/customers/', ['name' => $name]); + return $this->post('/customers/', ['name' => $name, 'accessToVersionControlSource' => $accessToVersionControlSource]); + } + + public function update($customerId, array $customer) + { + return $this->put(sprintf('/customers/%s/', $customerId), $customer); } public function remove($customerId) diff --git a/tests/Api/CustomersTest.php b/tests/Api/CustomersTest.php index 4ef4de7..c58a7cf 100644 --- a/tests/Api/CustomersTest.php +++ b/tests/Api/CustomersTest.php @@ -49,6 +49,7 @@ public function testCreate() 'id' => 1, 'type' => 'composer-repo', 'name' => $name = 'Customer', + 'accessToVersionControlSource' => false, ], ]; @@ -56,12 +57,40 @@ public function testCreate() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with($this->equalTo('/customers/'), $this->equalTo(['name' => $name])) + ->with($this->equalTo('/customers/'), $this->equalTo(['name' => $name, 'accessToVersionControlSource' => false])) ->will($this->returnValue($expected)); $this->assertSame($expected, $api->create($name)); } + public function testUpdate() + { + $expected = [ + [ + 'id' => 1, + 'type' => 'composer-repo', + 'name' => $name = 'Customer', + 'urlName' => 'customer', + 'accessToVersionControlSource' => false, + ], + ]; + + $customer = [ + 'name' => $name, + 'urlName' => 'customer', + 'accessToVersionControlSource' => false, + ]; + + /** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with($this->equalTo('/customers/1/'), $this->equalTo($customer)) + ->will($this->returnValue($expected)); + + $this->assertSame($expected, $api->update(1, $customer)); + } + public function testRemove() { $expected = '';