public function setUp() { $this->config = $this->getMock('Composer\Config'); $this->config->expects($this->any()) ->method('get') ->will($this->returnCallback(function ($key) { switch ($key) { case 'cache-repo-dir': return sys_get_temp_dir() . '/composer-test-repo-cache'; case 'vendor-dir': return sys_get_temp_dir() . '/composer-test/vendor'; } return null; })); $this->rootPackage = $this->getMock('Composer\Package\RootPackageInterface'); $this->package = $this->getMock('Composer\Package\PackageInterface'); $this->package->expects($this->any()) ->method('getName') ->will($this->returnValue('foo-asset/foo')); $this->composer = $this->getMock('Composer\Composer'); $this->composer->expects($this->any()) ->method('getPackage') ->will($this->returnValue($this->rootPackage)); $this->composer->expects($this->any()) ->method('getConfig') ->will($this->returnValue($this->config)); }
protected function setUp() { $this->fs = new Filesystem(); $that = $this; $this->workingDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'cmptest-' . md5(uniqid('', true)); $this->fs->ensureDirectoryExists($this->workingDir); $this->vendorDir = $this->workingDir . DIRECTORY_SEPARATOR . 'composer-test-autoload'; $this->ensureDirectoryExistsAndClear($this->vendorDir); $this->config = $this->getMock('Composer\\Config'); $this->configValueMap = array('vendor-dir' => function () use($that) { return $that->vendorDir; }); $this->config->expects($this->atLeastOnce())->method('get')->will($this->returnCallback(function ($arg) use($that) { $ret = null; if (isset($that->configValueMap[$arg])) { $ret = $that->configValueMap[$arg]; if (is_callable($ret)) { $ret = $ret(); } } return $ret; })); $this->origDir = getcwd(); chdir($this->workingDir); $this->im = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock(); $this->im->expects($this->any())->method('getInstallPath')->will($this->returnCallback(function ($package) use($that) { $targetDir = $package->getTargetDir(); return $that->vendorDir . '/' . $package->getName() . ($targetDir ? '/' . $targetDir : ''); })); $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface'); $this->eventDispatcher = $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock(); $this->generator = new AutoloadGenerator($this->eventDispatcher); }
public function testUseGlobalIncludePath() { $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array('psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''))); $package->setTargetDir('Main/Foo/'); $this->repository->expects($this->once())->method('getCanonicalPackages')->will($this->returnValue(array())); $this->config->expects($this->at(2))->method('get')->with($this->equalTo('use-include-path'))->will($this->returnValue(true)); $this->fs->ensureDirectoryExists($this->vendorDir . '/a'); $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'IncludePath'); $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_real_include_path.php', $this->vendorDir . '/composer/autoload_real.php'); }