Skip to content
Snippets Groups Projects

Issue #3344127: Composer validate all fixture manipulation changes

Merged Issue #3344127: Composer validate all fixture manipulation changes
8 unresolved threads
8 unresolved threads
Compare and Show latest version
1 file
+ 5
4
Compare changes
  • Side-by-side
  • Inline
@@ -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);
+1
$runner->run([
'validate',
// @todo Check the lock file in https://drupal.org/i/3343827.
'--no-check-lock',
    • Comment on lines +51 to +52
      Author Maintainer

      In that issue we will be update the lock file when we manipulate the fixtures

Please register or sign in to reply
'--no-check-publish',
Please register or sign in to reply
'--with-dependencies',
'--no-interaction',
'--ansi',
'--no-cache',
"--working-dir={$this->dir}",
    • Comment on lines -59 to +59

      Turns out this works thanks to Magic 🪄

      (Symfony's Process already does this for us: \Symfony\Component\Process\Process::escapeArgument() :shrug:)

Please register or sign in to reply
]);
}
/**
* 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';
}
    • Comment on lines +82 to +85

      In order to keep the tests simple, I think this is a reasonable default to set :thumbsup: It's also easy to grep for :thumbsup:

Please register or sign in to reply
$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 {
Please register or sign in to reply
if ($this->committed) {
throw new \BadMethodCallException('Already committed.');
}
@@ -372,6 +396,7 @@ class FixtureManipulator {
}
$this->committed = TRUE;
$this->committingChanges = FALSE;
$this->validateComposer();
}
/**
Loading