Skip to content

Remove incorrect MissingArgumentException, add docs, update tests #861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2020
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
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ v3 APIs:
* [Checks](repo/checks.md)
* [Contents](repo/contents.md)
* [Deployments](repo/deployments.md)
* [Labels](repo/labels.md)
* [Protection](repo/protection.md)
* [Releases](repo/releases.md)
* [Assets](repo/assets.md)
Expand Down
48 changes: 48 additions & 0 deletions doc/repo/labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Repo / Labels API
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)

### List all labels for this repository

```php
$labels = $client->api('repo')->labels()->all('twbs', 'bootstrap');
```

### Get a single label

```php
$label = $client->api('repo')->labels()->show('twbs', 'bootstrap', 'feature');
```

### Create a label

> Requires [authentication](../security.md).

```php
$params = [
'name' => 'bug',
'color' => 'f29513',
'description' => 'Something isn\'t working',
];
$label = $client->api('repo')->labels()->create('twbs', 'bootstrap', $params);
```

### Update a label

> Requires [authentication](../security.md).

```php
$params = [
'new_name' => 'bug :bug:',
'color' => 'b01f26',
'description' => 'Small bug fix required',
];
$label = $client->api('repo')->labels()->update('twbs', 'bootstrap', 'bug', $params);
```

### Delete a label

> Requires [authentication](../security.md).

```php
$label = $client->api('repo')->labels()->remove('twbs', 'bootstrap', 'bug');
```
4 changes: 0 additions & 4 deletions lib/Github/Api/Repository/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public function create($username, $repository, array $params)

public function update($username, $repository, $label, array $params)
{
if (!isset($params['name'], $params['color'])) {
throw new MissingArgumentException(['name', 'color']);
}

return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
}

Expand Down
34 changes: 2 additions & 32 deletions test/Github/Tests/Api/Repository/LabelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,43 +102,13 @@ public function shouldCreateLabel()
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data));
}

/**
* @test
*/
public function shouldNotUpdateLabelWithoutName()
{
$this->expectException(MissingArgumentException::class);
$data = ['color' => 'red'];

$api = $this->getApiMock();
$api->expects($this->never())
->method('patch');

$api->update('KnpLabs', 'php-github-api', 'labelName', $data);
}

/**
* @test
*/
public function shouldNotUpdateLabelWithoutColor()
{
$this->expectException(MissingArgumentException::class);
$data = ['name' => 'test'];

$api = $this->getApiMock();
$api->expects($this->never())
->method('patch');

$api->update('KnpLabs', 'php-github-api', 'labelName', $data);
}

/**
* @test
*/
public function shouldUpdateLabel()
{
$expectedValue = ['label' => 'somename'];
$data = ['name' => 'test', 'color' => 'red'];
$expectedValue = ['name' => 'test'];
$data = ['new_name' => 'test', 'color' => 'red'];

$api = $this->getApiMock();
$api->expects($this->once())
Expand Down