commit
3135ea2b75
|
@ -15,26 +15,25 @@ namespace Composer\Test\Installer;
|
||||||
use Composer\Autoload\AutoloadGenerator;
|
use Composer\Autoload\AutoloadGenerator;
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
use Composer\Package\MemoryPackage;
|
use Composer\Package\MemoryPackage;
|
||||||
|
use Composer\Test\TestCase;
|
||||||
|
|
||||||
class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase
|
class AutoloadGeneratorTest extends TestCase
|
||||||
{
|
{
|
||||||
public $vendorDir;
|
public $vendorDir;
|
||||||
private $workingDir;
|
private $workingDir;
|
||||||
private $im;
|
private $im;
|
||||||
private $repository;
|
private $repository;
|
||||||
private $generator;
|
private $generator;
|
||||||
|
private $fs;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$fs = new Filesystem;
|
$this->fs = new Filesystem;
|
||||||
$that = $this;
|
$that = $this;
|
||||||
|
|
||||||
$this->workingDir = realpath(sys_get_temp_dir());
|
$this->workingDir = realpath(sys_get_temp_dir());
|
||||||
$this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
|
$this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
|
||||||
if (is_dir($this->vendorDir)) {
|
$this->ensureDirectoryExistsAndClear($this->vendorDir);
|
||||||
$fs->removeDirectory($this->vendorDir);
|
|
||||||
}
|
|
||||||
mkdir($this->vendorDir);
|
|
||||||
|
|
||||||
$this->dir = getcwd();
|
$this->dir = getcwd();
|
||||||
chdir($this->workingDir);
|
chdir($this->workingDir);
|
||||||
|
@ -53,13 +52,20 @@ class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
return $that->vendorDir;
|
return $that->vendorDir;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$this->repo = $this->getMock('Composer\Repository\RepositoryInterface');
|
$this->repository = $this->getMock('Composer\Repository\RepositoryInterface');
|
||||||
|
|
||||||
$this->generator = new AutoloadGenerator();
|
$this->generator = new AutoloadGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
|
if ($this->vendorDir === $this->workingDir) {
|
||||||
|
if (is_dir($this->workingDir.'/.composer')) {
|
||||||
|
$this->fs->removeDirectory($this->workingDir.'/.composer');
|
||||||
|
}
|
||||||
|
} elseif (is_dir($this->vendorDir)) {
|
||||||
|
$this->fs->removeDirectory($this->vendorDir);
|
||||||
|
}
|
||||||
chdir($this->dir);
|
chdir($this->dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,12 +74,12 @@ class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
$package = new MemoryPackage('a', '1.0', '1.0');
|
$package = new MemoryPackage('a', '1.0', '1.0');
|
||||||
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
|
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
|
||||||
|
|
||||||
$this->repo->expects($this->once())
|
$this->repository->expects($this->once())
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
mkdir($this->vendorDir.'/.composer');
|
mkdir($this->vendorDir.'/.composer');
|
||||||
$this->generator->dump($this->repo, $package, $this->im, $this->vendorDir.'/.composer');
|
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||||
$this->assertAutoloadFiles('main', $this->vendorDir.'/.composer');
|
$this->assertAutoloadFiles('main', $this->vendorDir.'/.composer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,14 +90,15 @@ class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
$package = new MemoryPackage('a', '1.0', '1.0');
|
$package = new MemoryPackage('a', '1.0', '1.0');
|
||||||
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
|
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
|
||||||
|
|
||||||
$this->repo->expects($this->once())
|
$this->repository->expects($this->once())
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
if (!is_dir($this->vendorDir.'/.composer')) {
|
if (!is_dir($this->vendorDir.'/.composer')) {
|
||||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||||
}
|
}
|
||||||
$this->generator->dump($this->repo, $package, $this->im, $this->vendorDir.'/.composer');
|
|
||||||
|
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||||
$this->assertAutoloadFiles('main3', $this->vendorDir.'/.composer');
|
$this->assertAutoloadFiles('main3', $this->vendorDir.'/.composer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,13 +107,13 @@ class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
$package = new MemoryPackage('a', '1.0', '1.0');
|
$package = new MemoryPackage('a', '1.0', '1.0');
|
||||||
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
|
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
|
||||||
|
|
||||||
$this->repo->expects($this->once())
|
$this->repository->expects($this->once())
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$this->vendorDir .= '/subdir';
|
$this->vendorDir .= '/subdir';
|
||||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||||
$this->generator->dump($this->repo, $package, $this->im, $this->vendorDir.'/.composer');
|
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||||
$this->assertAutoloadFiles('main2', $this->vendorDir.'/.composer');
|
$this->assertAutoloadFiles('main2', $this->vendorDir.'/.composer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,12 +127,12 @@ class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
$a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
|
$a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
|
||||||
$b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
|
$b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
|
||||||
|
|
||||||
$this->repo->expects($this->once())
|
$this->repository->expects($this->once())
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue($packages));
|
->will($this->returnValue($packages));
|
||||||
|
|
||||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||||
$this->generator->dump($this->repo, $package, $this->im, $this->vendorDir.'/.composer');
|
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||||
$this->assertAutoloadFiles('vendors', $this->vendorDir.'/.composer');
|
$this->assertAutoloadFiles('vendors', $this->vendorDir.'/.composer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,12 +147,12 @@ class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
$a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
|
$a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
|
||||||
$b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
|
$b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
|
||||||
|
|
||||||
$this->repo->expects($this->once())
|
$this->repository->expects($this->once())
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue($packages));
|
->will($this->returnValue($packages));
|
||||||
|
|
||||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||||
$this->generator->dump($this->repo, $package, $this->im, $this->vendorDir.'/.composer');
|
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||||
$this->assertAutoloadFiles('override_vendors', $this->vendorDir.'/.composer');
|
$this->assertAutoloadFiles('override_vendors', $this->vendorDir.'/.composer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,9 @@ namespace Composer\Test\Installer;
|
||||||
use Composer\Installer\LibraryInstaller;
|
use Composer\Installer\LibraryInstaller;
|
||||||
use Composer\DependencyResolver\Operation;
|
use Composer\DependencyResolver\Operation;
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
|
use Composer\Test\TestCase;
|
||||||
|
|
||||||
class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
|
class LibraryInstallerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $vendorDir;
|
private $vendorDir;
|
||||||
private $binDir;
|
private $binDir;
|
||||||
|
@ -30,16 +31,10 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->fs = new Filesystem;
|
$this->fs = new Filesystem;
|
||||||
|
|
||||||
$this->vendorDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-vendor';
|
$this->vendorDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-vendor';
|
||||||
if (is_dir($this->vendorDir)) {
|
$this->ensureDirectoryExistsAndClear($this->vendorDir);
|
||||||
$this->fs->removeDirectory($this->vendorDir);
|
|
||||||
}
|
|
||||||
mkdir($this->vendorDir);
|
|
||||||
|
|
||||||
$this->binDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-bin';
|
$this->binDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-bin';
|
||||||
if (is_dir($this->binDir)) {
|
$this->ensureDirectoryExistsAndClear($this->binDir);
|
||||||
$this->fs->removeDirectory($this->binDir);
|
|
||||||
}
|
|
||||||
mkdir($this->binDir);
|
|
||||||
|
|
||||||
$this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
@ -52,6 +47,17 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
|
||||||
->getMock();
|
->getMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
if (is_dir($this->vendorDir)) {
|
||||||
|
$this->fs->removeDirectory($this->vendorDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($this->binDir)) {
|
||||||
|
$this->fs->removeDirectory($this->binDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testInstallerCreationShouldNotCreateVendorDirectory()
|
public function testInstallerCreationShouldNotCreateVendorDirectory()
|
||||||
{
|
{
|
||||||
$this->fs->removeDirectory($this->vendorDir);
|
$this->fs->removeDirectory($this->vendorDir);
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Composer\Test;
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
use Composer\Package\MemoryPackage;
|
use Composer\Package\MemoryPackage;
|
||||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
|
use Composer\Util\Filesystem;
|
||||||
|
|
||||||
abstract class TestCase extends \PHPUnit_Framework_TestCase
|
abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
@ -40,4 +41,13 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||||
$normVersion = self::$versionParser->normalize($version);
|
$normVersion = self::$versionParser->normalize($version);
|
||||||
return new MemoryPackage($name, $normVersion, $version);
|
return new MemoryPackage($name, $normVersion, $version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function ensureDirectoryExistsAndClear($directory)
|
||||||
|
{
|
||||||
|
$fs = new Filesystem();
|
||||||
|
if (is_dir($directory)) {
|
||||||
|
$fs->removeDirectory($directory);
|
||||||
|
}
|
||||||
|
mkdir($directory, 0777, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue