diff --git a/README.md b/README.md index 7716e4c..f7342a6 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ Returns a single customer. ##### Create a customer ```php $customer = $client->customers()->create('New customer name'); +// or +$customer = $client->customers()->create('New customer name', false, 'customer-url-name'); ``` Returns the customer. diff --git a/src/Api/Customers.php b/src/Api/Customers.php index 1dc0e5f..6fb7d26 100644 --- a/src/Api/Customers.php +++ b/src/Api/Customers.php @@ -17,9 +17,17 @@ public function show($customerIdOrUrlName) return $this->get(sprintf('/customers/%s/', $customerIdOrUrlName)); } - public function create($name, $accessToVersionControlSource = false) + public function create($name, $accessToVersionControlSource = false, $urlName = null) { - return $this->post('/customers/', ['name' => $name, 'accessToVersionControlSource' => $accessToVersionControlSource]); + $parameters = [ + 'name' => $name, + 'accessToVersionControlSource' => $accessToVersionControlSource, + ]; + if ($urlName) { + $parameters['urlName'] = $urlName; + } + + return $this->post('/customers/', $parameters); } /** diff --git a/tests/Api/CustomersTest.php b/tests/Api/CustomersTest.php index efc07bf..e3c15ef 100644 --- a/tests/Api/CustomersTest.php +++ b/tests/Api/CustomersTest.php @@ -63,6 +63,27 @@ public function testCreate() $this->assertSame($expected, $api->create($name)); } + public function testCreateAllParameters() + { + $expected = [ + [ + 'id' => 1, + 'type' => 'composer-repo', + 'name' => $name = 'Customer', + 'accessToVersionControlSource' => false, + ], + ]; + + /** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with($this->equalTo('/customers/'), $this->equalTo(['name' => $name, 'accessToVersionControlSource' => true, 'urlName' => 'url-name'])) + ->will($this->returnValue($expected)); + + $this->assertSame($expected, $api->create($name, true, 'url-name')); + } + public function tesEdit() { $expected = [