Ejemplo n.º 1
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testFailIfInvalidEnvironment()
 {
     $installInfo = new InstallInfo('vendor/package', '/path');
     $installInfo->setEnvironment('foo');
 }
Ejemplo n.º 2
0
 public function testUnserializeFullRootPackageFile()
 {
     $packageFile = $this->serializer->unserializeRootPackageFile(self::FULL_ROOT_JSON, '/path', $this->baseConfig);
     $installInfo1 = new InstallInfo('vendor/package1', '/path/to/package1');
     $installInfo1->setInstallerName('composer');
     $installInfo1->addDisabledBindingUuid(Uuid::fromString('4d02ee67-d845-4789-a9c1-8301351c6f5a'));
     $installInfo2 = new InstallInfo('vendor/package2', '/path/to/package2');
     $installInfo2->setEnvironment(Environment::DEV);
     $this->assertInstanceOf('Puli\\Manager\\Api\\Package\\RootPackageFile', $packageFile);
     $this->assertSame('/path', $packageFile->getPath());
     $this->assertFullConfig($packageFile);
     $this->assertSame(array('acme/blog-extension1', 'acme/blog-extension2'), $packageFile->getOverrideOrder());
     $this->assertEquals(array($installInfo1, $installInfo2), $packageFile->getInstallInfos());
     $config = $packageFile->getConfig();
     $this->assertSame('puli-dir', $config->get(Config::PULI_DIR));
     $this->assertSame('Puli\\MyFactory', $config->get(Config::FACTORY_OUT_CLASS));
     $this->assertSame('puli-dir/MyFactory.php', $config->get(Config::FACTORY_OUT_FILE));
     $this->assertSame('my-type', $config->get(Config::REPOSITORY_TYPE));
     $this->assertSame('puli-dir/my-repo', $config->get(Config::REPOSITORY_PATH));
     $this->assertSame('my-store-type', $config->get(Config::DISCOVERY_STORE_TYPE));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function installPackage($installPath, $name = null, $installerName = InstallInfo::DEFAULT_INSTALLER_NAME, $env = Environment::PROD)
 {
     Assert::string($installPath, 'The install path must be a string. Got: %s');
     Assert::string($installerName, 'The installer name must be a string. Got: %s');
     Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s');
     Assert::nullOrPackageName($name);
     $this->assertPackagesLoaded();
     $installPath = Path::makeAbsolute($installPath, $this->rootDir);
     foreach ($this->packages as $package) {
         if ($installPath === $package->getInstallPath()) {
             return;
         }
     }
     if (null === $name) {
         // Read the name from the package file
         $name = $this->loadPackageFile($installPath)->getPackageName();
     }
     if (null === $name) {
         throw new InvalidConfigException(sprintf('Could not find a name for the package at %s. The name should ' . 'either be passed to the installer or be set in the "name" ' . 'property of %s.', $installPath, $installPath . '/puli.json'));
     }
     if ($this->packages->contains($name)) {
         throw NameConflictException::forName($name);
     }
     $relInstallPath = Path::makeRelative($installPath, $this->rootDir);
     $installInfo = new InstallInfo($name, $relInstallPath);
     $installInfo->setInstallerName($installerName);
     $installInfo->setEnvironment($env);
     $package = $this->loadPackage($installInfo);
     $this->assertNoLoadErrors($package);
     $this->rootPackageFile->addInstallInfo($installInfo);
     try {
         $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
     } catch (Exception $e) {
         $this->rootPackageFile->removeInstallInfo($name);
         throw $e;
     }
     $this->packages->add($package);
 }
Ejemplo n.º 4
0
 private function jsonToRootPackageFile(stdClass $jsonData, RootPackageFile $packageFile)
 {
     if (isset($jsonData->{'override-order'})) {
         $packageFile->setOverrideOrder((array) $jsonData->{'override-order'});
     }
     if (isset($jsonData->plugins)) {
         $packageFile->setPluginClasses($jsonData->plugins);
     }
     if (isset($jsonData->config)) {
         $config = $packageFile->getConfig();
         foreach ($this->objectsToArrays($jsonData->config) as $key => $value) {
             $config->set($key, $value);
         }
     }
     if (isset($jsonData->packages)) {
         foreach ($jsonData->packages as $packageName => $packageData) {
             $installInfo = new InstallInfo($packageName, $packageData->{'install-path'});
             if (isset($packageData->env)) {
                 $installInfo->setEnvironment($packageData->env);
             }
             if (isset($packageData->installer)) {
                 $installInfo->setInstallerName($packageData->installer);
             }
             if (isset($packageData->{'disabled-bindings'})) {
                 foreach ($packageData->{'disabled-bindings'} as $uuid) {
                     $installInfo->addDisabledBindingUuid(Uuid::fromString($uuid));
                 }
             }
             $packageFile->addInstallInfo($installInfo);
         }
     }
 }
Ejemplo n.º 5
0
 public function testMatch()
 {
     $packageFile = new PackageFile('vendor/name');
     $package = new Package($packageFile, __DIR__);
     $this->assertFalse($package->match(Expr::same('foobar', Package::NAME)));
     $this->assertTrue($package->match(Expr::same('vendor/name', Package::NAME)));
     $this->assertFalse($package->match(Expr::same('/path/foo', Package::INSTALL_PATH)));
     $this->assertTrue($package->match(Expr::same(__DIR__, Package::INSTALL_PATH)));
     $this->assertFalse($package->match(Expr::same(PackageState::NOT_LOADABLE, Package::STATE)));
     $this->assertTrue($package->match(Expr::same(PackageState::ENABLED, Package::STATE)));
     $this->assertFalse($package->match(Expr::same('webmozart', Package::INSTALLER)));
     // Packages without install info (= the root package) are assumed to be
     // installed in the production environment
     $this->assertTrue($package->match(Expr::same(Environment::PROD, Package::ENVIRONMENT)));
     $installInfo = new InstallInfo('vendor/install-info', '/path');
     $installInfo->setInstallerName('webmozart');
     $packageWithInstallInfo = new Package($packageFile, __DIR__, $installInfo);
     $this->assertFalse($packageWithInstallInfo->match(Expr::same('foobar', Package::INSTALLER)));
     $this->assertTrue($packageWithInstallInfo->match(Expr::same('webmozart', Package::INSTALLER)));
     $this->assertTrue($packageWithInstallInfo->match(Expr::notsame(Environment::DEV, Package::ENVIRONMENT)));
     $installInfo2 = new InstallInfo('vendor/install-info', '/path');
     $installInfo2->setEnvironment(Environment::DEV);
     $packageWithInstallInfo2 = new Package($packageFile, __DIR__, $installInfo2);
     $this->assertTrue($packageWithInstallInfo2->match(Expr::same(Environment::DEV, Package::ENVIRONMENT)));
 }