Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make jobs work on Drupal 10 #279

Merged
merged 5 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions example/example.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ name: Example
type: module
description: "Provides an example module for testing and illustration purposes."
package: Other
core: 8.x
core_version_requirement: '^8 || ^9'
core_version_requirement: '^8 || ^9 || ^10'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ name: "Example Submodule: Do Not Enable"
type: module
description: "An example submodule that is not enabled by ORCA."
package: Other
core: 8.x
core_version_requirement: '^8 || ^9'
core_version_requirement: '^8 || ^9 || ^10'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ name: "Example Submodule: Enable"
type: module
description: "An example submodule that is enabled by ORCA."
package: Other
core: 8.x
core_version_requirement: '^8 || ^9'
core_version_requirement: '^8 || ^9 || ^10'
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ name: "Example Submodule: Remove"
type: module
description: "An example submodule that is removed from the packages config via ORCA_PACKAGES_CONFIG_ALTER."
package: Other
core: 8.x
17 changes: 17 additions & 0 deletions src/Domain/Composer/ComposerFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@ public static function isValidPackageName(string $name): bool {
return !ValidatingArrayLoader::hasPackageNamingError($name);
}

/**
* Remove config from root composer.json.
*
* @param array $config
* A list of config elements to be removed, e.g., "platform".
*/
public function removeConfig(array $config): void {
if (empty($config)) {
throw new \InvalidArgumentException('No config provided to remove.');
}

$this->runComposer([
'config',
'--unset',
], $config);
}

/**
* Removes packages.
*
Expand Down
19 changes: 18 additions & 1 deletion src/Domain/Fixture/FixtureCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public function __construct(CloudHooksInstaller $cloud_hooks_installer, Codebase
public function create(FixtureOptions $options): void {
$this->options = $options;
$this->createComposerProject();
$this->removeComposerConfigPlatform();
$this->fixDefaultDependencies();
$this->addAllowedComposerPlugins();
$this->addCompanyPackages();
Expand All @@ -211,6 +212,19 @@ private function createComposerProject(): void {
$this->codebaseCreator->create($this->options);
}

/**
* Remove "config.platform" parameter from fixture root composer.json.
*/
private function removeComposerConfigPlatform(): void {
$this->output->writeln("Removing Composer platform requirements.");
try {
$this->composer->removeConfig(['platform']);
}
catch (\Exception $e) {
$this->output->writeln("Failed to remove Composer platform requirements.");
}
}

/**
* Fixes the default dependencies.
*/
Expand Down Expand Up @@ -252,8 +266,11 @@ private function fixDefaultDependencies(): void {
}

// Acquia CMS uses drupal-test-traits as a dev dependency.
// Add only when Drupal core version is NOT 10.
// @todo remove this via ORCA-298
$additions[] = 'weitzman/drupal-test-traits';
if (!$this->options->coreVersionParsedMatches('^10')) {
$additions[] = 'weitzman/drupal-test-traits';
}

// Require additional packages.
$prefer_source = $this->options->preferSource();
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Fixture/SiteInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private function addDependencies(): void {
'help',
'toolbar',
]);
$this->addItems($info_file, 'themes', ['seven']);
$this->addItems($info_file, 'themes', ['claro']);
secretsayan marked this conversation as resolved.
Show resolved Hide resolved

$info_file->toFile($path, new Yaml());
}
Expand Down
70 changes: 46 additions & 24 deletions src/Domain/Tool/Phpunit/PhpUnitTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,51 @@ private function setTestSuite(): void {
*/
private function setCoverageFilter(): void {

// Removing default "whitelist" element.
$whitelist = $this->xpath->query('//phpunit/filter/whitelist')->item(0);
assert($whitelist instanceof \DOMElement);
$whitelist->parentNode->removeChild($whitelist);
// Adding suffixes to "whitelist" element.
$suffixes = [
'.php',
'.inc',
'.module',
'.install',
'.theme',
'.profile',
'.engine',
];

// Creating new "whitelist" element.
$whitelist = $this->doc->createElement('whitelist');
if ($whitelist instanceof \DOMElement) {
$whitelist->parentNode->removeChild($whitelist);
$appendTo = "//phpunit/filter";

// Creating new "whitelist" element.
$whitelist = $this->doc->createElement('whitelist');

foreach ($suffixes as $suffix) {
$directory = $this->doc->createElement('directory', $this->getPath());
$directory->setAttribute('suffix', $suffix);
$whitelist->appendChild($directory);
}
}
else {
// Checking for Drupal 10 style "phpunit.xml" structure.
$whitelist = $this->xpath->query('//phpunit/coverage')->item(0);
assert($whitelist instanceof \DOMElement);
$whitelist->parentNode->removeChild($whitelist);
$appendTo = "//phpunit";

// Creating new "coverage" element.
$whitelist = $this->doc->createElement('coverage');

// Create new include element.
$include = $this->doc->createElement('include');

foreach ($suffixes as $suffix) {
$directory = $this->doc->createElement('directory', $this->getPath());
$directory->setAttribute('suffix', $suffix);
$include->appendChild($directory);
}
$whitelist->appendChild($include);
}

// Excluding tests directories.
$exclude = $this->doc->createElement('exclude');
Expand All @@ -166,27 +204,11 @@ private function setCoverageFilter(): void {
$this->doc->createElement('directory', '../*/contrib/*/tests');
$exclude->appendChild($exclude_directory);

// Appending the excluded directories to "whitelist" element.
// Appending the excluded directories to "whitelist/coverage" element.
$whitelist->appendChild($exclude);

// Adding suffixes to "whitelist" element.
$suffixes = [
'.php',
'.inc',
'.module',
'.install',
'.theme',
'.profile',
'.engine',
];
foreach ($suffixes as $suffix) {
$directory = $this->doc->createElement('directory', $this->getPath());
$directory->setAttribute('suffix', $suffix);
$whitelist->appendChild($directory);
}

// Writing "whitelist" element to file.
$this->xpath->query('//phpunit/filter')->item(0)->appendChild($whitelist);
// Writing "whitelist/coverage" element to file.
$this->xpath->query($appendTo)->item(0)->appendChild($whitelist);
}

/**
Expand Down
27 changes: 23 additions & 4 deletions src/Options/FixtureOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,8 @@ public function getProjectTemplate(): string {
return $this->options['project-template'];
}

// Use minimal project for SUT-only (i.e. isolated) jobs, which should
// have no other company packages.
if ($this->isSutOnly()) {
$this->options['project-template'] = 'acquia/drupal-minimal-project';
if ($this->coreVersionParsedMatches('^10')) {
$this->options['project-template'] = 'acquia/drupal-recommended-project:dev-drupal10';
}
else {
$this->options['project-template'] = 'acquia/drupal-recommended-project';
Expand Down Expand Up @@ -343,6 +341,27 @@ public function getCoreResolved(): string {
return $version;
}

/**
* Checks if core version resolves to the constraint provided.
*
* @param string $constraints
* The constraints to check for.
*
* @return bool
* TRUE if it does or FALSE if not.
*/
public function coreVersionParsedMatches(string $constraints): bool {
$parser = new VersionParser();
$core = $this->getCoreResolved();

$required = $parser->parseConstraints($constraints);
$actual = $parser->parseConstraints($core);
if ($required->matches($actual)) {
return TRUE;
}
return FALSE;
}

/**
* Gets the raw options data.
*
Expand Down
28 changes: 28 additions & 0 deletions tests/Domain/Composer/ComposerFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,34 @@ public function providerIsValidVersionConstraint(): array {
];
}

/**
* @dataProvider providerRemoveConfig
*/
public function testRemoveConfig(array $config): void {
$this->processRunner
->runExecutable('composer', array_merge([
'config',
'--unset',
], $config), self::FIXTURE_PATH)
->shouldBeCalledOnce();

$composer = $this->createComposer();
$composer->removeConfig($config);
}

public function testRemoveConfigEmptyArray(): void {
$this->expectException(\InvalidArgumentException::class);

$composer = $this->createComposer();
$composer->removeConfig([]);
}

public function providerRemoveConfig(): array {
return [
[['platform']],
];
}

/**
* @dataProvider providerPackageList
*/
Expand Down