Exemple #1
0
 /**
  * @param Alias $alias
  * @return string
  */
 private function mapAlias(Alias $alias)
 {
     $result = '';
     foreach ($alias->toArray() as $property => $value) {
         if (is_scalar($value) || is_null($value)) {
             $result .= "{$property}: {$value}\n";
         }
     }
     return trim($result);
 }
Exemple #2
0
 /**
  * @param InputInterface $input
  */
 private function setFromArgs(InputInterface $input)
 {
     if ($this->getService('alias_manager')->has($input->getArgument('bootstrap'))) {
         $this->setFromAlias($this->getService('alias_manager')->get($input->getArgument('bootstrap')));
     } else {
         $alias = new Alias();
         $alias->setPackage($input->getArgument('bootstrap'));
         $alias->setVersion($input->getArgument('version'));
         $alias->setSource($input->getArgument('source'));
         $this->setFromAlias($alias);
     }
 }
 public function testExecuteWithOptions()
 {
     $input = $this->provideInput([]);
     $output = new BufferedOutput();
     $alias = new Alias();
     $alias->setPackage('vendor/bootstrap');
     $alias->setSource('specific/url');
     $services = $this->provideServices($this->provideExecutor(1, ' --repository-url=specific/url'));
     $services['project']->setName('vendor/package');
     $services['project']->setBootstrap($alias);
     $task = new BootstrapImportation($services);
     $this->assertSame(ITask::NO_ERROR_CODE, $task->execute($input, $output));
     $this->assertSame("Installing project vendor/package from vendor/bootstrap\n", $output->fetch());
 }
Exemple #4
0
 /**
  * @param $name
  * @param $desc
  * @param $bootstrap
  * @param $version
  * @param $source
  * @return Alias
  */
 private function provideAlias($name, $desc, $bootstrap, $version, $source)
 {
     $alias = new Alias();
     $alias->setName($name);
     $alias->setDescription($desc);
     $alias->setPackage($bootstrap);
     $alias->setVersion($version);
     $alias->setSource($source);
     return $alias;
 }
Exemple #5
0
 public function testCreateProjectWithVersionAndOptions()
 {
     $alias = new Alias();
     $alias->setPackage('vendor/package');
     $alias->setVersion('1.0.0');
     $project = new Project();
     $project->setBootstrap($alias);
     $project->setDirectoryPath('dir/path');
     $executor = $this->getMockBuilder('TRex\\Cli\\Executor')->getMock();
     $executor->expects($this->once())->method('flush')->with('composer create-project --prefer-dist vendor/package "dir/path" 1.0.0 --repository-url=url')->will($this->returnValue(0));
     $composer = new Composer($executor, new BalloonFactory(new DummyFileReaderFactory()));
     $this->assertSame(0, $composer->createProject($project, ['repository-url' => 'url']));
 }
Exemple #6
0
 /**
  * @param Alias $newAlias
  * @param $hasAlias
  * @param bool $willBeSaved
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 private function provideAliasManager(Alias $newAlias, $hasAlias, $willBeSaved)
 {
     $oldAlias = clone $newAlias;
     $oldAlias->setDescription($newAlias->getDescription() . '_old');
     $oldAlias->setPackage($newAlias->getPackage() . '_old');
     $oldAlias->setVersion($newAlias->getVersion() . '_old');
     $aliasManager = $this->getMockBuilder('Samurai\\Alias\\AliasManager')->disableOriginalConstructor()->getMock();
     $aliasManager->expects($this->once())->method('has')->with($newAlias->getName())->will($this->returnValue($hasAlias));
     $aliasManager->expects($this->exactly((int) $willBeSaved))->method('add')->with($this->equalTo($newAlias));
     $aliasManager->expects($this->any())->method('get')->with($newAlias->getName())->will($this->returnValue($oldAlias));
     return $aliasManager;
 }
Exemple #7
0
 /**
  * @param Alias $newAlias
  * @param Alias $oldAlias
  * @return ConfirmationQuestion
  */
 private function buildQuestion(Alias $newAlias, Alias $oldAlias)
 {
     return new ConfirmationQuestion(sprintf('<question>Do you want to override the bootstrap "%s" with "%s" </question>[y]', trim($oldAlias->getPackage() . ' ' . $oldAlias->getVersion()), trim($newAlias->getPackage() . ' ' . $newAlias->getVersion())));
 }
Exemple #8
0
 /**
  * @param Alias $alias
  * @param $hasAlias
  * @param bool $willBeRemoved
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 private function provideAliasManager(Alias $alias, $hasAlias, $willBeRemoved)
 {
     $aliasManager = $this->getMockBuilder('Samurai\\Alias\\AliasManager')->disableOriginalConstructor()->getMock();
     $aliasManager->expects($this->once())->method('hasLocal')->with($alias->getName())->will($this->returnValue($hasAlias));
     if ($hasAlias) {
         $aliasManager->expects($this->once())->method('get')->with($alias->getName())->will($this->returnValue($alias));
     }
     $aliasManager->expects($this->exactly((int) $willBeRemoved))->method('remove')->with($this->equalTo($alias->getName()));
     return $aliasManager;
 }
Exemple #9
0
 /**
  * @return array
  */
 public function toArray()
 {
     return array_merge(parent::toArray(), ['isEnable' => $this->isEnable(), 'tasks' => $this->getTasks(), 'dependencies' => $this->getDependencies()->toArray()]);
 }
Exemple #10
0
 /**
  * @param Alias $alias
  * @param string $useMethod
  * @param bool $hasAlias
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 private function provideAliasManager(Alias $alias, $useMethod, $hasAlias)
 {
     $aliasManager = $this->getMockBuilder('Samurai\\Alias\\AliasManager')->disableOriginalConstructor()->getMock();
     $aliasManager->expects($this->exactly((int) ($useMethod === 'getGlobal')))->method('getGlobal')->will($this->returnValue([$alias->getName() => $alias]));
     $aliasManager->expects($this->exactly((int) ($useMethod === 'getLocal')))->method('getLocal')->will($this->returnValue([$alias->getName() => $alias]));
     $aliasManager->expects($this->exactly((int) ($useMethod === 'getAll' || !$hasAlias)))->method('getAll')->will($this->returnValue([$alias->getName() => $alias]));
     $aliasManager->expects($this->exactly((int) ($useMethod === 'get' && $hasAlias)))->method('get')->will($this->returnValue($alias));
     $aliasManager->expects($this->exactly((int) ($useMethod === 'get')))->method('has')->will($this->returnValue($hasAlias));
     return $aliasManager;
 }