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
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ $jobs = $client->organization()->sync();
```
Returns an array of created jobs. One for every synchronization.

#### Team

##### List an organization's teams
```php
$teams = $client->teams()->all();
```
Returns an array of teams.

#### Customer

##### List an organization's customers
Expand Down Expand Up @@ -107,6 +115,68 @@ $composerRepository = $client->customers()->regenerateToken($customerId, $confir
```
Returns the updated Composer repository.

#### Project

##### List an organization's projects
```php
$projects = $client->projects()->all();
```
Returns an array of projects.

##### Show a project
```php
$projectId = 42;
$project = $client->projects()->show($projectId);
```
Returns a single project.

##### Create a project
```php
$project = $client->projects()->create('New project name');
```
Returns the project.

##### Delete a project
```php
$projectId = 42;
$client->projects()->remove($projectId);
```

##### List a projects's teams
```php
$projectId = 42;
$teams = $client->projects()->listTeams($projectId);
```
Returns an array of projects teams.

##### Add a team to a project or update the permission
```php
$projectId = 42;
$teams = [
[
'id' => 12,
'permission' => 'owner',
],
];
$teams = $client->customers()->addOrUpdateTeams($projectId, $teams);
```
Returns an array of added project teams.


##### Remove a team from a customer
```php
$projectId = 42;
$teamId = 12;
$client->customers()->removeTeam($projectId, $teamId);
```

##### List a projects's packages
```php
$projectId = 42;
$packages = $client->projects()->listPackages($projectId);
```
Returns an array of projects packages.

#### Package

##### List an organization's packages
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function addOrUpdatePackages($customerId, array $packages)
{
foreach ($packages as $package) {
if (!isset($package['name'])) {
throw new InvalidArgumentException('Parameter "name" is requried.');
throw new InvalidArgumentException('Parameter "name" is required.');
}
}

Expand Down
58 changes: 58 additions & 0 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace PrivatePackagist\ApiClient\Api;

use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;

class Projects extends AbstractApi
{
public function all()
{
return $this->get('/projects/');
}

public function show($projectId)
{
return $this->get(sprintf('/projects/%s/', $projectId));
}

public function create($name)
{
return $this->post('/projects/', ['name' => $name]);
}

public function remove($projectId)
{
return $this->delete(sprintf('/projects/%s/', $projectId));
}

public function listTeams($projectsId)
{
return $this->get(sprintf('/projects/%s/teams/', $projectsId));
}

public function addOrUpdateTeams($projectId, array $teams)
{
foreach ($teams as $team) {
if (!isset($team['id'])) {
throw new InvalidArgumentException('Parameter "id" is required.');
}

if (!isset($team['permission'])) {
throw new InvalidArgumentException('Parameter "permission" is required.');
}
}

return $this->post(sprintf('/projects/%s/teams/', $projectId), $teams);
}

public function removeTeam($projectId, $teamId)
{
return $this->delete(sprintf('/projects/%s/teams/%s/', $projectId, $teamId));
}

public function listPackages($projectsId)
{
return $this->get(sprintf('/projects/%s/packages/', $projectsId));
}
}
11 changes: 11 additions & 0 deletions src/Api/Teams.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PrivatePackagist\ApiClient\Api;

class Teams extends AbstractApi
{
public function all()
{
return $this->get('/teams/');
}
}
10 changes: 10 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,21 @@ public function credentials()
return new Api\Credentials($this, $this->responseMediator);
}

public function teams()
{
return new Api\Teams($this, $this->responseMediator);
}

public function customers()
{
return new Api\Customers($this, $this->responseMediator);
}

public function projects()
{
return new Api\Projects($this, $this->responseMediator);
}

public function organization()
{
return new Api\Organization($this, $this->responseMediator);
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testAddOrUpdatePackages()

/**
* @expectedException \PrivatePackagist\ApiClient\Exception\InvalidArgumentException
* @expectedExceptionMessage Parameter "name" is requried.
* @expectedExceptionMessage Parameter "name" is required.
*/
public function testAddOrUpdatePackagesMissingName()
{
Expand Down
177 changes: 177 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

namespace PrivatePackagist\ApiClient\Api;

class ProjectsTest extends ApiTestCase
{
public function testAll()
{
$expected = [
$this->getProjectDefinition(),
];

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/projects/'))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->all());
}

public function testShow()
{
$expected = $this->getProjectDefinition();

$projectId = 1;

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/projects/1/'))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->show($projectId));
}

public function testCreate()
{
$expected = $this->getProjectDefinition();

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with($this->equalTo('/projects/'), $this->equalTo(['name' => 'ACME Websites']))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->create('ACME Websites'));
}

public function testRemove()
{
$expected = '';

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with($this->equalTo('/projects/1/'))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->remove(1));
}

public function testListTeams()
{
$expected = [
[
'id' => 42,
'name' => 'Owners',
'permission' => 'owner',
'members' => [],
'projects' => [],
],
];

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/projects/1/teams/'))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->listTeams(1));
}

public function testAddOrUpdateTeam()
{
$expected = [
[
'id' => 42,
'name' => 'Owners',
'permission' => 'owner',
'members' => [],
'projects' => [],
],
];

$teams = [['id' => 42, 'permission' => 'owner']];

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with($this->equalTo('/projects/1/teams/'), $this->equalTo($teams))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->addOrUpdateTeams(1, $teams));
}

public function testRemoveTeam()
{
$expected = '';

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with($this->equalTo('/projects/1/teams/42/'))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->removeTeam(1, 42));
}

public function testListPackages()
{
$expected = [
[
'name' => 'composer/composer',
'origin' => 'private',
'versionConstraint' => null,
'expirationDate' => null,
],
];

/** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/projects/1/packages/'))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->listPackages(1));
}

private function getProjectDefinition()
{
return [
'id' => 1,
'name' => 'ACME Websites',
'urlName' => 'acme-websites',
'teams' => [
[
'id' => 1,
'name' => 'Owners',
'permission' => 'owner',
'members' => [
[
'id' => 12,
'username' => 'username'
]
],
]
]
];
}

/**
* @return string
*/
protected function getApiClass()
{
return Projects::class;
}
}
Loading