Skip to content
Snippets Groups Projects

Issue #3298889: Make \Drupal\package_manager_test_api\ApiController more easily extendable

Merged Issue #3298889: Make \Drupal\package_manager_test_api\ApiController more easily extendable
1 unresolved thread
1 unresolved thread
11 files
+ 119
143
Compare changes
  • Side-by-side
  • Inline
Files
11
@@ -2,45 +2,19 @@
namespace Drupal\automatic_updates_extensions_test_api;
use Drupal\automatic_updates_extensions\ExtensionUpdater;
use Drupal\Core\Controller\ControllerBase;
use Drupal\package_manager\PathLocator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\package_manager_test_api\ApiController as PackageManagerApiController;
/**
* Provides API endpoints to interact with a staging area in functional tests.
*/
class ApiController extends ControllerBase {
/**
* The extension updater.
*
* @var \Drupal\automatic_updates_extensions\ExtensionUpdater
*/
private $extensionUpdater;
class ApiController extends PackageManagerApiController {
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
private $pathLocator;
/**
* Constructs an ApiController object.
*
* @param \Drupal\automatic_updates_extensions\ExtensionUpdater $extension_updater
* The updater.
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* {@inheritdoc}
*/
public function __construct(ExtensionUpdater $extension_updater, PathLocator $path_locator) {
$this->extensionUpdater = $extension_updater;
$this->pathLocator = $path_locator;
}
protected $finishedRoute = 'automatic_updates_extensions_test_api.finish';
/**
* {@inheritdoc}
@@ -53,36 +27,13 @@ class ApiController extends ControllerBase {
}
/**
* Runs a complete stage life cycle.
*
* Creates a staging area, requires packages into it, applies changes to the
* active directory, and destroys the stage.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request. The runtime and dev dependencies are expected to be in
* either the query string or request body, under the 'runtime' and 'dev'
* keys, respectively. There may also be a 'files_to_return' key, which
* contains an array of file paths, relative to the project root, whose
* contents should be returned in the response.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* A JSON response containing an associative array of the contents of the
* files listed in the 'files_to_return' request key. The array will be
* keyed by path, relative to the project root.
* {@inheritdoc}
*/
public function run(Request $request): JsonResponse {
$this->extensionUpdater->begin($request->get('projects', []));
$this->extensionUpdater->stage();
$this->extensionUpdater->apply();
$this->extensionUpdater->postApply();
$this->extensionUpdater->destroy();
$dir = $this->pathLocator->getProjectRoot();
$file_contents = [];
foreach ($request->get('files_to_return', []) as $path) {
$file_contents[$path] = file_get_contents($dir . '/' . $path);
}
return new JsonResponse($file_contents);
protected function createAndApplyStage(Request $request): string {
$id = $this->stage->begin($request->get('projects', []));
$this->stage->stage();
$this->stage->apply();
return $id;
}
}
Loading