Esempio n. 1
0
 /**
  * @param string $repository
  *
  * @return array|false
  */
 public function getLastRelease($repository)
 {
     $last_version = '';
     $last_tag = [];
     foreach ($this->getTags($repository) as $tag) {
         if (($version = Composer::getVersionCompatible($tag['name'])) && (!$last_version || version_compare($version, $last_version, '>=')) && version_compare($version, '1.0.0', '<')) {
             $last_version = $version;
             $last_tag = $tag;
         }
     }
     return $last_tag ?: false;
 }
Esempio n. 2
0
 /**
  * @param array $tag
  * @param Composer $composer
  * @param OutputInterface $output
  */
 protected function doUpdateItself(array $tag, Composer $composer, OutputInterface $output)
 {
     $output->writeln('Discovered a new version of the application: <info>' . $tag['name'] . '</info>');
     // create install package
     $package = new Package('anime-db/anime-db', $tag['version'], $tag['name']);
     $package->setDistType('zip');
     $package->setDistUrl($tag['zipball_url']);
     $package->setInstallationSource('dist');
     // download new version
     $target = sys_get_temp_dir() . '/anime-db';
     $this->getContainer()->get('filesystem')->remove($target);
     $composer->download($package, $target);
     $new_package = $composer->getPackageFromConfigFile($target . '/composer.json');
     $dispatcher = $this->getContainer()->get('event_dispatcher');
     // notify about downloaded
     $dispatcher->dispatch(StoreEvents::DOWNLOADED, new Downloaded($target, $new_package, $composer->getRootPackage()));
     // rewriting the application files
     $this->rewriting($target);
     // notify about updated
     // event will be sent after the update application components
     $this->getContainer()->get('anime_db.event_dispatcher')->dispatch(StoreEvents::UPDATED, new Updated($new_package));
     $composer->reload();
     $output->writeln('<info>Update itself has been completed</info>');
 }
Esempio n. 3
0
 /**
  * @param array $tag
  * @param string $current_version
  * @param int $result
  *
  * @return UpdateCommand
  */
 protected function getCommandToExecute(array $tag, $current_version, $result)
 {
     $that = $this;
     $installer = $this->getMockBuilder('\\Composer\\Installer')->disableOriginalConstructor()->getMock();
     $installer->expects($this->once())->method('run')->will($this->returnValue($result));
     $this->container->expects($that->at(0))->method('get')->will($this->returnValue($this->composer))->with('anime_db.composer');
     $this->container->expects($that->at(1))->method('get')->will($this->returnValue($this->github))->with('anime_db.client.github');
     $this->composer->expects($this->once())->method('setIO')->will($this->returnCallback(function ($io) use($that) {
         $that->assertInstanceOf('\\Composer\\IO\\ConsoleIO', $io);
     }));
     $this->github->expects($this->once())->method('getLastRelease')->will($this->returnValue($tag))->with('anime-db/anime-db');
     $this->composer->expects($this->atLeastOnce())->method('getRootPackage')->will($this->returnValue($this->package));
     $this->composer->expects($this->once())->method('getInstaller')->will($this->returnValue($installer));
     $this->package->expects($this->once())->method('getPrettyVersion')->will($this->returnValue($current_version));
     /* @var $helper_set HelperSet */
     $helper_set = $this->getMockBuilder('\\Symfony\\Component\\Console\\Helper\\HelperSet')->disableOriginalConstructor()->getMock();
     $this->output->expects($this->at(0))->method('writeln')->with('Search for a new version of the application');
     $command = new UpdateCommand();
     $command->setHelperSet($helper_set);
     $command->setContainer($this->container);
     return $command;
 }
Esempio n. 4
0
 /**
  * @dataProvider getVersions
  *
  * @param string $actual
  * @param string $expected
  */
 public function testGetVersionCompatible($actual, $expected)
 {
     $this->assertEquals($expected, Composer::getVersionCompatible($actual));
 }