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
|
<?php declare(strict_types=1);
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Util;
use Composer\Test\TestCase;
use Composer\Util\ForgejoUrl;
use PHPUnit\Framework\Attributes\DataProvider;
class ForgejoUrlTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('createProvider')]
public function testCreate(?string $repoUrl): void
{
$forgejoUrl = ForgejoUrl::tryFrom($repoUrl);
$this->assertNotNull($forgejoUrl);
$this->assertSame('codeberg.org', $forgejoUrl->originUrl);
$this->assertSame('acme', $forgejoUrl->owner);
$this->assertSame('repo', $forgejoUrl->repository);
$this->assertSame('https://codeberg.org/api/v1/repos/acme/repo', $forgejoUrl->apiUrl);
}
public static function createProvider(): array
{
return [
['git@codeberg.org:acme/repo.git'],
['https://codeberg.org/acme/repo'],
['https://codeberg.org/acme/repo.git'],
];
}
public function testCreateInvalid(): void
{
$this->expectException(\InvalidArgumentException::class);
ForgejoUrl::create('https://example.org');
}
public function testGenerateSshUrl(): void
{
$forgejoUrl = ForgejoUrl::create('git@codeberg.org:acme/repo.git');
$this->assertSame('git@codeberg.org:acme/repo.git', $forgejoUrl->generateSshUrl());
}
}
|