Skip to content

Commit

Permalink
Merge pull request #38 from packagist/t/customer-add-minimum-stability
Browse files Browse the repository at this point in the history
Vendor: add option to limit package versions by stability
  • Loading branch information
naderman authored Jul 16, 2020
2 parents 42fa918 + 480d247 commit 749eaff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Returns a single customer.
```php
$customer = $client->customers()->create('New customer name');
// or
$customer = $client->customers()->create('New customer name', false, 'customer-url-name');
$customer = $client->customers()->create('New customer name', false, 'customer-url-name', 'beta');
```
Returns the customer.

Expand All @@ -202,6 +202,7 @@ $customerData = [
'name' => $name,
'urlName' => 'customer',
'accessToVersionControlSource' => false,
'minimumAccessibleStability' => 'beta',
];
$customer = $client->customers()->edit($customerId, $customerData);
```
Expand Down Expand Up @@ -240,6 +241,7 @@ $packages = [
'name' => 'acme-website/package',
'versionConstraint' => '^1.0 | ^2.0', // optional version constraint to limit updates the customer receives
'expirationDate' => (new \DateTime())->add(new \DateInterval('P1Y'))->format('c'), // optional expiration date to limit updates the customer receives
'minimumAccessibleStability' => 'beta', // optional stability to restrict customers to specific package version stabilities like alpha, beta, or RC
],
];
$packages = $client->customers()->addOrEditPackages($customerId, $packages);
Expand Down
3 changes: 2 additions & 1 deletion src/Api/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ public function show($customerIdOrUrlName)
return $this->get(sprintf('/customers/%s/', $customerIdOrUrlName));
}

public function create($name, $accessToVersionControlSource = false, $urlName = null)
public function create($name, $accessToVersionControlSource = false, $urlName = null, $minimumAccessibleStability = null)
{
$parameters = [
'name' => $name,
'accessToVersionControlSource' => $accessToVersionControlSource,
'minimumAccessibleStability' => $minimumAccessibleStability,
];
if ($urlName) {
$parameters['urlName'] = $urlName;
Expand Down
10 changes: 7 additions & 3 deletions tests/Api/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ public function testCreate()
'type' => 'composer-repo',
'name' => $name = 'Customer',
'accessToVersionControlSource' => false,
'minimumAccessibleStability' => 'dev',
],
];

/** @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' => false]))
->with($this->equalTo('/customers/'), $this->equalTo(['name' => $name, 'accessToVersionControlSource' => false, 'minimumAccessibleStability' => null]))
->willReturn($expected);

$this->assertSame($expected, $api->create($name));
Expand All @@ -78,17 +79,18 @@ public function testCreateAllParameters()
'type' => 'composer-repo',
'name' => $name = 'Customer',
'accessToVersionControlSource' => false,
'minimumAccessibleStability' => 'beta'
],
];

/** @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']))
->with($this->equalTo('/customers/'), $this->equalTo(['name' => $name, 'accessToVersionControlSource' => true, 'urlName' => 'url-name', 'minimumAccessibleStability' => 'beta']))
->willReturn($expected);

$this->assertSame($expected, $api->create($name, true, 'url-name'));
$this->assertSame($expected, $api->create($name, true, 'url-name', 'beta'));
}

public function tesEdit()
Expand All @@ -100,13 +102,15 @@ public function tesEdit()
'name' => $name = 'Customer',
'urlName' => 'customer',
'accessToVersionControlSource' => false,
'minimumAccessibleStability' => 'dev',
],
];

$customer = [
'name' => $name,
'urlName' => 'customer',
'accessToVersionControlSource' => false,
'minimumAccessibleStability' => null,
];

/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
Expand Down

0 comments on commit 749eaff

Please sign in to comment.