Example #1
0
 /**
  * Test that the deletion works.
  *
  * @param string $setter    The setter to call.
  *
  * @param string $getter    The getter to call.
  *
  * @param string $configKey The config key in the json array that will get populated.
  *
  * @param mixed  $value     The value to pass.
  *
  * @param mixed  $default   The default value that shall be returned if nothing has been set.
  *
  * @return void
  *
  * @dataProvider providerTestDelegation
  */
 public function testDelegation($setter, $getter, $configKey, $value, $default)
 {
     $array = new JsonArray();
     $config = new TensideJsonConfig($array);
     $this->assertEquals($default, call_user_func([$config, $getter]));
     $this->assertSame($config, call_user_func([$config, $setter], $value));
     $this->assertEquals($value, $array->get($configKey));
     $this->assertEquals($value, call_user_func([$config, $getter]));
 }
 /**
  * {@inheritDoc}
  */
 public function getCredentials(Request $request)
 {
     $inputData = new JsonArray($request->getContent());
     if (!($inputData->has('username') && $inputData->has('password'))) {
         // post data? Return null and no other methods will be called
         return null;
     }
     // What you return here will be passed to getUser() as $credentials
     return (object) ['username' => $inputData->get('username'), 'password' => $inputData->get('password')];
 }
 /**
  * Ensure the home path has been set in the passed meta data.
  *
  * @param JsonArray $metaData The meta data to examine.
  *
  * @return void
  */
 private function ensureHomePath(JsonArray $metaData)
 {
     if ($metaData->has(RequirePackageTask::SETTING_HOME)) {
         return;
     }
     $metaData->set(RequirePackageTask::SETTING_HOME, $this->home->homeDir());
 }
 /**
  * Try to validate the version constraint.
  *
  * @param Request $request The request.
  *
  * @return JsonResponse
  *
  * @throws \RuntimeException For invalid user classes.
  *
  * @ApiDoc(
  *   section="misc",
  *   statusCodes = {
  *     200 = "When everything worked out ok",
  *     400 = "When the request payload was invalid."
  *   },
  *   authentication = true,
  *   authenticationRoles = {
  *     "ROLE_NONE"
  *   }
  * )
  * @ApiDescription(
  *   request={
  *     "constraint" = {
  *       "description" = "The constraint to test.",
  *       "dataType" = "string",
  *       "required" = true
  *     }
  *   },
  *   response={
  *    "status" = {
  *      "dataType" = "choice",
  *      "description" = "OK or ERROR",
  *      "format" = "['OK', 'ERROR']",
  *    },
  *    "error" = {
  *      "dataType" = "string",
  *      "description" = "The error message (if any).",
  *    }
  *   }
  * )
  */
 public function checkVersionConstraintAction(Request $request)
 {
     try {
         $inputData = new JsonArray($request->getContent());
     } catch (\Exception $exception) {
         return new JsonResponse(['status' => 'ERROR', 'error' => 'invalid payload'], JsonResponse::HTTP_BAD_REQUEST);
     }
     $versionParser = new VersionParser();
     if (!$inputData->has('constraint')) {
         return new JsonResponse(['status' => 'ERROR', 'error' => 'invalid payload'], JsonResponse::HTTP_BAD_REQUEST);
     }
     try {
         $versionParser->parseConstraints($inputData->get('constraint'));
     } catch (\Exception $exception) {
         return new JsonResponse(['status' => 'ERROR', 'error' => $exception->getMessage()], JsonResponse::HTTP_OK);
     }
     return new JsonResponse(['status' => 'OK'], JsonResponse::HTTP_OK);
 }
 /**
  * Update the information of a package in the composer.json.
  *
  * Note that the payload name of the package must match the vendor and package passed as parameter.
  *
  * @param string  $vendor  The name of the vendor.
  *
  * @param string  $package The name of the package.
  *
  * @param Request $request The request to process.
  *
  * @return JsonResponse
  *
  * @throws NotAcceptableHttpException When the passed payload is invalid.
  * @throws NotFoundHttpException When the package has not been found.
  *
  * @ApiDoc(
  *   section="package",
  *   statusCodes = {
  *     200 = "When everything worked out ok"
  *   },
  *   authentication = true,
  *   authenticationRoles = {
  *     "ROLE_MANIPULATE_REQUIREMENTS"
  *   }
  * )
  *
  * @ApiDescription(
  *   request={
  *     "name" = {
  *       "dataType" = "string",
  *       "description" = "The name of the package",
  *       "required" = true
  *     },
  *     "constraint" = {
  *       "dataType" = "string",
  *       "description" = "The constraint of the package (when package is installed)",
  *       "required" = true
  *     },
  *     "locked" = {
  *       "dataType" = "string",
  *       "description" = "Flag if the package has been locked for updates",
  *       "required" = true
  *     },
  *   },
  *   response={
  *     "name" = {
  *       "dataType" = "string",
  *       "description" = "The name of the package"
  *     },
  *     "version" = {
  *       "dataType" = "string",
  *       "description" = "The version of the package"
  *     },
  *     "constraint" = {
  *       "dataType" = "string",
  *       "description" = "The constraint of the package (when package is installed)"
  *     },
  *     "type" = {
  *       "dataType" = "string",
  *       "description" = "The noted package type"
  *     },
  *     "locked" = {
  *       "dataType" = "string",
  *       "description" = "Flag if the package has been locked for updates"
  *     },
  *     "time" = {
  *       "dataType" = "datetime",
  *       "description" = "The release date"
  *     },
  *     "upgrade_version" = {
  *       "dataType" = "string",
  *       "description" = "The version available for upgrade (optional, if any)"
  *     },
  *     "description" = {
  *       "dataType" = "string",
  *       "description" = "The package description"
  *     },
  *     "license" = {
  *       "actualType" = "collection",
  *       "subType" = "string",
  *       "description" = "The licenses"
  *     },
  *     "keywords" = {
  *       "actualType" = "collection",
  *       "subType" = "string",
  *       "description" = "The keywords"
  *     },
  *     "homepage" = {
  *       "dataType" = "string",
  *       "description" = "The support website (optional, if any)"
  *     },
  *     "authors" = {
  *       "actualType" = "collection",
  *       "subType" = "object",
  *       "description" = "The authors",
  *       "children" = {
  *         "name" = {
  *           "dataType" = "string",
  *           "description" = "Full name of the author (optional, if any)"
  *         },
  *         "homepage" = {
  *           "dataType" = "string",
  *           "description" = "Email address of the author (optional, if any)"
  *         },
  *         "email" = {
  *           "dataType" = "string",
  *           "description" = "Homepage URL for the author (optional, if any)"
  *         },
  *         "role" = {
  *           "dataType" = "string",
  *           "description" = "Author's role in the project (optional, if any)"
  *         }
  *       }
  *     },
  *     "support" = {
  *       "actualType" = "collection",
  *       "subType" = "object",
  *       "description" = "The support options",
  *       "children" = {
  *         "email" = {
  *           "dataType" = "string",
  *           "description" = "Email address for support (optional, if any)"
  *         },
  *         "issues" = {
  *           "dataType" = "string",
  *           "description" = "URL to the issue tracker (optional, if any)"
  *         },
  *         "forum" = {
  *           "dataType" = "string",
  *           "description" = "URL to the forum (optional, if any)"
  *         },
  *         "wiki" = {
  *           "dataType" = "string",
  *           "description" = "URL to the wiki (optional, if any)"
  *         },
  *         "irc" = {
  *           "dataType" = "string",
  *           "description" = "IRC channel for support, as irc://server/channel (optional, if any)"
  *         },
  *         "source" = {
  *           "dataType" = "string",
  *           "description" = "URL to browse or download the sources (optional, if any)"
  *         },
  *         "docs" = {
  *           "dataType" = "string",
  *           "description" = "URL to the documentation (optional, if any)"
  *         },
  *       }
  *     },
  *     "abandoned" = {
  *       "dataType" = "boolean",
  *       "description" = "Flag if this package is abandoned"
  *     },
  *     "replacement" = {
  *       "dataType" = "string",
  *       "description" = "Replacement for this package (optional, if any)"
  *     }
  *   }
  * )
  */
 public function putPackageAction($vendor, $package, Request $request)
 {
     $packageName = $vendor . '/' . $package;
     $info = new JsonArray($request->getContent());
     $name = $info->get('name');
     if (!($info->has('name') && $info->has('locked') && $info->has('constraint'))) {
         throw new NotAcceptableHttpException('Invalid package information.');
     }
     if ($name !== $packageName) {
         throw new NotAcceptableHttpException('Package name mismatch ' . $packageName . ' vs. ' . $name . '.');
     }
     $composer = $this->getComposer();
     $json = $this->get('tenside.composer_json');
     $package = $this->findPackage($name, $composer->getRepositoryManager()->getLocalRepository());
     if (null === $package) {
         throw new NotFoundHttpException('Package ' . $packageName . ' not found.');
     }
     $json->setLock($package, $info->get('locked'));
     return $this->forward('TensideCoreBundle:Package:getPackage');
 }
Example #6
0
 /**
  * Determine the life time for the token.
  *
  * This examines the GET parameters if a field "ttl" has been set.
  * If not, it examines the JSON post data for a field named ttl.
  *
  * @param Request $request The request.
  *
  * @return int|null
  */
 private function determineLifeTime(Request $request)
 {
     if ($lifetime = $request->query->getInt('ttl')) {
         return $this->revertToNullOnMinusOne($lifetime);
     }
     try {
         $inputData = new JsonArray($request->getContent());
         if ($inputData->has('ttl')) {
             return $this->revertToNullOnMinusOne(intval($inputData->get('ttl')));
         }
     } catch (\Exception $e) {
         // Swallow exception, we need to return a defined result.
     }
     return 3600;
 }
 /**
  * Search for packages.
  *
  * @param Request $request The search request.
  *
  * @return JsonResponse
  *
  * @ApiDoc(
  *   section="search",
  *   statusCodes = {
  *     200 = "When everything worked out ok"
  *   },
  *   authentication = true,
  *   authenticationRoles = {
  *     "ROLE_MANIPULATE_REQUIREMENTS"
  *   }
  * )
  * @ApiDescription(
  *   request={
  *    "keywords" = {
  *      "dataType" = "string",
  *      "description" = "The name of the project to search or any other keyword.",
  *      "required" = true
  *    },
  *    "type" = {
  *      "dataType" = "choice",
  *      "description" = "The type of package to search (optional, default: all).",
  *      "format" = "['installed', 'contao', 'all']",
  *      "required" = false
  *    },
  *    "threshold" = {
  *      "dataType" = "int",
  *      "description" = "The amount of results after which the search shall be stopped (optional, default: 20).",
  *      "required" = false
  *    }
  *   },
  *   response={
  *     "package name 1...n" = {
  *       "actualType" = "object",
  *       "subType" = "object",
  *       "description" = "The content of the packages",
  *       "children" = {
  *         "name" = {
  *           "dataType" = "string",
  *           "description" = "The name of the package"
  *         },
  *         "version" = {
  *           "dataType" = "string",
  *           "description" = "The version of the package"
  *         },
  *         "constraint" = {
  *           "dataType" = "string",
  *           "description" = "The constraint of the package (when package is installed)"
  *         },
  *         "type" = {
  *           "dataType" = "string",
  *           "description" = "The noted package type"
  *         },
  *         "locked" = {
  *           "dataType" = "string",
  *           "description" = "Flag if the package has been locked for updates"
  *         },
  *         "time" = {
  *           "dataType" = "datetime",
  *           "description" = "The release date"
  *         },
  *         "upgrade_version" = {
  *           "dataType" = "string",
  *           "description" = "The version available for upgrade (optional, if any)"
  *         },
  *         "description" = {
  *           "dataType" = "string",
  *           "description" = "The package description"
  *         },
  *         "license" = {
  *           "actualType" = "collection",
  *           "subType" = "string",
  *           "description" = "The licenses"
  *         },
  *         "keywords" = {
  *           "actualType" = "collection",
  *           "subType" = "string",
  *           "description" = "The keywords"
  *         },
  *         "homepage" = {
  *           "dataType" = "string",
  *           "description" = "The support website (optional, if any)"
  *         },
  *         "authors" = {
  *           "actualType" = "collection",
  *           "subType" = "object",
  *           "description" = "The authors",
  *           "children" = {
  *             "name" = {
  *               "dataType" = "string",
  *               "description" = "Full name of the author (optional, if any)"
  *             },
  *             "homepage" = {
  *               "dataType" = "string",
  *               "description" = "Email address of the author (optional, if any)"
  *             },
  *             "email" = {
  *               "dataType" = "string",
  *               "description" = "Homepage URL for the author (optional, if any)"
  *             },
  *             "role" = {
  *               "dataType" = "string",
  *               "description" = "Author's role in the project (optional, if any)"
  *             }
  *           }
  *         },
  *         "support" = {
  *           "actualType" = "collection",
  *           "subType" = "object",
  *           "description" = "The support options",
  *           "children" = {
  *             "email" = {
  *               "dataType" = "string",
  *               "description" = "Email address for support (optional, if any)"
  *             },
  *             "issues" = {
  *               "dataType" = "string",
  *               "description" = "URL to the issue tracker (optional, if any)"
  *             },
  *             "forum" = {
  *               "dataType" = "string",
  *               "description" = "URL to the forum (optional, if any)"
  *             },
  *             "wiki" = {
  *               "dataType" = "string",
  *               "description" = "URL to the wiki (optional, if any)"
  *             },
  *             "irc" = {
  *               "dataType" = "string",
  *               "description" = "IRC channel for support, as irc://server/channel (optional, if any)"
  *             },
  *             "source" = {
  *               "dataType" = "string",
  *               "description" = "URL to browse or download the sources (optional, if any)"
  *             },
  *             "docs" = {
  *               "dataType" = "string",
  *               "description" = "URL to the documentation (optional, if any)"
  *             },
  *           }
  *         },
  *         "abandoned" = {
  *           "dataType" = "boolean",
  *           "description" = "Flag if this package is abandoned"
  *         },
  *         "replacement" = {
  *           "dataType" = "string",
  *           "description" = "Replacement for this package (optional, if any)"
  *         },
  *         "installed" = {
  *           "dataType" = "int",
  *           "description" = "Amount of installations"
  *         },
  *         "downloads" = {
  *           "dataType" = "int",
  *           "description" = "Amount of downloads"
  *         },
  *         "favers" = {
  *           "dataType" = "int",
  *           "description" = "Amount of favers"
  *         },
  *       }
  *     }
  *   }
  * )
  */
 public function searchAction(Request $request)
 {
     $composer = $this->getComposer();
     $data = new JsonArray($request->getContent());
     $keywords = $data->get('keywords');
     $type = $data->get('type');
     $threshold = $data->has('threshold') ? $data->get('threshold') : 20;
     $localRepository = $composer->getRepositoryManager()->getLocalRepository();
     $searcher = $this->getRepositorySearch($keywords, $type, $composer, $threshold);
     $results = $searcher->searchAndDecorate($keywords, $this->getFilters($type));
     $responseData = [];
     $rootPackage = $composer->getPackage();
     $converter = new PackageConverter($rootPackage);
     foreach ($results as $versionedResult) {
         /** @var VersionedPackage $versionedResult */
         // Might have no version matching the current stability setting.
         if (null === ($latestVersion = $versionedResult->getLatestVersion())) {
             continue;
         }
         $package = $converter->convertPackageToArray($latestVersion);
         $package->set('installed', $this->getInstalledVersion($localRepository, $versionedResult->getName()))->set('downloads', $versionedResult->getMetaData('downloads'))->set('favers', $versionedResult->getMetaData('favers'));
         $responseData[$package->get('name')] = $package->getData();
     }
     return JsonResponse::create($responseData)->setEncodingOptions(JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_FORCE_OBJECT);
 }
Example #8
0
 /**
  * Test the merge method.
  *
  * @return void
  */
 public function testMerge()
 {
     $json = new JsonArray(['test' => ['key1' => 'value1', 'key2' => 'value2']]);
     $json->merge(['test' => ['key1' => 'value1', 'key2' => 'foobar', 'key3' => 'three']]);
     $this->assertEquals(['test'], $json->getEntries('/'));
     $this->assertEquals(['test/key1', 'test/key2', 'test/key3'], $json->getEntries('/test'));
     $this->assertEquals('foobar', $json->get('/test/key2'));
 }
 /**
  * Queue a task in the list.
  *
  * @param Request $request The request.
  *
  * @return JsonResponse
  *
  * @throws NotAcceptableHttpException When the payload is invalid.
  *
  * @ApiDoc(
  *   section="tasks",
  *   statusCodes = {
  *     201 = "When everything worked out ok",
  *     406 = "When the payload is invalid"
  *   },
  *   authentication = true,
  *   authenticationRoles = {
  *     "ROLE_MANIPULATE_REQUIREMENTS"
  *   },
  * )
  * @ApiDescription(
  *   response={
  *     "status" = {
  *       "dataType" = "string",
  *       "description" = "OK on success"
  *     },
  *     "task" = {
  *         "id" = {
  *           "dataType" = "string",
  *           "description" = "The task id."
  *         },
  *         "status" = {
  *           "dataType" = "string",
  *           "description" = "The task status."
  *         },
  *         "type" = {
  *           "dataType" = "string",
  *           "description" = "The type of the task."
  *         },
  *         "user_data" = {
  *           "dataType" = "object",
  *           "description" = "The user submitted additional data."
  *         },
  *         "created_at" = {
  *           "dataType" = "string",
  *           "description" = "The date the task was created in ISO 8601 format."
  *         }
  *      }
  *   }
  * )
  */
 public function addTaskAction(Request $request)
 {
     $metaData = null;
     $content = $request->getContent();
     if (empty($content)) {
         throw new NotAcceptableHttpException('Invalid payload');
     }
     $metaData = new JsonArray($content);
     if (!$metaData->has('type')) {
         throw new NotAcceptableHttpException('Invalid payload');
     }
     try {
         $taskId = $this->getTensideTasks()->queue($metaData->get('type'), $metaData);
     } catch (\InvalidArgumentException $exception) {
         throw new NotAcceptableHttpException($exception->getMessage());
     }
     return $this->createJsonResponse([$this->convertTaskToArray($this->getTensideTasks()->getTask($taskId))], false, 'OK', JsonResponse::HTTP_CREATED);
 }
Example #10
0
 /**
  * Test that the reason of root requirements get converted.
  *
  * @return void
  */
 public function testRootInstallReasonGetsConverted()
 {
     $json = new JsonArray();
     $manager = new InstallationManager($json);
     $installer = $this->getMockForAbstractClass(InstallerInterface::class);
     $pool = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->getMock();
     $manager->addInstaller($installer);
     $manager->setPool($pool);
     $reason = $this->getMockBuilder(Rule::class)->disableOriginalConstructor()->getMock();
     $reason->method('getPrettyString')->with($pool)->willReturn('The reason is 42');
     $reason->method('getReason')->willReturn(Rule::RULE_JOB_INSTALL);
     $repository = $this->getMockForAbstractClass(InstalledRepositoryInterface::class);
     $package = $this->getMockForAbstractClass(PackageInterface::class);
     $operation = new InstallOperation($package, $reason);
     $package->method('getType')->will($this->returnValue('library'));
     $package->method('getPrettyName')->will($this->returnValue('vendor/package'));
     $installer->expects($this->once())->method('supports')->with('library')->will($this->returnValue(true));
     $installer->expects($this->once())->method('install')->with($repository, $package);
     $manager->install($repository, $operation);
     $this->assertEquals('Required by the root package: The reason is 42', $json->get('vendor\\/package/reason'));
 }
 /**
  * Retrieve the available versions of a package.
  *
  * NOTE: This method will become inaccessible as soon as the installation is complete.
  *
  * @param string $vendor  The vendor name of the package.
  *
  * @param string $project The name of the package.
  *
  * @return JsonResponse
  *
  * @ApiDoc(
  *   section="install",
  *   statusCodes = {
  *     201 = "When everything worked out ok",
  *     406 = "When the installation is already complete"
  *   },
  * )
  * @ApiDescription(
  *   response={
  *     "versions" = {
  *       "actualType" = "collection",
  *       "subType" = "object",
  *       "description" = "The list of versions",
  *       "children" = {
  *         "name" = {
  *           "dataType" = "string",
  *           "description" = "The name of the package"
  *         },
  *         "version" = {
  *           "dataType" = "string",
  *           "description" = "The version of the package"
  *         },
  *         "version_normalized" = {
  *           "dataType" = "string",
  *           "description" = "The normalized version of the package"
  *         },
  *         "reference" = {
  *           "dataType" = "string",
  *           "description" = "The optional reference"
  *         }
  *       }
  *     }
  *   }
  * )
  */
 public function getProjectVersionsAction($vendor, $project)
 {
     $this->checkUninstalled();
     $url = sprintf('https://packagist.org/packages/%s/%s.json', $vendor, $project);
     $rfs = new RemoteFilesystem($this->getInputOutput());
     $results = $rfs->getContents($url, $url);
     $data = new JsonArray($results);
     $versions = [];
     foreach ($data->get('package/versions') as $information) {
         $version = ['name' => $information['name'], 'version' => $information['version'], 'version_normalized' => $information['version_normalized']];
         $normalized = $information['version'];
         if ('dev-' === substr($normalized, 0, 4)) {
             if (isset($information['extra']['branch-alias'][$normalized])) {
                 $version['version_normalized'] = $information['extra']['branch-alias'][$normalized];
             }
         }
         if (isset($information['source']['reference'])) {
             $version['reference'] = $information['source']['reference'];
         } elseif (isset($information['dist']['reference'])) {
             $version['reference'] = $information['dist']['reference'];
         }
         $versions[] = $version;
     }
     return new JsonResponse(['status' => 'OK', 'versions' => $versions]);
 }
 /**
  * Convert the information of all packages in a repository to an array used by json API.
  *
  * @param RepositoryInterface $repository   The repository holding the packages to convert.
  *
  * @param bool                $requiredOnly If true, return only the packages added to the root package as require.
  *
  * @param null|JsonArray      $upgradeList  The package version to show as upgradable to.
  *
  * @return JsonArray
  */
 public function convertRepositoryToArray(RepositoryInterface $repository, $requiredOnly = false, JsonArray $upgradeList = null)
 {
     $requires = $requiredOnly ? $this->rootPackage->getRequires() : false;
     $packages = new JsonArray();
     /** @var \Composer\Package\PackageInterface $package */
     foreach ($repository->getPackages() as $package) {
         $name = $package->getPrettyName();
         $esc = $packages->escape($name);
         if (false === $requires || isset($requires[$name])) {
             $upgradeVersion = null;
             if ($upgradeList && $upgradeList->has($esc)) {
                 $upgradeVersion = $upgradeList->get($esc);
             }
             $packages->set($esc, $this->convertPackageToArray($package, $upgradeVersion)->getData());
         }
     }
     return $packages;
 }
Example #13
0
 /**
  * Ensure the home path has been set in the passed meta data.
  *
  * @param JsonArray $metaData The meta data to examine.
  *
  * @return void
  */
 private function ensureHomePath(JsonArray $metaData)
 {
     if ($metaData->has(AbstractPackageManipulatingTask::SETTING_HOME)) {
         return;
     }
     $metaData->set(AbstractPackageManipulatingTask::SETTING_HOME, $this->home->homeDir());
 }
Example #14
0
 /**
  * Create a task instance from the given MetaData.
  *
  * @param JsonArray $config The configuration of the task.
  *
  * @return Task|null
  */
 private function createTaskFromMetaData(JsonArray $config)
 {
     $typeName = $config->get(Task::SETTING_TYPE);
     if ($this->factory->isTypeSupported($typeName)) {
         return $this->factory->createInstance($typeName, $config);
     }
     return null;
 }
Example #15
0
 /**
  * {@inheritDoc}
  */
 public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
 {
     $this->packageInformation->set($this->packageInformation->escape($operation->getPackage()->getPrettyName()), ['type' => 'uninstall', 'package' => $this->dumper->dump($operation->getPackage())]);
     parent::uninstall($repo, $operation);
 }
Example #16
0
 /**
  * {@inheritDoc}
  */
 public function set($path, $value)
 {
     $this->data->set($path, $value);
     return $this;
 }
Example #17
0
 /**
  * Set the task state.
  *
  * @param string $status The status code.
  *
  * @return void
  */
 protected function setStatus($status)
 {
     $this->file->set('status', $status);
 }
Example #18
0
 /**
  * Test that a RemovePackageTask task is created properly.
  *
  * @return void
  */
 public function testOnCreateTaskRemovePackageTask()
 {
     $factory = new ComposerTaskFactory(new HomePathDeterminator($this->getTempDir()));
     $task = $factory->createInstance('remove-package', $config = new JsonArray([RemovePackageTask::SETTING_TYPE => 'remove-package', RemovePackageTask::SETTING_ID => 'remove-task-id', RemovePackageTask::SETTING_PACKAGE => ['vendor/dependency-name', '1.0.0'], 'status' => RemovePackageTask::STATE_PENDING]));
     $this->assertInstanceOf(RemovePackageTask::class, $task);
     $this->assertEquals($this->getTempDir(), $config->get(RemovePackageTask::SETTING_HOME));
 }
Example #19
0
 /**
  * Convert the data of a complete package to the passed json array.
  *
  * @param CompletePackageInterface $package The package to process.
  *
  * @param JsonArray                $data    The json array to push the data to.
  *
  * @return void
  */
 private function convertCompletePackage(CompletePackageInterface $package, $data)
 {
     $data->set('description', $package->getDescription());
     $data->set('license', $package->getLicense());
     if ($keywords = $package->getKeywords()) {
         $data->set('keywords', $keywords);
     }
     if ($homepage = $package->getHomepage()) {
         $data->set('homepage', $homepage);
     }
     if ($authors = $package->getAuthors()) {
         $data->set('authors', $authors);
     }
     if ($support = $package->getSupport()) {
         $data->set('support', $support);
     }
     if ($extra = $package->getExtra()) {
         $data->set('extra', $extra);
     }
     $data->set('abandoned', $package->isAbandoned());
     if ($package->isAbandoned()) {
         $data->set('replacement', $package->getReplacementPackage());
     }
 }
Example #20
0
 /**
  * Decorate the package with stats from packagist.
  *
  * @param VersionedPackage $package The package version.
  *
  * @return VersionedPackage
  */
 protected function decorateWithPackagistStats(VersionedPackage $package)
 {
     if (null === $this->decorateBaseUrl) {
         return $package;
     }
     $rfs = new RemoteFilesystem(new BufferIO());
     $requestUrl = sprintf($this->decorateBaseUrl, $package->getName());
     if (!($jsonData = $rfs->getContents($requestUrl, $requestUrl))) {
         $this->decorateBaseUrl = null;
         return $package;
     }
     try {
         $data = new JsonArray($jsonData);
     } catch (\RuntimeException $exception) {
         $this->decorateBaseUrl = null;
         return $package;
     }
     $metaPaths = ['downloads' => 'package/downloads/total', 'favers' => 'package/favers'];
     foreach ($metaPaths as $metaKey => $metaPath) {
         $package->addMetaData($metaKey, $data->get($metaPath));
     }
     return $package;
 }