|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Bitbucket\Tests; |
| 6 | + |
| 7 | +use Bitbucket\Client; |
| 8 | +use Bitbucket\HttpClient\Builder; |
| 9 | +use Http\Mock\Client as MockClient; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +/** |
| 13 | + * Tests API URLs constructed in Src and Downloads API classes. |
| 14 | + */ |
| 15 | +class ApiUrlTest extends TestCase |
| 16 | +{ |
| 17 | + protected MockClient $httpClient; |
| 18 | + protected Client $client; |
| 19 | + |
| 20 | + public function setUp(): void |
| 21 | + { |
| 22 | + $this->httpClient = new MockClient(); |
| 23 | + $this->client = new Client(new Builder($this->httpClient)); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Src::show |
| 28 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Src::buildSrcUri |
| 29 | + * |
| 30 | + * @dataProvider dataProvider |
| 31 | + */ |
| 32 | + public function testWorkspaceSrcShowUri(string $fileName): void |
| 33 | + { |
| 34 | + $this->client->repositories() |
| 35 | + ->workspaces('my-workspace') |
| 36 | + ->src('my-project') |
| 37 | + ->show('main', $fileName); |
| 38 | + |
| 39 | + $this->assertSame( |
| 40 | + "https://api.bitbucket.org/2.0/repositories/my-workspace/my-project/src/main/$fileName?format=meta", |
| 41 | + (string) $this->httpClient->getLastRequest()->getUri() |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Src::download |
| 47 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Src::buildSrcUri |
| 48 | + * |
| 49 | + * @dataProvider dataProvider |
| 50 | + */ |
| 51 | + public function testWorkspaceSrcDownloadUri(string $fileName): void |
| 52 | + { |
| 53 | + $this->client->repositories() |
| 54 | + ->workspaces('my-workspace') |
| 55 | + ->src('my-project') |
| 56 | + ->download('main', $fileName); |
| 57 | + |
| 58 | + $this->assertSame( |
| 59 | + "https://api.bitbucket.org/2.0/repositories/my-workspace/my-project/src/main/$fileName", |
| 60 | + (string) $this->httpClient->getLastRequest()->getUri() |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Downloads::download |
| 66 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Downloads::buildDownloadsUri |
| 67 | + * |
| 68 | + * @dataProvider dataProvider |
| 69 | + */ |
| 70 | + public function testWorkspaceDownloadUri(string $fileName): void |
| 71 | + { |
| 72 | + $this->client->repositories() |
| 73 | + ->workspaces('my-workspace') |
| 74 | + ->downloads('my-project') |
| 75 | + ->download($fileName); |
| 76 | + |
| 77 | + $this->assertSame( |
| 78 | + "https://api.bitbucket.org/2.0/repositories/my-workspace/my-project/downloads/$fileName", |
| 79 | + (string) $this->httpClient->getLastRequest()->getUri() |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Downloads::remove |
| 85 | + * @covers \Bitbucket\Api\Repositories\Workspaces\Downloads::buildDownloadsUri |
| 86 | + * |
| 87 | + * @dataProvider dataProvider |
| 88 | + */ |
| 89 | + public function testWorkspaceRemoveUri(string $fileName): void |
| 90 | + { |
| 91 | + $this->client->repositories() |
| 92 | + ->workspaces('my-workspace') |
| 93 | + ->downloads('my-project') |
| 94 | + ->remove($fileName); |
| 95 | + |
| 96 | + $this->assertSame( |
| 97 | + "https://api.bitbucket.org/2.0/repositories/my-workspace/my-project/downloads/$fileName", |
| 98 | + (string) $this->httpClient->getLastRequest()->getUri() |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public static function dataProvider(): array |
| 103 | + { |
| 104 | + return [ |
| 105 | + 'File in root' => ['README.md'], |
| 106 | + 'File in subdirectory' => ['docs/contributing/CODE_OF_CONDUCT.md'], |
| 107 | + ]; |
| 108 | + } |
| 109 | +} |
0 commit comments