public function testConstructor()
 {
     $pharcomposer = new PharComposer(__DIR__ . '/../composer.json');
     $this->assertEquals($this->getPathProjectAbsolute('/') . '/', $pharcomposer->getBase());
     $this->assertEquals($this->getPathProjectAbsolute('bin/phar-composer'), $pharcomposer->getMain());
     $this->assertInstanceOf('Clue\\PharComposer\\Package', $pharcomposer->getPackageRoot());
     $this->assertNotCount(0, $pharcomposer->getPackagesDependencies());
     $this->assertEquals($this->getPathProjectAbsolute('vendor') . '/', $pharcomposer->getPathVendor());
     $this->assertEquals('phar-composer.phar', $pharcomposer->getTarget());
     return $pharcomposer;
 }
Exemple #2
0
 public function getPharer($path, $version = null)
 {
     if ($version !== null) {
         // TODO: should be the other way around
         $path .= ':' . $version;
     }
     $this->assertWritable();
     $step = 1;
     $steps = 1;
     if ($this->isPackageUrl($path)) {
         $url = $path;
         $version = null;
         $steps = 3;
         if (preg_match('/(.+)\\:((?:dev\\-|v\\d)\\S+)$/i', $url, $match)) {
             $url = $match[1];
             $version = $match[2];
             if (substr($version, 0, 4) === 'dev-') {
                 $version = substr($version, 4);
             }
         }
         $path = $this->getDirTemporary();
         $finder = new ExecutableFinder();
         $git = $finder->find('git', '/usr/bin/git');
         $that = $this;
         $this->displayMeasure('[' . $step++ . '/' . $steps . '] Cloning <info>' . $url . '</info> into temporary directory <info>' . $path . '</info>', function () use($that, $url, $path, $version, $git) {
             $that->exec($git . ' clone ' . escapeshellarg($url) . ' ' . escapeshellarg($path));
             if ($version !== null) {
                 $this->exec($git . ' checkout ' . escapeshellarg($version) . ' 2>&1', $path);
             }
         }, 'Cloning base repository completed');
         $pharcomposer = new PharComposer($path . '/composer.json');
         $package = $pharcomposer->getPackageRoot()->getName();
         if (is_file('composer.phar')) {
             $command = $finder->find('php', '/usr/bin/php') . ' composer.phar';
         } else {
             $command = $finder->find('composer', '/usr/bin/composer');
         }
         $command .= ' install --no-dev --no-progress --no-scripts';
         $this->displayMeasure('[' . $step++ . '/' . $steps . '] Installing dependencies for <info>' . $package . '</info> into <info>' . $path . '</info> (using <info>' . $command . '</info>)', function () use($that, $command, $path) {
             try {
                 $that->exec($command, $path);
             } catch (UnexpectedValueException $e) {
                 throw new UnexpectedValueException('Installing dependencies via composer failed', 0, $e);
             }
         }, 'Downloading dependencies completed');
     } elseif ($this->isPackageName($path)) {
         if (is_dir($path)) {
             $this->log('<info>There\'s also a directory with the given name</info>');
         }
         $steps = 2;
         $package = $path;
         $path = $this->getDirTemporary();
         $finder = new ExecutableFinder();
         if (is_file('composer.phar')) {
             $command = $finder->find('php', '/usr/bin/php') . ' composer.phar';
         } else {
             $command = $finder->find('composer', '/usr/bin/composer');
         }
         $command .= ' create-project ' . escapeshellarg($package) . ' ' . escapeshellarg($path) . ' --no-dev --no-progress --no-scripts';
         $that = $this;
         $this->displayMeasure('[' . $step++ . '/' . $steps . '] Installing <info>' . $package . '</info> to temporary directory <info>' . $path . '</info> (using <info>' . $command . '</info>)', function () use($that, $command) {
             try {
                 $that->exec($command);
             } catch (UnexpectedValueException $e) {
                 throw new UnexpectedValueException('Installing package via composer failed', 0, $e);
             }
         }, 'Downloading package completed');
     }
     if (is_dir($path)) {
         $path = rtrim($path, '/') . '/composer.json';
     }
     if (!is_file($path)) {
         throw new InvalidArgumentException('The given path "' . $path . '" is not a readable file');
     }
     $pharer = new PharComposer($path);
     $pharer->setOutput($this->output);
     $pharer->setStep($step);
     $pathVendor = $pharer->getPathVendor();
     if (!is_dir($pathVendor)) {
         $this->log('<error>Project is not installed via composer. Run "composer install" manually</error>');
         return;
     }
     return $pharer;
 }