2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-03-08 13:17:22 +00:00
|
|
|
namespace Composer\Test\Repository;
|
2012-02-18 16:06:30 +00:00
|
|
|
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2022-02-22 15:47:09 +00:00
|
|
|
use Composer\Util\Platform;
|
2012-02-18 16:06:30 +00:00
|
|
|
use Symfony\Component\Process\ExecutableFinder;
|
|
|
|
use Composer\Package\Dumper\ArrayDumper;
|
|
|
|
use Composer\Repository\VcsRepository;
|
|
|
|
use Composer\Util\Filesystem;
|
|
|
|
use Composer\Util\ProcessExecutor;
|
|
|
|
use Composer\IO\NullIO;
|
2012-04-25 15:35:47 +00:00
|
|
|
use Composer\Config;
|
2012-02-18 16:06:30 +00:00
|
|
|
|
2012-05-06 13:10:13 +00:00
|
|
|
/**
|
|
|
|
* @group slow
|
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
class VcsRepositoryTest extends TestCase
|
2012-02-18 16:06:30 +00:00
|
|
|
{
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2013-10-10 20:57:03 +00:00
|
|
|
private static $composerHome;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-02-18 16:06:30 +00:00
|
|
|
private static $gitRepo;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var ?string
|
|
|
|
*/
|
|
|
|
private $skipped = null;
|
2012-02-18 16:06:30 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
protected function initialize(): void
|
2012-02-18 16:06:30 +00:00
|
|
|
{
|
|
|
|
$locator = new ExecutableFinder();
|
|
|
|
if (!$locator->find('git')) {
|
2012-05-06 13:10:13 +00:00
|
|
|
$this->skipped = 'This test needs a git binary in the PATH to be able to run';
|
2012-06-14 10:10:01 +00:00
|
|
|
|
2012-02-18 16:06:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-02-18 12:03:34 +00:00
|
|
|
|
2022-02-22 15:47:09 +00:00
|
|
|
$oldCwd = Platform::getCwd();
|
2022-05-11 14:05:35 +00:00
|
|
|
self::$composerHome = self::getUniqueTmpDirectory();
|
|
|
|
self::$gitRepo = self::getUniqueTmpDirectory();
|
2019-02-18 12:03:34 +00:00
|
|
|
|
|
|
|
if (!@chdir(self::$gitRepo)) {
|
2020-10-08 09:04:39 +00:00
|
|
|
$this->skipped = 'Could not move into the temp git repo '.self::$gitRepo;
|
2012-06-14 10:10:01 +00:00
|
|
|
|
2012-02-18 16:06:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// init
|
|
|
|
$process = new ProcessExecutor;
|
2022-08-17 12:20:07 +00:00
|
|
|
$exec = static function ($command) use ($process): void {
|
2022-02-22 15:47:09 +00:00
|
|
|
$cwd = Platform::getCwd();
|
2013-02-15 23:15:18 +00:00
|
|
|
if ($process->execute($command, $output, $cwd) !== 0) {
|
|
|
|
throw new \RuntimeException('Failed to execute '.$command.': '.$process->getErrorOutput());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-30 16:54:14 +00:00
|
|
|
$exec('git init -q');
|
|
|
|
$exec('git checkout -b master');
|
2013-02-18 07:34:23 +00:00
|
|
|
$exec('git config user.email composertest@example.org');
|
|
|
|
$exec('git config user.name ComposerTest');
|
2019-02-18 12:03:34 +00:00
|
|
|
$exec('git config commit.gpgsign false');
|
2012-02-18 16:06:30 +00:00
|
|
|
touch('foo');
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git add foo');
|
|
|
|
$exec('git commit -m init');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
// non-composed tag & branch
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git tag 0.5.0');
|
|
|
|
$exec('git branch oldbranch');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
// add composed tag & master branch
|
2022-08-17 12:20:07 +00:00
|
|
|
$composer = ['name' => 'a/b'];
|
2012-02-18 16:06:30 +00:00
|
|
|
file_put_contents('composer.json', json_encode($composer));
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git add composer.json');
|
|
|
|
$exec('git commit -m addcomposer');
|
|
|
|
$exec('git tag 0.6.0');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
// add feature-a branch
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git checkout -b feature/a-1.0-B');
|
2012-02-18 16:06:30 +00:00
|
|
|
file_put_contents('foo', 'bar feature');
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git add foo');
|
|
|
|
$exec('git commit -m change-a');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
// add version to composer.json
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git checkout master');
|
2012-02-18 16:06:30 +00:00
|
|
|
$composer['version'] = '1.0.0';
|
|
|
|
file_put_contents('composer.json', json_encode($composer));
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git add composer.json');
|
|
|
|
$exec('git commit -m addversion');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
// create tag with wrong version in it
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git tag 0.9.0');
|
2012-02-18 16:06:30 +00:00
|
|
|
// create tag with correct version in it
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git tag 1.0.0');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
// add feature-b branch
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git checkout -b feature-b');
|
2012-02-18 16:06:30 +00:00
|
|
|
file_put_contents('foo', 'baz feature');
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git add foo');
|
|
|
|
$exec('git commit -m change-b');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
// add 1.0 branch
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git checkout master');
|
|
|
|
$exec('git branch 1.0');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
2012-02-18 18:00:40 +00:00
|
|
|
// add 1.0.x branch
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git branch 1.1.x');
|
2012-02-18 18:00:40 +00:00
|
|
|
|
2012-02-18 16:06:30 +00:00
|
|
|
// update master to 2.0
|
|
|
|
$composer['version'] = '2.0.0';
|
|
|
|
file_put_contents('composer.json', json_encode($composer));
|
2013-02-15 23:15:18 +00:00
|
|
|
$exec('git add composer.json');
|
|
|
|
$exec('git commit -m bump-version');
|
2012-02-18 16:06:30 +00:00
|
|
|
|
|
|
|
chdir($oldCwd);
|
|
|
|
}
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2012-02-18 16:06:30 +00:00
|
|
|
{
|
2012-05-06 13:10:13 +00:00
|
|
|
if (!self::$gitRepo) {
|
|
|
|
$this->initialize();
|
|
|
|
}
|
|
|
|
if ($this->skipped) {
|
|
|
|
$this->markTestSkipped($this->skipped);
|
2012-02-18 16:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public static function tearDownAfterClass(): void
|
2012-02-18 16:06:30 +00:00
|
|
|
{
|
|
|
|
$fs = new Filesystem;
|
2013-10-10 20:57:03 +00:00
|
|
|
$fs->removeDirectory(self::$composerHome);
|
2012-02-18 16:06:30 +00:00
|
|
|
$fs->removeDirectory(self::$gitRepo);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testLoadVersions(): void
|
2012-02-18 16:06:30 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [
|
2012-02-18 16:06:30 +00:00
|
|
|
'0.6.0' => true,
|
|
|
|
'1.0.0' => true,
|
2012-02-18 18:00:40 +00:00
|
|
|
'1.0.x-dev' => true,
|
2012-04-13 00:47:55 +00:00
|
|
|
'1.1.x-dev' => true,
|
2012-02-18 16:06:30 +00:00
|
|
|
'dev-feature-b' => true,
|
2012-08-23 22:43:40 +00:00
|
|
|
'dev-feature/a-1.0-B' => true,
|
2012-02-18 16:06:30 +00:00
|
|
|
'dev-master' => true,
|
2020-05-06 11:23:52 +00:00
|
|
|
'9999999-dev' => true, // alias of dev-master
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2012-02-18 16:06:30 +00:00
|
|
|
|
2013-10-10 20:57:03 +00:00
|
|
|
$config = new Config();
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge([
|
|
|
|
'config' => [
|
2013-10-10 20:57:03 +00:00
|
|
|
'home' => self::$composerHome,
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
]);
|
2019-02-18 12:03:34 +00:00
|
|
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();
|
2022-08-17 12:20:07 +00:00
|
|
|
$repo = new VcsRepository(['url' => self::$gitRepo, 'type' => 'vcs'], new NullIO, $config, $httpDownloader);
|
2012-02-18 16:06:30 +00:00
|
|
|
$packages = $repo->getPackages();
|
|
|
|
$dumper = new ArrayDumper();
|
|
|
|
|
|
|
|
foreach ($packages as $package) {
|
|
|
|
if (isset($expected[$package->getPrettyVersion()])) {
|
|
|
|
unset($expected[$package->getPrettyVersion()]);
|
|
|
|
} else {
|
|
|
|
$this->fail('Unexpected version '.$package->getPrettyVersion().' in '.json_encode($dumper->dump($package)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty($expected, 'Missing versions: '.implode(', ', array_keys($expected)));
|
2012-02-18 16:06:30 +00:00
|
|
|
}
|
|
|
|
}
|