Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Jun 26, 2024
1 parent 78edc31 commit b3e174e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ public function listRepositoryContents(string $owner, string $repositoryName, st

$items = [];

if (isset($response['body'][0])) {
if (!empty($response['body'][0])) {
$items = $response['body'];
} else {
} elseif (!empty($response['body'])) {
$items = [$response['body']];
}

Expand Down
27 changes: 27 additions & 0 deletions tests/VCS/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\TestCase;
use Utopia\Http\Http;
use Utopia\VCS\Adapter\Git;
use Utopia\VCS\Adapter\Git\GitHub;

abstract class Base extends TestCase
{
Expand Down Expand Up @@ -83,6 +84,32 @@ public function testListRepositoryContents(): void
$contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', 'src/Appwrite');
$this->assertIsArray($contents);
$this->assertNotEmpty($contents);


$contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', '');
$this->assertIsArray($contents);
$this->assertNotEmpty($contents);
$this->assertGreaterThan(0, \count($contents));

$fileContent = null;
foreach ($contents as $content) {
if ($content['type'] === GitHub::CONTENTS_FILE) {
$fileContent = $content;
break;
}
}
$this->assertNotNull($fileContent);
$this->assertStringContainsString('.', $fileContent['name']);

$directoryContent = null;
foreach ($contents as $content) {
if ($content['type'] === GitHub::CONTENTS_DIRECTORY) {
$directoryContent = $content;
break;
}
}
$this->assertNotNull($directoryContent);
$this->assertEquals(0, $directoryContent['size']);
}

public function testCreateRepository(): void
Expand Down

0 comments on commit b3e174e

Please sign in to comment.