public function testGetWithDefaultTarget() { $this->collection->add($this->target1); $this->collection->add($this->target2); $this->assertSame($this->target1, $this->collection->get(InstallTarget::DEFAULT_TARGET)); $this->collection->setDefaultTarget('target2'); $this->assertSame($this->target2, $this->collection->get(InstallTarget::DEFAULT_TARGET)); }
public function testAddCreateUrlGeneratorMethod() { $targets = new InstallTargetCollection(array(new InstallTarget('local', 'symlink', 'public_html', '/%s'), new InstallTarget('remote', 'rsync', 'ssh://example.com', 'http://example.com/%s', array('user' => 'webmozart', 'password' => 'password')))); $targets->setDefaultTarget('remote'); $this->targetManager->expects($this->any())->method('getTargets')->willReturn($targets); $class = new Clazz('Puli\\MyFactory'); $class->addImport(new Import('Puli\\Factory\\PuliFactory')); $class->addImplementedInterface('PuliFactory'); $class->setFilePath($this->tempFile); $this->generator->addCreateUrlGeneratorMethod($class); $writer = new ClassWriter(); $writer->writeClass($class); $expected = <<<EOF <?php namespace Puli; use Puli\\AssetPlugin\\Api\\Factory\\UrlGeneratorFactory; use Puli\\AssetPlugin\\Api\\Target\\InstallTarget; use Puli\\AssetPlugin\\Api\\Target\\InstallTargetCollection; use Puli\\AssetPlugin\\Api\\UrlGenerator\\AssetUrlGenerator; use Puli\\AssetPlugin\\UrlGenerator\\DiscoveryUrlGenerator; use Puli\\Discovery\\Api\\ResourceDiscovery; use Puli\\Factory\\PuliFactory; class MyFactory implements PuliFactory, UrlGeneratorFactory { /** * Creates the URL generator. * * @param ResourceDiscovery \$discovery The resource discovery to read from. * * @return AssetUrlGenerator The created URL generator. */ public function createUrlGenerator(ResourceDiscovery \$discovery) { \$targets = new InstallTargetCollection(array( new InstallTarget('local', 'symlink', 'public_html', '/%s', array()), new InstallTarget('remote', 'rsync', 'ssh://example.com', 'http://example.com/%s', array( 'user' => 'webmozart', 'password' => 'password', )), )); \$targets->setDefaultTarget('remote'); \$generator = new DiscoveryUrlGenerator(\$discovery, \$targets); return \$generator; } } EOF; $this->assertSame($expected, file_get_contents($this->tempFile)); }
public function testListTargets() { $targets = new InstallTargetCollection(array(new InstallTarget('local', 'symlink', 'public_html', '/%s'), new InstallTarget('remote', 'rsync', 'ssh://example.com', 'http://example.com/%s', array('user' => 'webmozart', 'password' => 'password')))); $targets->setDefaultTarget('remote'); $this->targetManager->expects($this->any())->method('getTargets')->willReturn($targets); $args = self::$listCommand->parseArgs(new StringArgs('')); $expected = <<<EOF local symlink public_html /%s * remote rsync ssh://example.com http://example.com/%s user="******" password="******" EOF; $this->assertSame(0, $this->handler->handleList($args, $this->io)); $this->assertSame($expected, $this->io->fetchOutput()); $this->assertEmpty($this->io->fetchErrors()); }
private function assertTargetsLoaded() { if (null !== $this->targets) { return; } $targetsData = $this->rootPackageFileManager->getExtraKey(AssetPlugin::INSTALL_TARGETS_KEY); if ($targetsData) { $jsonValidator = new JsonValidator(); $errors = $jsonValidator->validate($targetsData, __DIR__ . '/../../res/schema/install-targets-schema-1.0.json'); if (count($errors) > 0) { throw new ValidationFailedException(sprintf("The extra key \"%s\" is invalid:\n%s", AssetPlugin::INSTALL_TARGETS_KEY, implode("\n", $errors))); } } $this->targets = new InstallTargetCollection(); $this->targetsData = (array) $targetsData; foreach ($this->targetsData as $targetName => $targetData) { $this->targets->add($this->dataToTarget($targetName, $targetData)); if (isset($targetData->default) && $targetData->default) { $this->targets->setDefaultTarget($targetName); } } }