Skip to content

Commit 1c39d0d

Browse files
committed
test(api): Test build create
1 parent 7373272 commit 1c39d0d

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ composer.phar
88
.phan
99
/builds
1010
.env
11+
tests/Mock/Source.zip

app/Support/PrefixerClient.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public function project(int $projectId)
4646
return $this->request('GET', '/projects/'.$projectId);
4747
}
4848

49-
public function createBuild(int $projectId, $zipFilename, $githubAccessToken = null)
49+
public function createBuild(int $projectId, $zipFile, $githubAccessToken = null)
5050
{
5151
$options = [
5252
'multipart' => [
5353
[
5454
'name' => 'uploaded_source_file',
55-
'filename' => basename($zipFilename),
56-
'contents' => Utils::tryFopen($zipFilename, 'r'),
55+
'filename' => basename($zipFile),
56+
'contents' => Utils::tryFopen($zipFile, 'r'),
5757
],
5858
],
5959
];
@@ -67,7 +67,7 @@ public function createBuild(int $projectId, $zipFilename, $githubAccessToken = n
6767

6868
return $this->request(
6969
'POST',
70-
'/projects/'.$projectId.'/build',
70+
'/projects/'.$projectId.'/builds',
7171
$options
7272
);
7373
}
@@ -99,15 +99,17 @@ public function downloadLog(int $projectId, int $buildId, $file)
9999

100100
private function request(string $method, $relApiUri = '', array $options = [])
101101
{
102-
$options = array_merge($this->jsonHeaders(), $options);
102+
$options = array_merge($this->headers(), $options);
103103

104104
$res = (new GuzzleClient())->request(
105-
'GET',
105+
$method,
106106
self::API_BASE_URI.$relApiUri,
107107
$options,
108108
);
109109

110-
if (200 === $res->getStatusCode()) {
110+
$statusCode = $res->getStatusCode();
111+
112+
if (200 === $statusCode || 201 === $statusCode) {
111113
if (\in_array('application/json', $res->getHeader('Content-Type'), true)) {
112114
return json_decode($res->getBody());
113115
}
@@ -118,11 +120,10 @@ private function request(string $method, $relApiUri = '', array $options = [])
118120
throw new Exception($res->getReasonPhrase(), $res->getStatusCode());
119121
}
120122

121-
private function jsonHeaders()
123+
private function headers()
122124
{
123125
return [
124126
'headers' => [
125-
'Content-Type' => 'application/json',
126127
'Accept' => 'application/json, text/plain, */*',
127128
'Authorization' => 'Bearer '.$this->personalAccessToken,
128129
],

phpunit.xml.dist

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="Commands">
13-
<directory suffix="Test.php">./tests/Commands</directory>
14-
</testsuite>
15-
<testsuite name="Support">
16-
<directory suffix="Test.php">./tests/Support</directory>
17-
</testsuite>
18-
</testsuites>
19-
<coverage processUncoveredFiles="true">
20-
<include>
21-
<directory suffix=".php">./app</directory>
22-
</include>
23-
</coverage>
2+
<phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
3+
<testsuites>
4+
<testsuite name="Commands">
5+
<directory suffix="Test.php">./tests/Commands</directory>
6+
</testsuite>
7+
<testsuite name="Support">
8+
<directory suffix="Test.php">./tests/Support</directory>
9+
</testsuite>
10+
</testsuites>
11+
<coverage processUncoveredFiles="true">
12+
<include>
13+
<directory suffix=".php">./app</directory>
14+
</include>
15+
</coverage>
16+
<groups>
17+
<exclude>
18+
<group>disabled</group>
19+
</exclude>
20+
</groups>
2421
</phpunit>

tests/Commands/PrefixCommandTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Tests\TestCase;
1616

1717
/**
18+
* @group disabled
1819
* @coversNothing
1920
*/
2021
final class PrefixCommandTest extends TestCase

tests/Support/PrefixerClientTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public function testProject()
4949

5050
public function testCreateBuild()
5151
{
52+
$projectId = (int) env('PROJECT_ID');
53+
$sourceDirectory = env('SOURCE_DIRECTORY');
54+
$projectZip = realpath($sourceDirectory.'/../Source.zip');
55+
$response = $this->apiClient()->createBuild($projectId, $projectZip);
56+
57+
$this->assertSame('initial-state', $response->build->state);
5258
}
5359

5460
public function testBuild()

0 commit comments

Comments
 (0)