protected function setUp()
 {
     $this->packageFileManager = $this->getMock('Puli\\Manager\\Api\\Package\\RootPackageFileManager');
     $this->installerManager = $this->getMock('Puli\\AssetPlugin\\Api\\Installer\\InstallerManager');
     $this->targetManager = new PackageFileInstallTargetManager($this->packageFileManager, $this->installerManager);
     $this->installerManager->expects($this->any())->method('hasInstallerDescriptor')->willReturnMap(array(array('symlink', true), array('rsync', true)));
 }
 public function handleRemove(Args $args)
 {
     $installerName = $args->getArgument('name');
     if (!$this->installerManager->hasInstallerDescriptor($installerName)) {
         throw new RuntimeException(sprintf('The installer "%s" does not exist.', $installerName));
     }
     $this->installerManager->removeRootInstallerDescriptor($installerName);
     return 0;
 }
 /**
  * {@inheritdoc}
  */
 public function addTarget(InstallTarget $target)
 {
     $this->assertTargetsLoaded();
     if (!$this->installerManager->hasInstallerDescriptor($target->getInstallerName())) {
         throw NoSuchInstallerException::forInstallerName($target->getInstallerName());
     }
     $previousTargets = $this->targets->toArray();
     $previousData = $this->targetsData;
     $this->targets->add($target);
     $this->targetsData[$target->getName()] = $this->targetToData($target);
     try {
         $this->persistTargetsData();
     } catch (Exception $e) {
         $this->targets->replace($previousTargets);
         $this->targetsData = $previousData;
         throw $e;
     }
 }
 /**
  * @expectedException \Puli\AssetPlugin\Api\Installation\NotInstallableException
  * @expectedExceptionMessage Puli\AssetPlugin\Tests\Installation\Fixtures\TestInstallerInvalid
  * @expectedExceptionCode 8
  */
 public function testFailIfInstallerClassInvalid()
 {
     $resources = new ArrayResourceCollection(array(new GenericResource('/path/css'), new GenericResource('/path/js')));
     $installerDescriptor = new InstallerDescriptor('rsync', self::INSTALLER_CLASS_INVALID, null, array(new InstallerParameter('param1', InstallerParameter::REQUIRED), new InstallerParameter('param2', InstallerParameter::OPTIONAL, 'default1'), new InstallerParameter('param3', InstallerParameter::OPTIONAL, 'default2')));
     $target = new InstallTarget('server', 'rsync', 'ssh://server/public_html', '/%s', array('param1' => 'custom1', 'param3' => 'custom2'));
     $mapping = new AssetMapping('/path/{css,js}', 'server', 'assets');
     $this->targets->add($target);
     $this->repo->expects($this->any())->method('find')->with('/path/{css,js}')->willReturn($resources);
     $this->installerManager->expects($this->any())->method('hasInstallerDescriptor')->with('rsync')->willReturn(true);
     $this->installerManager->expects($this->any())->method('getInstallerDescriptor')->with('rsync')->willReturn($installerDescriptor);
     $this->manager->prepareInstallation($mapping);
 }
 /**
  * {@inheritdoc}
  */
 public function prepareInstallation(AssetMapping $mapping)
 {
     $glob = $mapping->getGlob();
     $targetName = $mapping->getTargetName();
     $resources = $this->repo->find($glob);
     if ($resources->isEmpty()) {
         throw NotInstallableException::noResourceMatches($glob);
     }
     if (!$this->installTargets->contains($targetName)) {
         throw NotInstallableException::targetNotFound($targetName);
     }
     $target = $this->installTargets->get($targetName);
     $installerName = $target->getInstallerName();
     if (!$this->installerManager->hasInstallerDescriptor($installerName)) {
         throw NotInstallableException::installerNotFound($installerName);
     }
     $installerDescriptor = $this->installerManager->getInstallerDescriptor($installerName);
     $installer = $this->loadInstaller($installerDescriptor);
     $rootDir = $this->environment->getRootDirectory();
     $params = new InstallationParams($installer, $installerDescriptor, $resources, $mapping, $target, $rootDir);
     $installer->validateParams($params);
     return $params;
 }
 private function initDefaultInstallers()
 {
     $this->installerManager->expects($this->once())->method('getInstallerDescriptors')->willReturn(array(new InstallerDescriptor('symlink', 'Puli\\Installer\\SymlinkInstaller', 'Symlink description'), new InstallerDescriptor('copy', 'Puli\\Installer\\CopyInstaller', 'The copy description is significantly longer than all the other descriptions, although it doesn\'t bear any more information.'), new InstallerDescriptor('rsync', 'Puli\\Installer\\RsyncInstaller', 'Just a short description', array(new InstallerParameter('required', InstallerParameter::REQUIRED, null, 'The description of "required"'), new InstallerParameter('optional', InstallerParameter::OPTIONAL, 42, 'The description of "optional"')))));
 }