示例#1
0
 /**
  * Creates a new package.
  *
  * @param PackageFile|null $packageFile The package file or `null` if the
  *                                      package file could not be loaded.
  * @param string           $installPath The absolute install path.
  * @param InstallInfo|null $installInfo The install info of this package.
  * @param Exception[]      $loadErrors  The errors that happened during
  *                                      loading of the package, if any.
  */
 public function __construct(PackageFile $packageFile = null, $installPath, InstallInfo $installInfo = null, array $loadErrors = array())
 {
     Assert::absoluteSystemPath($installPath);
     Assert::true($packageFile || $loadErrors, 'The load errors must be passed if the package file is null.');
     Assert::allIsInstanceOf($loadErrors, 'Exception');
     // If a package name was set during installation, that name wins over
     // the predefined name in the puli.json file (if any)
     $this->name = $installInfo && null !== $installInfo->getPackageName() ? $installInfo->getPackageName() : ($packageFile ? $packageFile->getPackageName() : null);
     if (null === $this->name) {
         $this->name = $this->getDefaultName();
     }
     // The path is stored both here and in the install info. While the
     // install info contains the path as it is stored in the install file
     // (i.e. relative or absolute), the install path of the package is
     // always an absolute path.
     $this->installPath = $installPath;
     $this->installInfo = $installInfo;
     $this->packageFile = $packageFile;
     $this->loadErrors = $loadErrors;
     if (!file_exists($installPath)) {
         $this->state = PackageState::NOT_FOUND;
     } elseif (count($loadErrors) > 0) {
         $this->state = PackageState::NOT_LOADABLE;
     } else {
         $this->state = PackageState::ENABLED;
     }
 }
示例#2
0
 public function testRenameNonRootPackage()
 {
     $this->initDefaultManager();
     $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->returnCallback(function (RootPackageFile $rootPackageFile) {
         PHPUnit_Framework_Assert::assertTrue($rootPackageFile->hasInstallInfo('vendor/new'));
         PHPUnit_Framework_Assert::assertFalse($rootPackageFile->hasInstallInfo('vendor/package1'));
     }));
     $this->installInfo1->addDisabledBindingUuid($uuid = Uuid::uuid4());
     $this->assertSame('vendor/package1', $this->installInfo1->getPackageName());
     $this->assertTrue($this->manager->hasPackage('vendor/package1'));
     $this->manager->renamePackage('vendor/package1', 'vendor/new');
     $this->assertTrue($this->rootPackageFile->hasInstallInfo('vendor/new'));
     $this->assertFalse($this->rootPackageFile->hasInstallInfo('vendor/package1'));
     $this->assertFalse($this->manager->hasPackage('vendor/package1'));
     $this->assertTrue($this->manager->hasPackage('vendor/new'));
     $package = $this->manager->getPackage('vendor/new');
     $installInfo = $this->rootPackageFile->getInstallInfo('vendor/new');
     $this->assertInstanceOf('Puli\\Manager\\Api\\Package\\Package', $package);
     $this->assertSame('vendor/new', $package->getName());
     $this->assertSame($this->packageDir1, $package->getInstallPath());
     $this->assertSame($installInfo, $package->getInstallInfo());
     $this->assertSame('vendor/new', $installInfo->getPackageName());
     $this->assertSame('../package1', $installInfo->getInstallPath());
     $this->assertSame(array($uuid), $installInfo->getDisabledBindingUuids());
 }
示例#3
0
 public function testCreate()
 {
     $installInfo = new InstallInfo('vendor/package', '/path');
     $installInfo->setInstallerName('Composer');
     $this->assertSame('vendor/package', $installInfo->getPackageName());
     $this->assertSame('/path', $installInfo->getInstallPath());
     $this->assertSame('Composer', $installInfo->getInstallerName());
 }
示例#4
0
 /**
  * Adds install info for an installed package.
  *
  * @param InstallInfo $installInfo The install info.
  */
 public function addInstallInfo(InstallInfo $installInfo)
 {
     $this->installInfos[$installInfo->getPackageName()] = $installInfo;
 }