-
-
Notifications
You must be signed in to change notification settings - Fork 27
Added new endpoint, fix and added tests. #41
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
Changes from all commits
8003181
88f0461
94e6840
7d06940
be8ce6b
fc710b2
938480b
426bb9c
685fec8
daf93c1
499a83b
09538e6
b5243de
c35a591
bc0a1e0
3b0079e
d166b8d
fce732a
f985d66
93a295e
a65d013
8dae0a0
45f309b
ab45989
b040d79
2e91bd5
7898d70
693245a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Bitbucket API Client. | ||
* | ||
* (c) Graham Campbell <graham@alt-three.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Bitbucket\Api\Repositories\Workspaces; | ||
|
||
/** | ||
* The users api class. | ||
* | ||
* @author Graham Campbell <graham@alt-three.com> | ||
*/ | ||
class Repositories extends AbstractWorkspacesApi | ||
{ | ||
/** | ||
* @param string $repo | ||
* @param array $params | ||
* | ||
* @throws \Http\Client\Exception | ||
* | ||
* @return array | ||
*/ | ||
public function show(string $repo, array $params = []) | ||
{ | ||
$path = $this->buildRepositoryPath($repo); | ||
|
||
return $this->get($path, $params); | ||
} | ||
|
||
/** | ||
* Build the commit path from the given parts. | ||
* | ||
* @param string[] $parts | ||
* | ||
* @throws \Bitbucket\Exception\InvalidArgumentException | ||
* | ||
* @return string | ||
*/ | ||
protected function buildRepositoryPath(string ...$parts) | ||
{ | ||
return static::buildPath('repositories', $this->username, ...$parts); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,20 @@ public function show(array $params = []) | |
return $this->get($path, $params); | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* | ||
* @throws \Http\Client\Exception | ||
* | ||
* @return array | ||
*/ | ||
public function list(array $params = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please delete this. This is already implemented on the "CurrentUser" API. |
||
{ | ||
$path = $this->buildWorkspacesPath(); | ||
|
||
return $this->get($path, $params); | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ public function show(string $project, array $params = []) | |
* | ||
* @return array | ||
*/ | ||
public function update(string $project, array $params = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't change this. We have params like this out of convention. If we want to review that, we'd want to do it for all cases, not just one, and not in this PR. |
||
public function update(string $project, array $params) | ||
{ | ||
$path = $this->buildProjectsPath($project); | ||
|
||
|
@@ -104,6 +104,6 @@ public function remove(string $project, array $params = []) | |
*/ | ||
protected function buildProjectsPath(string ...$parts) | ||
{ | ||
return static::buildPath('workspaces', $this->username, 'projects', ...$parts); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This typo, and a few others are already fixed on |
||
return static::buildPath('workspaces', $this->workspace, 'projects', ...$parts); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests; | ||
|
||
use Bitbucket\Tests\responses\ProjectCreateResponse; | ||
use Bitbucket\Tests\responses\ProjectRemoveResponse; | ||
use Bitbucket\Tests\responses\ProjectsListResponse; | ||
use Bitbucket\Tests\responses\ProjectsShowResponse; | ||
use Bitbucket\Tests\responses\ProjectUpdateResponse; | ||
|
||
class ProjectsTest extends TestCase | ||
{ | ||
public function test_projects_list() | ||
{ | ||
$response = new ProjectsListResponse(); | ||
$client = $this->getClient($response); | ||
$projects = $client->workspaces('my-workspace')->projects()->list(); | ||
|
||
$this->assertCount(9, $projects['values']); | ||
} | ||
|
||
public function test_project_show() | ||
{ | ||
$response = new ProjectsShowResponse(); | ||
$client = $this->getClient($response); | ||
$project = $client->workspaces('my-workspace')->projects()->show('Atlassian1'); | ||
|
||
$this->assertCount(11, $project); | ||
} | ||
|
||
public function test_project_create() | ||
{ | ||
$response = new ProjectCreateResponse(); | ||
$client = $this->getClient($response); | ||
|
||
$params = [ | ||
'name' => 'name', | ||
'key' => 'key', | ||
'description' => 'description', | ||
'links' => (object) [ | ||
'avatar' => (object) [ | ||
'href' => '', | ||
], | ||
], | ||
'is_private' => true, | ||
]; | ||
|
||
$project = $client->workspaces('my-workspace')->projects()->create( | ||
$params | ||
); | ||
|
||
$this->assertCount(11, $project); | ||
} | ||
|
||
public function test_project_update() | ||
{ | ||
$response = new ProjectUpdateResponse(); | ||
$client = $this->getClient($response); | ||
|
||
$params = [ | ||
'name' => 'name-updated', | ||
'key' => 'Atlassian1', | ||
'description' => 'description-updated', | ||
'links' => (object) [ | ||
'avatar' => (object) [ | ||
'href' => '', | ||
], | ||
], | ||
'is_private' => true, | ||
]; | ||
|
||
$project = $client->workspaces('my-workspace')->projects()->update( | ||
'Atlassian1', | ||
$params | ||
); | ||
|
||
$this->assertCount(11, $project); | ||
} | ||
|
||
public function test_project_remove() | ||
{ | ||
$response = new ProjectRemoveResponse(); | ||
$client = $this->getClient($response); | ||
|
||
$project = $client->workspaces('my-workspace')->projects()->remove( | ||
'Atlassian1' | ||
); | ||
|
||
$this->assertCount(0, $project); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests; | ||
|
||
use Bitbucket\Client; | ||
use Bitbucket\HttpClient\Builder; | ||
use Bitbucket\Tests\responses\BaseResponse; | ||
use Http\Mock\Client as MockClient; | ||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
/** | ||
* @param BaseResponse $response | ||
* | ||
* @return Client | ||
*/ | ||
protected function getClient(BaseResponse $response) | ||
{ | ||
$mock_client = new MockClient($response); | ||
$builder = new Builder($mock_client); | ||
|
||
return new Client($builder); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests; | ||
|
||
use Bitbucket\Tests\responses\WorkspacesListResponse; | ||
use Bitbucket\Tests\responses\WorkspacesShowResponse; | ||
|
||
class WorkspacesTest extends TestCase | ||
{ | ||
public function test_workspaces_list() | ||
{ | ||
$response = new WorkspacesListResponse(); | ||
$client = $this->getClient($response); | ||
$workspaces = $client->workspaces('my-workspace')->list(); | ||
|
||
$this->assertCount(4, $workspaces); | ||
} | ||
|
||
public function test_workspace_show() | ||
{ | ||
$response = new WorkspacesShowResponse(); | ||
$client = $this->getClient($response); | ||
$workspace = $client->workspaces('my-workspace')->show(); | ||
|
||
$this->assertCount(7, $workspace); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests\responses; | ||
|
||
class BaseResponse | ||
{ | ||
/** | ||
* @param string $path | ||
* | ||
* @return string | ||
*/ | ||
protected function packagePath(string $path) | ||
{ | ||
return __DIR__.'/../'.$path; | ||
} | ||
|
||
/** | ||
* @param string $path | ||
* | ||
* @return false|string | ||
*/ | ||
protected function getJsonContent(string $path) | ||
{ | ||
return file_get_contents($this->packagePath($path)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests\responses; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Http\Message\ResponseFactory; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ProjectCreateResponse extends BaseResponse implements ResponseFactory | ||
{ | ||
/** | ||
* @param int $statusCode | ||
* @param null $reasonPhrase | ||
* @param array $headers | ||
* @param null $body | ||
* @param string $protocolVersion | ||
* | ||
* @return Response|ResponseInterface | ||
*/ | ||
public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $protocolVersion = '1.1') | ||
{ | ||
$json = $this->getJsonContent('stubs/project-create-success.json'); | ||
|
||
return new Response(200, ['Content-Type' => 'application/json'], $json); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests\responses; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Http\Message\ResponseFactory; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ProjectRemoveResponse extends BaseResponse implements ResponseFactory | ||
{ | ||
/** | ||
* @param int $statusCode | ||
* @param null $reasonPhrase | ||
* @param array $headers | ||
* @param null $body | ||
* @param string $protocolVersion | ||
* | ||
* @return Response|ResponseInterface | ||
*/ | ||
public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $protocolVersion = '1.1') | ||
{ | ||
$json = $this->getJsonContent('stubs/project-remove-success.json'); | ||
|
||
return new Response(200, ['Content-Type' => 'application/json'], $json); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests\responses; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Http\Message\ResponseFactory; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ProjectUpdateResponse extends BaseResponse implements ResponseFactory | ||
{ | ||
/** | ||
* @param int $statusCode | ||
* @param null $reasonPhrase | ||
* @param array $headers | ||
* @param null $body | ||
* @param string $protocolVersion | ||
* | ||
* @return Response|ResponseInterface | ||
*/ | ||
public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $protocolVersion = '1.1') | ||
{ | ||
$json = $this->getJsonContent('stubs/project-update-success.json'); | ||
|
||
return new Response(200, ['Content-Type' => 'application/json'], $json); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Bitbucket\Tests\responses; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Http\Message\ResponseFactory; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ProjectsAllResponse extends BaseResponse implements ResponseFactory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong to implement this interface, when you then disregard the parameters. |
||
{ | ||
/** | ||
* @param int $statusCode | ||
* @param null $reasonPhrase | ||
* @param array $headers | ||
* @param null $body | ||
* @param string $protocolVersion | ||
* | ||
* @return Response|ResponseInterface | ||
*/ | ||
public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $protocolVersion = '1.1') | ||
{ | ||
$json = $this->getJsonContent('stubs/projects-all-success.json'); | ||
|
||
return new Response(200, ['Content-Type' => 'application/json'], $json); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete this. There is no such API.