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
|
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Intl\Tests\Util;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Exception\RuntimeException;
use Symfony\Component\Intl\Util\GitRepository;
#[\PHPUnit\Framework\Attributes\Group('intl-data')]
class GitRepositoryTest extends TestCase
{
private ?string $targetDir = null;
private const REPO_URL = 'https://github.com/symfony/intl.git';
#[\PHPUnit\Framework\Attributes\Before]
#[\PHPUnit\Framework\Attributes\After]
protected function cleanup()
{
$this->targetDir = sys_get_temp_dir().'/GitRepositoryTest/source';
$fs = new Filesystem();
$fs->remove($this->targetDir);
}
public function testItThrowsAnExceptionIfInitialisedWithNonGitDirectory()
{
$this->expectException(RuntimeException::class);
@mkdir($this->targetDir, 0777, true);
new GitRepository($this->targetDir);
}
public function testItClonesTheRepository()
{
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
$this->assertInstanceOf(GitRepository::class, $git);
$this->assertDirectoryExists($this->targetDir.'/.git');
$this->assertSame($this->targetDir, $git->getPath());
$this->assertSame(self::REPO_URL, $git->getUrl());
$this->assertMatchesRegularExpression('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
$this->assertNotEmpty($git->getLastAuthor());
$this->assertInstanceOf(\DateTimeImmutable::class, $git->getLastAuthoredDate());
$this->assertStringMatchesFormat('v%s', $git->getLastTag());
$this->assertStringMatchesFormat('v3%s', $git->getLastTag(fn ($tag) => str_starts_with($tag, 'v3')));
}
public function testItCheckoutsToTheLastTag()
{
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
$lastCommitHash = $git->getLastCommitHash();
$lastV3Tag = $git->getLastTag(fn ($tag) => str_starts_with($tag, 'v3'));
$git->checkout($lastV3Tag);
$this->assertNotEquals($lastCommitHash, $git->getLastCommitHash());
}
}
|