Esempio n. 1
0
 /**
  * @test
  */
 public function shouldReturnInstalledUpdatedAndUninstalledPackages()
 {
     $package1 = $this->createPackageMock('name1', 'ref1');
     $package2 = $this->createPackageMock('name2', 'ref2');
     $package21 = $this->createPackageMock('name2', 'ref21');
     $package3 = $this->createPackageMock('name3', 'ref3');
     $package4 = $this->createPackageMock('name4', 'ref4');
     $previousInstalledPackages = [$package1, $package2, $package3];
     $currentlyInstalledPackages = [$package21, $package3, $package4];
     $expectedInstalled = [$package4];
     $expectedUpdated = [$package21];
     $expectedUninstalled = [$package1];
     $builder = new ChangeSetBuilder();
     list($actualInstalled, $actualUpdated, $actualUninstalled) = $builder->build($previousInstalledPackages, $currentlyInstalledPackages);
     $this->assertSame($expectedInstalled, $actualInstalled);
     $this->assertSame($expectedUpdated, $actualUpdated);
     $this->assertSame($expectedUninstalled, $actualUninstalled);
 }
Esempio n. 2
0
 /**
  * @param string $packageName
  * @throws VerboseException
  */
 public function update($packageName)
 {
     $this->logger->info(sprintf('%s updating begin', $packageName));
     $this->maintenance->activate();
     $previousInstalled = $this->getInstalled();
     $currentPackage = $this->findInstalledPackage($packageName);
     $this->updateComposerJsonFile($currentPackage, '*');
     $this->scriptRunner->removeApplicationCache();
     if ($this->doInstall($packageName)) {
         $currentlyInstalled = $this->getInstalled();
         $changeSetBuilder = new ChangeSetBuilder();
         list($installedPackages, $updatedPackages, $uninstalledPackages) = $changeSetBuilder->build($previousInstalled, $currentlyInstalled);
         array_map(function (PackageInterface $p) {
             $this->scriptRunner->runInstallScripts($p);
         }, $installedPackages);
         $fetchPreviousInstalledPackageVersion = function ($packageName) use($previousInstalled) {
             foreach ($previousInstalled as $p) {
                 if ($p->getName() == $packageName) {
                     return $p->getVersion();
                 }
             }
             return '';
         };
         array_map(function (PackageInterface $p) use($fetchPreviousInstalledPackageVersion) {
             $previousInstalledPackageVersion = $fetchPreviousInstalledPackageVersion($p->getName());
             $this->scriptRunner->runUpdateScripts($p, $previousInstalledPackageVersion);
         }, $updatedPackages);
         array_map(function (PackageInterface $p) {
             $this->scriptRunner->runUninstallScripts($p);
         }, $uninstalledPackages);
         $this->scriptRunner->clearApplicationCache();
         $this->scriptRunner->runPlatformUpdate();
         $this->scriptRunner->clearDistApplicationCache();
         $justInstalledPackage = $this->findInstalledPackage($packageName);
         $this->updateComposerJsonFile($justInstalledPackage, $justInstalledPackage->getPrettyVersion());
     } else {
         $this->updateComposerJsonFile($currentPackage, $currentPackage->getPrettyVersion());
         $errorMessage = sprintf('%s can\'t be updated!', $packageName);
         $this->logger->error($errorMessage);
         $this->logger->error($this->composerIO->getOutput());
         throw new VerboseException($errorMessage, $this->composerIO->getOutput());
     }
     $this->logger->info(sprintf('%s updated', $packageName));
 }