Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 240 additions & 0 deletions Tests/Package/Actions/ArtifactsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
<?php

/**
* @copyright Copyright (C) 2005 - 2026 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Github\Tests\Package\Actions;

use Joomla\Github\Package\Actions\Artifacts;
use Joomla\Github\Tests\Stub\GitHubTestCase;
use Joomla\Http\Exception\UnexpectedResponseException;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* Test class for the GitHub API package.
*
* @since __DEPLOY_VERSION__
*/
#[CoversClass(Artifacts::class)]
class ArtifactsTest extends GitHubTestCase
{
/**
* @var Artifacts Object under test.
* @since __DEPLOY_VERSION__
*/
protected $object;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

$this->object = new Artifacts($this->options, $this->client);
}

/**
* Tests the getListForRepo method.
*
* @return void
*/
public function testGetListForRepo()
{
$this->client->expects($this->once())
->method('get')
->with('/repos/joomla/joomla-platform/actions/artifacts?page=2&per_page=30&name=name-value', [], 0)
->willReturn($this->response);

$this->assertEquals(json_decode($this->sampleString), $this->object->getListForRepo('joomla', 'joomla-platform', ['name' => 'name-value'], 2, 30));
}

/**
* Tests the getListForRepo method.
*
* @return void
*/
public function testGetListForRepoDefaults()
{
$this->client->expects($this->once())
->method('get')
->with('/repos/joomla/joomla-platform/actions/artifacts', [], 0)
->willReturn($this->response);

$this->assertEquals(json_decode($this->sampleString), $this->object->getListForRepo('joomla', 'joomla-platform'));
}

/**
* Tests the getListForRepo method.
*
* @return void
*/
public function testGetListForRepoFailure()
{
$this->expectException(UnexpectedResponseException::class);

$this->response = $this->getResponseObject($this->errorString, 500);

$this->client->expects($this->once())
->method('get')
->willReturn($this->response);

$this->object->getListForRepo('joomla', 'joomla-platform', ['name' => 'name-value'], 2, 30);
}

/**
* Tests the getListForRun method.
*
* @return void
*/
public function testGetListForRun()
{
$this->client->expects($this->once())
->method('get')
->with('/repos/joomla/joomla-platform/actions/runs/1/artifacts?page=2&per_page=30&name=name-value', [], 0)
->willReturn($this->response);

$this->assertEquals(json_decode($this->sampleString), $this->object->getListForRun('joomla', 'joomla-platform', 1, ['name' => 'name-value'], 2, 30));
}

/**
* Tests the getListForRun method.
*
* @return void
*/
public function testGetListForRunDefaults()
{
$this->client->expects($this->once())
->method('get')
->with('/repos/joomla/joomla-platform/actions/runs/1/artifacts', [], 0)
->willReturn($this->response);

$this->assertEquals(json_decode($this->sampleString), $this->object->getListForRun('joomla', 'joomla-platform', 1));
}

/**
* Tests the getListForRun method.
*
* @return void
*/
public function testGetListForRunFailure()
{
$this->expectException(UnexpectedResponseException::class);

$this->response = $this->getResponseObject($this->errorString, 500);

$this->client->expects($this->once())
->method('get')
->willReturn($this->response);

$this->object->getListForRun('joomla', 'joomla-platform', 1, ['name' => 'name-value'], 2, 30);
}

/**
* Tests the get method.
*
* @return void
*/
public function testGet()
{
$this->client->expects($this->once())
->method('get')
->with('/repos/joomla/joomla-platform/actions/artifacts/1', [], 0)
->willReturn($this->response);

$this->assertEquals(json_decode($this->sampleString), $this->object->get('joomla', 'joomla-platform', 1));
}

/**
* Tests the get method.
*
* @return void
*/
public function testGetFailure()
{
$this->expectException(UnexpectedResponseException::class);

$this->response = $this->getResponseObject($this->errorString, 500);

$this->client->expects($this->once())
->method('get')
->willReturn($this->response);

$this->object->get('joomla', 'joomla-platform', 1);
}

/**
* Tests the delete method.
*
* @return void
*/
public function testDelete()
{
$this->response = $this->getResponseObject('', 204);

$this->client->expects($this->once())
->method('delete')
->with('/repos/joomla/joomla-platform/actions/artifacts/1', [], 0)
->willReturn($this->response);

$this->assertNull($this->object->delete('joomla', 'joomla-platform', 1));
}

/**
* Tests the delete method.
*
* @return void
*/
public function testDeleteFailure()
{
$this->expectException(UnexpectedResponseException::class);

$this->response = $this->getResponseObject($this->errorString, 500);

$this->client->expects($this->once())
->method('delete')
->willReturn($this->response);

$this->object->delete('joomla', 'joomla-platform', 1);
}

/**
* Tests the download method.
*
* @return void
*/
public function testDownload()
{
$this->response = $this->getResponseObject('', 302, ['Location' => 'https://example.com/download']);

$this->client->expects($this->once())
->method('get')
->with('/repos/joomla/joomla-platform/actions/artifacts/1/zip', [], 0)
->willReturn($this->response);

$this->assertSame('https://example.com/download', $this->object->download('joomla', 'joomla-platform', 1, 'zip'));
}

/**
* Tests the download method.
*
* @return void
*/
public function testDownloadFailure()
{
$this->expectException(UnexpectedResponseException::class);

$this->response = $this->getResponseObject($this->errorString, 500);

$this->client->expects($this->once())
->method('get')
->willReturn($this->response);

$this->object->download('joomla', 'joomla-platform', 1, 'zip');
}
}
Loading