Skip to content

Commit dfc7421

Browse files
committed
Add integration tests
1 parent f3bb86e commit dfc7421

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

tests/Integration/BuildTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Aternos\BlobBuild\Test\Integration;
4+
5+
class BuildTest extends IntegrationTestCase
6+
{
7+
public function testGetProject(): void
8+
{
9+
$build = $this->client->getLatestProjectBuildInChannel("SoundMuffler", "Dev");
10+
$this->assertEquals("SoundMuffler", $build->getData()->getProjectName());
11+
12+
$project = $build->getProject();
13+
$this->assertEquals("SoundMuffler", $project->getData()->getName());
14+
}
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Aternos\BlobBuild\Test\Integration;
4+
5+
use Aternos\BlobBuild\Client\BlobBuildAPIClient;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class IntegrationTestCase extends TestCase
9+
{
10+
protected ?string $apiToken;
11+
protected BlobBuildAPIClient $client;
12+
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
$this->client = new BlobBuildAPIClient();
17+
$this->client->setUserAgent("aternos/[email protected] ([email protected])");
18+
$this->apiToken = getenv("BLOB_BUILD_API_TOKEN") ?: null;
19+
if ($this->apiToken !== null) {
20+
$this->client->setApiToken($this->apiToken);
21+
}
22+
}
23+
}

tests/Integration/ProjectTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Aternos\BlobBuild\Test\Integration;
4+
5+
class ProjectTest extends IntegrationTestCase
6+
{
7+
public function testSearch(): void
8+
{
9+
$projects = $this->client->searchProjects("sound");
10+
$this->assertNotEmpty($projects);
11+
$this->assertCount(1, $projects);
12+
13+
$build = $projects[0]->getLatestBuildInDefaultChannel();
14+
$this->assertEquals("SoundMuffler", $build->getData()->getProjectName());
15+
}
16+
17+
public function testGetProject(): void
18+
{
19+
$project = $this->client->getProject("SoundMuffler");
20+
$this->assertEquals("SoundMuffler", $project->getData()->getName());
21+
$this->assertEquals("https://blob.build/project/SoundMuffler", $project->getPageUrl());
22+
}
23+
24+
public function testGetBuilds(): void
25+
{
26+
$project = $this->client->getProject("SoundMuffler");
27+
$builds = $project->getBuilds();
28+
$this->assertArrayHasKey("Dev", $builds);
29+
$this->assertNotEmpty($builds["Dev"]);
30+
}
31+
32+
public function testGetLatestBuildInChannel(): void
33+
{
34+
$project = $this->client->getProject("SoundMuffler");
35+
$build = $project->getLatestBuildInChannel("Dev");
36+
$this->assertEquals("SoundMuffler", $build->getData()->getProjectName());
37+
}
38+
39+
public function testGetLatestBuildInDefaultChannel(): void
40+
{
41+
$project = $this->client->getProject("SoundMuffler");
42+
$build = $project->getLatestBuildInDefaultChannel();
43+
$this->assertEquals("SoundMuffler", $build->getData()->getProjectName());
44+
}
45+
46+
public function testGetBuild(): void
47+
{
48+
$project = $this->client->getProject("SoundMuffler");
49+
$build = $project->getBuild("Dev", 1);
50+
$this->assertEquals(1, $build->getData()->getBuildId());
51+
}
52+
}

tests/Integration/UserTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Aternos\BlobBuild\Test\Integration;
4+
5+
class UserTest extends IntegrationTestCase
6+
{
7+
public function testGetAuthenticatedUser(): void
8+
{
9+
if (!$this->apiToken) {
10+
$this->markTestSkipped("No API token provided");
11+
}
12+
$user = $this->client->getAuthenticatedUser();
13+
$this->assertEquals($this->apiToken, $user->getData()->getApiToken());
14+
$this->assertEmpty($user->getProjects());
15+
}
16+
}

0 commit comments

Comments
 (0)