-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBase.php
More file actions
142 lines (114 loc) · 4.59 KB
/
Base.php
File metadata and controls
142 lines (114 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace Utopia\Tests;
use Exception;
use PHPUnit\Framework\TestCase;
use Utopia\System\System;
use Utopia\VCS\Adapter\Git;
use Utopia\VCS\Adapter\Git\GitHub;
abstract class Base extends TestCase
{
protected Git $vcsAdapter;
protected function setUp(): void
{
$this->vcsAdapter = $this->createVCSAdapter();
}
abstract protected function createVCSAdapter(): Git;
abstract public function testUpdateComment(): void;
abstract public function testGenerateCloneCommand(): void;
abstract public function testGenerateCloneCommandWithCommitHash(): void;
abstract public function testgetEvent(): void;
abstract public function testGetRepositoryName(): void;
abstract public function testGetComment(): void;
abstract public function testGetPullRequest(): void;
abstract public function testGetRepositoryTree(): void;
public function testGetPullRequestFromBranch(): void
{
$result = $this->vcsAdapter->getPullRequestFromBranch('vermakhushboo', 'basic-js-crud', 'test');
$this->assertIsArray($result);
$this->assertNotEmpty($result);
}
public function testGetOwnerName(): void
{
$installationId = System::getEnv('INSTALLATION_ID') ?? '';
$owner = $this->vcsAdapter->getOwnerName($installationId);
$this->assertSame('test-kh', $owner);
}
public function testSearchRepositories(): void
{
$repos = $this->vcsAdapter->searchRepositories('test-kh', 1, 2);
$this->assertCount(2, $repos);
}
public function testCreateComment(): void
{
$commentId = $this->vcsAdapter->createComment('test-kh', 'test2', 1, 'hello');
$this->assertNotEmpty($commentId);
}
public function testListBranches(): void
{
$branches = $this->vcsAdapter->listBranches('vermakhushboo', 'basic-js-crud');
$this->assertIsArray($branches);
$this->assertNotEmpty($branches);
}
public function testListRepositoryLanguages(): void
{
$languages = $this->vcsAdapter->listRepositoryLanguages('vermakhushboo', 'basic-js-crud');
$this->assertIsArray($languages);
$this->assertContains('JavaScript', $languages);
$this->assertContains('HTML', $languages);
$this->assertContains('CSS', $languages);
}
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));
// Test with ref parameter
$contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', '', 'main');
$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->assertNotEmpty($fileContent['name']);
$this->assertStringContainsString('.', $fileContent['name']);
$this->assertIsNumeric($fileContent['size']);
$this->assertGreaterThan(0, $fileContent['size']);
$directoryContent = null;
foreach ($contents as $content) {
if ($content['type'] === GitHub::CONTENTS_DIRECTORY) {
$directoryContent = $content;
break;
}
}
$this->assertNotNull($directoryContent);
$this->assertNotEmpty($directoryContent['name']);
$this->assertIsNumeric($directoryContent['size']);
$this->assertSame(0, $directoryContent['size']);
}
public function testCreateRepository(): void
{
$repository = $this->vcsAdapter->createRepository('test-kh', 'new-repo', true);
$this->assertIsArray($repository);
$this->assertSame('test-kh/new-repo', $repository['full_name']);
}
/**
* @depends testCreateRepository
*/
public function testDeleteRepository(): void
{
$result = $this->vcsAdapter->deleteRepository('test-kh', 'new-repo');
$this->assertSame(true, $result);
$this->expectException(Exception::class);
$result = $this->vcsAdapter->deleteRepository('test-kh', 'new-repo-2');
}
}