Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/Api/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 30 additions & 1 deletion tests/Api/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,48 @@ public function testCreate()
'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]))
->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 = '';
Expand Down