Skip to content

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8003181
[NS] First Commit
SanaviaNicolas Jun 26, 2020
88f0461
[GF] Setup tests
Jun 29, 2020
94e6840
[NS] update tests
SanaviaNicolas Jun 29, 2020
7d06940
[GF] Removed unused dependency + add test script for composer
Jun 29, 2020
be8ce6b
[GF] Fix ci
Jun 29, 2020
fc710b2
[GF] Removed unused dependencies
Jun 29, 2020
938480b
[NS] fix tests
SanaviaNicolas Jun 29, 2020
426bb9c
Merge branch 'added-project-and-workspace' of github.com:offline-agen…
SanaviaNicolas Jun 29, 2020
685fec8
[GF] Fix test and removed composer script
Jun 29, 2020
daf93c1
[GF] Fix test
Jun 29, 2020
499a83b
[NS] remove docs
SanaviaNicolas Jun 29, 2020
09538e6
[NS] fix and update tests
SanaviaNicolas Jun 29, 2020
b5243de
Merge branch 'added-project-and-workspace' of github.com:offline-agen…
SanaviaNicolas Jun 29, 2020
c35a591
Merge remote-tracking branch 'upstream/3.0' into added-project-and-wo…
SanaviaNicolas Jun 29, 2020
bc0a1e0
[NS] revert last change
SanaviaNicolas Jun 29, 2020
3b0079e
[NS] use interface
SanaviaNicolas Jun 29, 2020
d166b8d
[NS] revert last change
SanaviaNicolas Jun 29, 2020
fce732a
[NS] fix update on teams/projects + fix projects tests
SanaviaNicolas Jun 29, 2020
f985d66
Apply fixes from StyleCI
Jun 29, 2020
93a295e
Merge pull request #1 from offline-agency/analysis-J2EDvQ
Jun 29, 2020
a65d013
[GF] Fix requested changes
Jun 29, 2020
8dae0a0
Apply fixes from StyleCI
Jun 29, 2020
45f309b
Merge pull request #2 from offline-agency/analysis-EAB5pZ
Jun 29, 2020
ab45989
[GF] Fix import + moved dependencies to require-dev
Jun 29, 2020
b040d79
Merge remote-tracking branch 'upstream/3.0' into added-project-and-wo…
Jun 30, 2020
2e91bd5
[GF] Update tests
Jun 30, 2020
7898d70
Apply fixes from StyleCI
Jun 30, 2020
693245a
Merge pull request #3 from offline-agency/analysis-D2K7vn
Jun 30, 2020
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"require-dev": {
"graham-campbell/analyzer": "^2.4",
"phpunit/phpunit": "^8.5|^9.0",
"php-http/guzzle6-adapter": "^2.0"
"php-http/guzzle6-adapter": "^2.0",
"php-http/mock-client": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
51 changes: 51 additions & 0 deletions src/Api/Repositories/Workspaces/Repositories.php
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
Copy link
Member

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.

{
/**
* @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);
}
}
14 changes: 14 additions & 0 deletions src/Api/Workspaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
Copy link
Member

Choose a reason for hiding this comment

The 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
*
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Workspaces/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function show(string $project, array $params = [])
*
* @return array
*/
public function update(string $project, array $params = [])
Copy link
Member

Choose a reason for hiding this comment

The 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);

Expand Down Expand Up @@ -104,6 +104,6 @@ public function remove(string $project, array $params = [])
*/
protected function buildProjectsPath(string ...$parts)
{
return static::buildPath('workspaces', $this->username, 'projects', ...$parts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This typo, and a few others are already fixed on 3.0.

return static::buildPath('workspaces', $this->workspace, 'projects', ...$parts);
}
}
91 changes: 91 additions & 0 deletions tests/ProjectsTest.php
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);
}
}
25 changes: 25 additions & 0 deletions tests/TestCase.php
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);
}
}
27 changes: 27 additions & 0 deletions tests/WorkspacesTest.php
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);
}
}
26 changes: 26 additions & 0 deletions tests/responses/BaseResponse.php
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));
}
}
26 changes: 26 additions & 0 deletions tests/responses/ProjectCreateResponse.php
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);
}
}
26 changes: 26 additions & 0 deletions tests/responses/ProjectRemoveResponse.php
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);
}
}
26 changes: 26 additions & 0 deletions tests/responses/ProjectUpdateResponse.php
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);
}
}
26 changes: 26 additions & 0 deletions tests/responses/ProjectsAllResponse.php
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
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
Loading