public function testGetRequestedPharsFromCliOptions()
 {
     $options = $this->getOptionsMock();
     $options->expects($this->any())->method('getArgumentCount')->willReturn(3);
     $options->expects($this->any())->method('getArgument')->willReturnMap([[0, 'https://example.com/foo.phar'], [1, 'phpunit'], [2, 'phpab@1.12.0']]);
     $expected = [RequestedPhar::fromUrl(new Url('https://example.com/foo.phar')), RequestedPhar::fromAlias(new PharAlias('phpunit', new AnyVersionConstraint())), RequestedPhar::fromAlias(new PharAlias('phpab', new ExactVersionConstraint('1.12.0')))];
     $commandConfig = new InstallCommandConfig($options, $this->getConfigMock(), $this->getPhiveXmlConfigMock());
     $this->assertEquals($expected, $commandConfig->getRequestedPhars());
 }
Ejemplo n.º 2
0
 /**
  * @return RequestedPhar[]
  * @throws CLI\CommandOptionsException
  */
 private function getPharsFromCliArguments()
 {
     $phars = [];
     $argCount = $this->cliOptions->getArgumentCount();
     for ($i = 0; $i < $argCount; $i++) {
         $argument = $this->cliOptions->getArgument($i);
         if (strpos($argument, 'https://') !== false) {
             $phars[] = RequestedPhar::fromUrl(new Url($argument));
         } else {
             $aliasSegments = explode('@', $argument, 2);
             $parser = new VersionConstraintParser();
             if (count($aliasSegments) === 2) {
                 $versionConstraint = $parser->parse($aliasSegments[1]);
             } else {
                 $versionConstraint = new AnyVersionConstraint();
             }
             $phars[] = RequestedPhar::fromAlias(new PharAlias($aliasSegments[0], $versionConstraint));
         }
     }
     return $phars;
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider invalidUrlProvider
  * @expectedException \PharIo\Phive\DownloadFailedException
  *
  * @param $urlString
  */
 public function testInstallByUrlThrowsExceptionIfUrlDoesNotContainValidPharName($urlString)
 {
     $url = new Url($urlString);
     $requestedPhar = RequestedPhar::fromUrl($url);
     $this->getPharService()->install($requestedPhar, '/tmp', true);
 }