Skip to content

Commit

Permalink
Made tests more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
roy.voetman committed Apr 28, 2024
1 parent a583ad7 commit 07a2951
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ All notable changes to `flysystem-gitlab-storage` will be documented in this fil
### 2.0.4 - 2020-12-16
- Savings HTTP exchanges with HEAD request

### 2.xx - 2024-xx-xx
### 3.0.0 - 2022-01-27
- Added flysystem v3 support.

### 3.1.0 - 2024-04-26
- Moved minimum PHP version to 8.1
10 changes: 6 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function read($path)
$headers = $response->getHeaders();
$headers = array_filter(
$headers,
fn($key) => substr($key, 0, 9) == 'X-Gitlab-',
fn($key) => substr($key, 0, 9) == 'x-gitlab-',
ARRAY_FILTER_USE_KEY
);

Expand Down Expand Up @@ -294,9 +294,11 @@ private function request(string $method, string $uri, array $params = []): Respo
private function buildUri(string $uri, array $params = []): string
{
$params = array_merge(['ref' => $this->branch], $params);

$params = array_map('urlencode', $params);


$params = array_map(function($value) {
return $value !== null ? urlencode($value) : null;
}, $params);

if(isset($params['path'])) {
$params['path'] = urldecode($params['path']);
}
Expand Down
4 changes: 4 additions & 0 deletions src/GitlabAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ public function directoryExists(string $path): bool

return (bool)count($tree->current());
} catch (Throwable $e) {
if ($e instanceof ClientException && $e->getCode() == 404) {
return false;
}

throw UnableToCheckExistence::forLocation($path, $e);
}
}
Expand Down
24 changes: 23 additions & 1 deletion tests/GitlabAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,12 @@ public function it_can_retrieve_a_list_of_contents_of_root_recursive()
$list = $this->gitlabAdapter->listContents('/', true);
$expectedPaths = [
['type' => 'dir', 'path' => 'recursive'],
['type' => 'dir', 'path' => 'recursive/level-1'],
['type' => 'dir', 'path' => 'recursive/level-1/level-2'],
['type' => 'file', 'path' => 'LICENSE'],
['type' => 'file', 'path' => 'README.md'],
['type' => 'file', 'path' => 'recursive/recursive.testing.md'],
['type' => 'file', 'path' => 'recursive/level-1/level-2/.gitkeep'],
['type' => 'file', 'path' => 'test'],
['type' => 'file', 'path' => 'test2'],
];
Expand All @@ -309,7 +312,26 @@ public function it_can_retrieve_a_list_of_contents_of_sub_folder()
{
$list = $this->gitlabAdapter->listContents('/recursive', false);
$expectedPaths = [
['type' => 'file', 'path' => 'recursive/recursive.testing.md']
['type' => 'dir', 'path' => 'recursive/level-1'],
['type' => 'dir', 'path' => 'recursive/level-1/level-2'],
['type' => 'file', 'path' => 'recursive/recursive.testing.md'],
['type' => 'file', 'path' => 'recursive/level-1/level-2/.gitkeep'],
];

foreach ($list as $item) {
$this->assertInstanceOf(StorageAttributes::class, $item);
$this->assertContains(
['type' => $item['type'], 'path' => $item['path']], $expectedPaths
);
}
}

#[Test]
public function it_can_retrieve_a_list_of_contents_of_deep_sub_folder()
{
$list = $this->gitlabAdapter->listContents('/recursive/level-1/level-2', false);
$expectedPaths = [
['type' => 'file', 'path' => 'recursive/level-1/level-2/.gitkeep'],
];

foreach ($list as $item) {
Expand Down

0 comments on commit 07a2951

Please sign in to comment.