Skip to content
Snippets Groups Projects
Commit e28dcb2d authored by Ted Bowman's avatar Ted Bowman Committed by Adam G-H
Browse files

Issue #3344127 by tedbow, kunal.sachdev, Wim Leers, phenaproxima: Run...

Issue #3344127 by tedbow, kunal.sachdev, Wim Leers, phenaproxima: Run `composer validate` after FixtureManipulator commits its changes
parent fcf4aa59
No related branches found
No related tags found
5 merge requests!989Issue #3356804 by phenaproxima: Flag a warning during status check if the...,!730Issue #3344127: Composer validate all fixture manipulation changes,!685Issue #3338667: [PP-1] Add build test to test cweaganscomposer-patches end-to-end,!548Issue #3310729: Incorrect documentation link in UI in case of Process error,!106Issue #3247479: Allow LockFileValidator results to carry multiple messages, and improve their text
......@@ -5,6 +5,7 @@ namespace Drupal\fixture_manipulator;
use Composer\Semver\VersionParser;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Serialization\Yaml;
use PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface;
use Symfony\Component\Filesystem\Filesystem;
/**
......@@ -40,6 +41,25 @@ class FixtureManipulator {
*/
private string $dir;
/**
* Validate the fixtures still passes `composer validate`.
*/
private function validateComposer(): void {
/** @var \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface $runner */
$runner = \Drupal::service(ComposerRunnerInterface::class);
$runner->run([
'validate',
// @todo Check the lock file in https://drupal.org/i/3343827.
'--no-check-lock',
'--no-check-publish',
'--with-dependencies',
'--no-interaction',
'--ansi',
'--no-cache',
"--working-dir={$this->dir}",
]);
}
/**
* Adds a package.
*
......@@ -60,7 +80,11 @@ class FixtureManipulator {
*/
public function addPackage(array $package, bool $is_dev_requirement = FALSE, bool $create_project = TRUE): self {
if (!$this->committingChanges) {
$this->queueManipulation('addPackage', func_get_args());
// To pass Composer validation all packages must have a version specified.
if (!isset($package['version'])) {
$package['version'] = '1.2.3';
}
$this->queueManipulation('addPackage', [$package, $is_dev_requirement, $create_project]);
return $this;
}
foreach (['name', 'type'] as $required_key) {
......@@ -357,7 +381,7 @@ class FixtureManipulator {
* @param string $dir
* The directory to commit the changes to.
*/
protected function doCommitChanges(string $dir): void {
final protected function doCommitChanges(string $dir): void {
if ($this->committed) {
throw new \BadMethodCallException('Already committed.');
}
......@@ -372,6 +396,7 @@ class FixtureManipulator {
}
$this->committed = TRUE;
$this->committingChanges = FALSE;
$this->validateComposer();
}
/**
......
......@@ -136,11 +136,14 @@ class ComposerPatchesValidatorTest extends PackageManagerKernelTestBase {
}
if ($in_stage && !$in_active) {
// Simulate a stage directory where the patcher is installed.
$package_data = json_decode(file_get_contents(__DIR__ . '/../../fixtures/path_repos/cweagans--composer-patches/composer.json'), TRUE);
$package_data['version'] = '24.12.1999';
$this->getStageFixtureManipulator()
->addPackage([
'name' => 'cweagans/composer-patches',
'version' => '24.12.1999',
'type' => 'composer-plugin',
->addPackage($package_data)
->addConfig([
'allow-plugins' => [
'cweagans/composer-patches' => TRUE,
],
]);
}
......
......@@ -145,6 +145,11 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
$this->testValidationDuringPreApply($composer_config_to_add, $packages_to_add, $expected_results_without_composer_plugin_violations);
}
/**
* Generates simple test cases.
*
* @return \Generator
*/
public function providerSimpleValidCases(): \Generator {
yield 'no composer plugins' => [
[],
......@@ -168,6 +173,8 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
'name' => 'cweagans/composer-patches',
'version' => '1.0.0',
'type' => 'composer-plugin',
'require' => ['composer-plugin-api' => '*'],
'extra' => ['class' => 'AnyClass'],
],
],
[
......@@ -193,6 +200,8 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
'name' => 'drupal/core-vendor-hardening',
'version' => '9.8.0',
'type' => 'composer-plugin',
'require' => ['composer-plugin-api' => '*'],
'extra' => ['class' => 'AnyClass'],
],
],
[],
......@@ -209,6 +218,8 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
'name' => 'composer/plugin-A',
'version' => '6.1',
'type' => 'composer-plugin',
'require' => ['composer-plugin-api' => '*'],
'extra' => ['class' => 'AnyClass'],
],
],
[],
......@@ -225,11 +236,17 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
'name' => 'composer/plugin-b',
'version' => '20.1',
'type' => 'composer-plugin',
'require' => ['composer-plugin-api' => '*'],
'extra' => ['class' => 'AnyClass'],
],
],
[],
];
// @todo handle following type of case where the project is invalid in
// https://www.drupal.org/node/3344595.
// phpcs:disable
/*
yield 'one UNsupported but disallowed plugin' => [
[
'allow-plugins' => [
......@@ -242,10 +259,14 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
'name' => 'composer/plugin-c',
'version' => '16.4',
'type' => 'composer-plugin',
'require' => ['composer-plugin-api' => '*'],
'extra' => ['class' => 'AnyClass'],
],
],
[],
];
*/
// phpcs:enable
}
public function providerSimpleInvalidCases(): \Generator {
......@@ -258,6 +279,8 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
[
[
'name' => 'NOT-cweagans/NOT-composer-patches',
'require' => ['composer-plugin-api' => '*'],
'extra' => ['class' => 'AnyClass'],
'version' => '6.1',
'type' => 'composer-plugin',
],
......@@ -283,6 +306,8 @@ class ComposerPluginsValidatorTest extends PackageManagerKernelTestBase {
'name' => 'also-not-cweagans/also-not-composer-patches',
'version' => '20.1',
'type' => 'composer-plugin',
'require' => ['composer-plugin-api' => '*'],
'extra' => ['class' => 'AnyClass'],
],
],
[
......
......@@ -150,6 +150,9 @@ class FixtureManipulatorTest extends PackageManagerKernelTestBase {
'my/package' => [
'name' => 'my/package',
'type' => 'library',
// If no version is specified in a new package it will be added.
'version' => '1.2.3',
'version_normalized' => '1.2.3.0',
],
'my/dev-package' => [
'name' => 'my/dev-package',
......@@ -162,6 +165,7 @@ class FixtureManipulatorTest extends PackageManagerKernelTestBase {
// Composer stores `version_normalized`in 'installed.json' but not
// 'installed.php'.
unset($installed_php_expected_packages['my/dev-package']['version_normalized']);
unset($installed_php_expected_packages['my/package']['version_normalized']);
[$installed_json, $installed_php] = $this->getData();
$installed_json['packages'] = array_intersect_key($installed_json['packages'], $installed_json_expected_packages);
$this->assertSame($installed_json_expected_packages, $installed_json['packages']);
......@@ -245,6 +249,8 @@ class FixtureManipulatorTest extends PackageManagerKernelTestBase {
'my/package' => [
'name' => 'my/package',
'type' => 'metapackage',
'version' => '1.2.3',
'version_normalized' => '1.2.3.0',
],
'my/dev-package' => [
'name' => 'my/dev-package',
......@@ -255,12 +261,16 @@ class FixtureManipulatorTest extends PackageManagerKernelTestBase {
'my/other-package' => [
'name' => 'my/other-package',
'type' => 'library',
'version' => '1.2.3',
'version_normalized' => '1.2.3.0',
],
];
$installed_php_expected_packages = $install_json_expected_packages;
// Composer stores `version_normalized`in 'installed.json' but not
// 'installed.php'.
unset($installed_php_expected_packages['my/dev-package']['version_normalized']);
unset($installed_php_expected_packages['my/package']['version_normalized']);
unset($installed_php_expected_packages['my/other-package']['version_normalized']);
$installed_php_expected_packages['my/dev-package']['install_path'] = "$this->dir/vendor/composer/../relative/path";
[$installed_json, $installed_php] = $this->getData();
$installed_json['packages'] = array_intersect_key($installed_json['packages'], $install_json_expected_packages);
......
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