1
0
Fork 0
composer/tests/Composer/Test/Repository/VcsRepositoryTest.php

158 lines
4.6 KiB
PHP
Raw Normal View History

2012-02-18 16:06:30 +00:00
<?php
/*
* 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
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
/**
* @group slow
*/
2012-02-18 16:06:30 +00:00
class VcsRepositoryTest extends \PHPUnit_Framework_TestCase
{
private static $gitRepo;
private $skipped;
2012-02-18 16:06:30 +00:00
protected function initialize()
2012-02-18 16:06:30 +00:00
{
$oldCwd = getcwd();
2013-01-30 09:44:07 +00:00
self::$gitRepo = sys_get_temp_dir() . '/composer-git-'.mt_rand().'/';
2012-02-18 16:06:30 +00:00
$locator = new ExecutableFinder();
if (!$locator->find('git')) {
$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;
}
if (!mkdir(self::$gitRepo) || !chdir(self::$gitRepo)) {
$this->skipped = 'Could not create and 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;
$exec = function ($command) use ($process) {
$cwd = getcwd();
if ($process->execute($command, $output, $cwd) !== 0) {
throw new \RuntimeException('Failed to execute '.$command.': '.$process->getErrorOutput());
}
};
$exec('git init');
2013-02-18 07:34:23 +00:00
$exec('git config user.email composertest@example.org');
$exec('git config user.name ComposerTest');
2012-02-18 16:06:30 +00:00
touch('foo');
$exec('git add foo');
$exec('git commit -m init');
2012-02-18 16:06:30 +00:00
// non-composed tag & branch
$exec('git tag 0.5.0');
$exec('git branch oldbranch');
2012-02-18 16:06:30 +00:00
// add composed tag & master branch
$composer = array('name' => 'a/b');
file_put_contents('composer.json', json_encode($composer));
$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
$exec('git checkout -b feature/a-1.0-B');
2012-02-18 16:06:30 +00:00
file_put_contents('foo', 'bar feature');
$exec('git add foo');
$exec('git commit -m change-a');
2012-02-18 16:06:30 +00:00
// add version to composer.json
$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));
$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
$exec('git tag 0.9.0');
2012-02-18 16:06:30 +00:00
// create tag with correct version in it
$exec('git tag 1.0.0');
2012-02-18 16:06:30 +00:00
// add feature-b branch
$exec('git checkout -b feature-b');
2012-02-18 16:06:30 +00:00
file_put_contents('foo', 'baz feature');
$exec('git add foo');
$exec('git commit -m change-b');
2012-02-18 16:06:30 +00:00
// add 1.0 branch
$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
$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));
$exec('git add composer.json');
$exec('git commit -m bump-version');
2012-02-18 16:06:30 +00:00
chdir($oldCwd);
}
public function setUp()
{
if (!self::$gitRepo) {
$this->initialize();
}
if ($this->skipped) {
$this->markTestSkipped($this->skipped);
2012-02-18 16:06:30 +00:00
}
}
public static function tearDownAfterClass()
{
$fs = new Filesystem;
$fs->removeDirectory(self::$gitRepo);
}
public function testLoadVersions()
{
$expected = array(
'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,
'dev-feature/a-1.0-B' => true,
2012-02-18 16:06:30 +00:00
'dev-master' => true,
);
2012-04-25 15:35:47 +00:00
$repo = new VcsRepository(array('url' => self::$gitRepo, 'type' => 'vcs'), new NullIO, new Config());
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)));
}
}
2012-02-18 18:00:40 +00:00
$this->assertEmpty($expected, 'Missing versions: '.implode(', ', array_keys($expected)));
2012-02-18 16:06:30 +00:00
}
}