Skip to content
Open
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
119 changes: 119 additions & 0 deletions Tests/Package/Orgs/TeamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use Joomla\Github\Package\Orgs\Teams;
use Joomla\Github\Tests\Stub\GitHubTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;

/**
* Test method.
Expand Down Expand Up @@ -599,4 +601,121 @@ public function testGetUserTeams()
$this->equalTo(json_decode($this->sampleString))
);
}

/**
* Data provider for the team methods addressing a team by organization and slug
*
* @return \Generator
*/
public static function slugMethodsProvider(): \Generator
{
yield 'getBySlug' => ['get', 'getBySlug', ['joomla', 'cms-maintainers'], ['/orgs/joomla/teams/cms-maintainers'], 200];
yield 'editBySlug' => [
'patch',
'editBySlug',
['joomla', 'cms-maintainers', null, 'Maintainers of the CMS'],
['/orgs/joomla/teams/cms-maintainers', '{"description":"Maintainers of the CMS"}'],
200,
];
yield 'deleteBySlug' => ['delete', 'deleteBySlug', ['joomla', 'cms-maintainers'], ['/orgs/joomla/teams/cms-maintainers'], 204];
yield 'getListMembersBySlug' => [
'get',
'getListMembersBySlug',
['joomla', 'cms-maintainers', 2, 50],
['/orgs/joomla/teams/cms-maintainers/members?page=2&per_page=50'],
200,
];
yield 'addMembershipBySlug' => [
'put',
'addMembershipBySlug',
['joomla', 'cms-maintainers', 'octocat', 'maintainer'],
['/orgs/joomla/teams/cms-maintainers/memberships/octocat', '{"role":"maintainer"}'],
200,
];
yield 'removeMembershipBySlug' => [
'delete',
'removeMembershipBySlug',
['joomla', 'cms-maintainers', 'octocat'],
['/orgs/joomla/teams/cms-maintainers/memberships/octocat'],
204,
];
yield 'getListReposBySlug' => [
'get',
'getListReposBySlug',
['joomla', 'cms-maintainers'],
['/orgs/joomla/teams/cms-maintainers/repos'],
200,
];
yield 'addRepoBySlug' => [
'put',
'addRepoBySlug',
['joomla', 'cms-maintainers', 'joomla', 'joomla-cms', 'maintain'],
['/orgs/joomla/teams/cms-maintainers/repos/joomla/joomla-cms', '{"permission":"maintain"}'],
204,
];
yield 'removeRepoBySlug' => [
'delete',
'removeRepoBySlug',
['joomla', 'cms-maintainers', 'joomla', 'joomla-cms'],
['/orgs/joomla/teams/cms-maintainers/repos/joomla/joomla-cms'],
204,
];
}

/**
* Tests the team methods addressing a team by organization and slug
*
* @param string $httpMethod The expected HTTP method
* @param string $method The method to call
* @param array $arguments The arguments
* @param array $request The expected request arguments
* @param integer $code The response code
*
* @return void
*/
#[DataProvider('slugMethodsProvider')]
public function testSlugMethods(string $httpMethod, string $method, array $arguments, array $request, int $code)
{
$this->client->expects($this->once())
->method($httpMethod)
->with(...$request)
->willReturn($this->getResponseObject($code === 204 ? '' : $this->sampleString, $code));

$this->object->$method(...$arguments);
}

/**
* Tests getMembershipBySlug and checkRepoBySlug
*
* @return void
*/
public function testMembershipAndRepoChecksBySlug()
{
$this->client->expects($this->exactly(3))
->method('get')
->willReturnOnConsecutiveCalls(
$this->getResponseObject('{"state":"active","role":"member"}', 200),
$this->getResponseObject('', 404),
$this->getResponseObject('', 204)
);

$this->assertSame('active', $this->object->getMembershipBySlug('joomla', 'cms-maintainers', 'octocat'));
$this->assertFalse($this->object->getMembershipBySlug('joomla', 'cms-maintainers', 'nobody'));
$this->assertTrue($this->object->checkRepoBySlug('joomla', 'cms-maintainers', 'joomla', 'joomla-cms'));
}

/**
* Tests that the methods using the legacy /teams/{team_id} routes are deprecated
*
* @return void
*/
#[IgnoreDeprecations]
public function testLegacyRoutesAreDeprecated()
{
$this->expectUserDeprecationMessageMatches('/Teams::get\(\) is deprecated and will be removed in 5\.0.*getBySlug\(\)/');

$this->client->method('get')->willReturn($this->response);

$this->object->get(123);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"php": "^8.3.0",
"joomla/http": "^4.0",
"joomla/registry": "^4.0",
"joomla/uri": "^4.0"
"joomla/uri": "^4.0",
"symfony/deprecation-contracts": "^2|^3"
},
"require-dev": {
"phpunit/phpunit": "^12.2.7",
Expand Down
22 changes: 22 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# Github API package

TODO

## Teams

GitHub addresses teams by organization and slug (`/orgs/{org}/teams/{team_slug}`); the `/teams/{team_id}` routes are
legacy. `$github->orgs->teams` has a `…BySlug()` method for each of them:

| Method | Replaces |
|---|---|
| `getBySlug($org, $slug)` | `get($id)` |
| `editBySlug($org, $slug, $name, $description, $privacy)` | `edit($id, ...)` |
| `deleteBySlug($org, $slug)` | `delete($id)` |
| `getListMembersBySlug($org, $slug, $page, $limit)` | `getListMembers($id)` |
| `getMembershipBySlug($org, $slug, $user)` | `getTeamMembership($id, $user)`, `isMember($id, $user)` |
| `addMembershipBySlug($org, $slug, $user, $role)` | `addTeamMembership($id, $user, $role)`, `addMember($id, $user)` |
| `removeMembershipBySlug($org, $slug, $user)` | `removeTeamMembership($id, $user)`, `removeMember($id, $user)` |
| `getListReposBySlug($org, $slug, $page, $limit)` | `getListRepos($id)` |
| `checkRepoBySlug($org, $slug, $owner, $repo)` | `checkRepo($id, $owner, $repo)` |
| `addRepoBySlug($org, $slug, $owner, $repo, $permission)` | `addRepo($id, $org, $repo)` |
| `removeRepoBySlug($org, $slug, $owner, $repo)` | `removeRepo($id, $owner, $repo)` |

The methods in the right column are deprecated and will be removed in 5.0. `getList($org)`, `create($org, ...)` and
`getUserTeams()` already use the current routes.
Loading
Loading