Skip to content
Snippets Groups Projects
Commit efe43b63 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3399155: Build test 'files_to_return' logic is not needed

parent a469e081
No related branches found
No related tags found
No related merge requests found
......@@ -81,24 +81,22 @@ END;
$this->assertStringContainsString('The project new_module is not a Drupal project known to Composer and cannot be updated.', $page_text);
$this->assertStringContainsString('new_module', $page_text);
// Use the API endpoint to create a stage and update the 'alpha' module to
// 1.1.0. We ask the API to return the contents of the module's
// composer.json file, so we can assert that they were updated to the
// version we expect.
// @see \Drupal\automatic_updates_extensions_test_api\ApiController::run()
$file_contents = $this->getPackageManagerTestApiResponse(
// 1.1.0.
$this->makePackageManagerTestApiRequest(
'/automatic-updates-extensions-test-api',
[
'projects' => [
'alpha' => '1.1.0',
],
'files_to_return' => [
'web/modules/contrib/alpha/composer.json',
],
]
);
$module_composer_json = json_decode($file_contents['web/modules/contrib/alpha/composer.json']);
$this->assertSame('1.1.0', $module_composer_json?->version);
$updated_composer_json = $this->getWebRoot() . 'modules/contrib/alpha/composer.json';
// Assert the module was updated.
$this->assertFileEquals(
__DIR__ . '/../../../../package_manager/tests/fixtures/build_test_projects/alpha/1.1.0/composer.json',
$updated_composer_json,
);
$this->assertRequestedChangesWereLogged(['Update drupal/alpha from 1.0.0 to 1.1.0']);
$this->assertAppliedChangesWereLogged(['Updated drupal/alpha from 1.0.0 to 1.1.0']);
}
......
......@@ -15,7 +15,6 @@ use PhpTuf\ComposerStager\API\Core\CommitterInterface;
use PhpTuf\ComposerStager\API\Core\StagerInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -90,9 +89,7 @@ class ApiController extends ControllerBase {
* @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.
* keys, respectively.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A response that directs to the ::finish() method.
......@@ -103,9 +100,6 @@ class ApiController extends ControllerBase {
$id = $this->createAndApplyStage($request);
$redirect_url = Url::fromRoute($this->finishedRoute)
->setRouteParameter('id', $id)
->setOption('query', [
'files_to_return' => $request->get('files_to_return', []),
])
->setAbsolute()
->toString();
......@@ -117,26 +111,14 @@ class ApiController extends ControllerBase {
*
* @param string $id
* The stage ID.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request. There may be a 'files_to_return' key in either the query
* string or request body 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.
* @return \Symfony\Component\HttpFoundation\Response
* The response.
*/
public function finish(string $id, Request $request): JsonResponse {
public function finish(string $id): Response {
$this->stage->claim($id)->postApply();
$this->stage->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);
return new Response();
}
/**
......@@ -145,9 +127,7 @@ class ApiController extends ControllerBase {
* @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.
* keys, respectively.
*
* @return string
* Unique ID for the stage, which can be used to claim the stage before
......
......@@ -26,22 +26,20 @@ class PackageInstallTest extends TemplateProjectTestBase {
// ensure that Composer won't complain that the lock file is out of sync.
$this->runComposer('composer update --lock', 'project');
// Use the API endpoint to create a stage and install alpha 1.0.0. We ask
// the API to return the contents of composer.json file of installed module,
// so we can assert that the module was installed with the expected version.
// @see \Drupal\package_manager_test_api\ApiController::run()
$file_contents = $this->getPackageManagerTestApiResponse(
// Use the API endpoint to create a stage and install alpha 1.0.0.
$this->makePackageManagerTestApiRequest(
'/package-manager-test-api',
[
'runtime' => [
'drupal/alpha:1.0.0',
],
'files_to_return' => [
'web/modules/contrib/alpha/composer.json',
],
]
);
$this->assertArrayHasKey('web/modules/contrib/alpha/composer.json', $file_contents);
// Assert the module was installed.
$this->assertFileEquals(
__DIR__ . '/../../fixtures/build_test_projects/alpha/1.0.0/composer.json',
$this->getWebRoot() . '/modules/contrib/alpha/composer.json',
);
$this->assertRequestedChangesWereLogged(['Install drupal/alpha 1.0.0']);
$this->assertAppliedChangesWereLogged(['Installed drupal/alpha 1.0.0']);
}
......
......@@ -42,22 +42,13 @@ class PackageUpdateTest extends TemplateProjectTestBase {
// Use the API endpoint to create a stage and update updated_module to
// 1.1.0. Even though both modules have version 1.1.0 available, only
// updated_module should be updated. We ask the API to return the contents
// of both modules' composer.json files, so we can assert that they were
// updated to the versions we expect.
// @see \Drupal\package_manager_test_api\ApiController::run()
$file_contents = $this->getPackageManagerTestApiResponse(
// updated_module should be updated.
$this->makePackageManagerTestApiRequest(
'/package-manager-test-api',
[
'runtime' => [
'drupal/updated_module:1.1.0',
],
'files_to_return' => [
'web/modules/contrib/alpha/composer.json',
'web/modules/contrib/updated_module/composer.json',
'bravo.txt',
"system_changes.json",
],
]
);
......@@ -66,14 +57,14 @@ class PackageUpdateTest extends TemplateProjectTestBase {
'updated_module' => '1.1.0',
];
foreach ($expected_versions as $module_name => $expected_version) {
$path = "web/modules/contrib/$module_name/composer.json";
$module_composer_json = json_decode($file_contents[$path]);
$path = "/modules/contrib/$module_name/composer.json";
$module_composer_json = json_decode(file_get_contents($this->getWebRoot() . "/$path"));
$this->assertSame($expected_version, $module_composer_json?->version);
}
// The post-apply event subscriber in updated_module 1.1.0 should have
// created this file.
// @see \Drupal\updated_module\PostApplySubscriber::postApply()
$this->assertSame('Bravo!', $file_contents['bravo.txt']);
$this->assertSame('Bravo!', file_get_contents($this->getWorkspaceDirectory() . '/project/bravo.txt'));
$this->assertExpectedStageEventsFired(ControllerStage::class);
$this->assertRequestedChangesWereLogged(['Update drupal/updated_module from 1.0.0 to 1.1.0']);
......
......@@ -719,27 +719,21 @@ END;
* The package manager test API URL to fetch.
* @param array $query_data
* The query data.
*
* @return array
* The received JSON.
*/
protected function getPackageManagerTestApiResponse(string $url, array $query_data): array {
protected function makePackageManagerTestApiRequest(string $url, array $query_data): void {
$url .= '?' . http_build_query($query_data);
$this->visit($url);
$mink = $this->getMink();
$session = $mink->getSession();
$file_contents = $session->getPage()->getContent();
// Ensure test failures provide helpful debug output when there's a fatal
// PHP error: don't use \Behat\Mink\WebAssert::statusCodeEquals().
if ($session->getStatusCode() == 500) {
$this->assertEquals(200, 500, 'Error response: ' . $file_contents);
$this->assertEquals(200, 500, 'Error response: ' . $session->getPage()->getContent());
}
else {
$mink->assertSession()->statusCodeEquals(200);
}
return json_decode($file_contents, TRUE, flags: JSON_THROW_ON_ERROR);
}
// BEGIN: DELETE FROM CORE MERGE REQUEST.
......
......@@ -98,9 +98,6 @@ class CoreUpdateTest extends UpdateTestBase {
'projects' => [
'drupal' => '9.8.1',
],
'files_to_return' => [
'web/core/lib/Drupal.php',
],
]);
// Ensure that the update is prevented if the web root and/or vendor
// directories are not writable.
......@@ -131,9 +128,11 @@ class CoreUpdateTest extends UpdateTestBase {
// Even though the response is what we expect, assert the status code as
// well, to be extra-certain that there was no kind of server-side error.
$this->assertSame(200, $update_status_code);
$file_contents = json_decode($file_contents, TRUE, flags: JSON_THROW_ON_ERROR);
$this->assertStringContainsString("const VERSION = '9.8.1';", $file_contents['web/core/lib/Drupal.php']);
$this->assertStringContainsString(
"const VERSION = '9.8.1';",
file_get_contents($this->getWebRoot() . '/core/lib/Drupal.php')
);
$this->assertUpdateSuccessful('9.8.1');
$this->assertRequestedChangesWereLogged([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment