diff --git a/src/TaskRunner/AbstractCommands.php b/src/TaskRunner/AbstractCommands.php index fbb9ab25a..e153a192b 100644 --- a/src/TaskRunner/AbstractCommands.php +++ b/src/TaskRunner/AbstractCommands.php @@ -128,4 +128,28 @@ public function getWorkingDir(): string return (string) $this->input->getParameterOption('--working-dir', getcwd()); } + /** + * Returns the composer.json parsed content. + */ + public function getComposerJson(): array + { + $file = $this->getWorkingDir() . '/composer.json'; + if (!file_exists($file)) { + throw new \Exception("The '$file' was not found."); + } + return (array) json_decode(file_get_contents($file), true); + } + + /** + * Returns the composer.lock parsed content. + */ + public function getComposerLock(): array + { + $file = $this->getWorkingDir() . '/composer.lock'; + if (!file_exists($file)) { + throw new \Exception("The '$file' was not found."); + } + return (array) json_decode(file_get_contents($file), true); + } + } diff --git a/src/TaskRunner/Commands/ComponentCheckCommands.php b/src/TaskRunner/Commands/ComponentCheckCommands.php index b6981bcd9..1987b4ec9 100644 --- a/src/TaskRunner/Commands/ComponentCheckCommands.php +++ b/src/TaskRunner/Commands/ComponentCheckCommands.php @@ -20,7 +20,7 @@ */ class ComponentCheckCommands extends AbstractCommands { - protected bool $commandFailed = false; + protected bool $evaluationFailed = false; protected bool $mandatoryFailed = false; protected bool $recommendedFailed = false; protected bool $insecureFailed = false; @@ -37,6 +37,8 @@ class ComponentCheckCommands extends AbstractCommands protected int $recommendedFailedCount = 0; protected array $installed; protected $io; + protected array $composerLock; + protected array $packageReviews; /** * Check composer for components that are not whitelisted/blacklisted. @@ -48,7 +50,6 @@ class ComponentCheckCommands extends AbstractCommands * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function componentCheck(ConsoleIO $io, array $options = [ 'endpoint' => InputOption::VALUE_REQUIRED, @@ -64,25 +65,24 @@ public function componentCheck(ConsoleIO $io, array $options = [ $this->io = $io; $this->prepareSkips(); - $composerLock = file_exists('composer.lock') ? json_decode(file_get_contents('composer.lock'), true) : false; - if (!isset($composerLock['packages'])) { + $this->composerLock = $this->getComposerLock(); + if (!isset($this->composerLock['packages'])) { $io->error('No packages found in the composer.lock file.'); return 1; } - $status = 0; $data = Website::packages(); if (empty($data)) { $io->error('Failed to connect to the endpoint ' . Website::url() . '/api/v1/package-reviews'); return 1; } - $modules = array_filter(array_combine(array_column($data, 'name'), $data)); + $this->packageReviews = array_filter(array_combine(array_column($data, 'name'), $data)); // To test this command execute it with the --test-command option: // ./vendor/bin/run toolkit:component-check --test-command --endpoint="https://digit-dqa.fpfis.tech.ec.europa.eu" // Then we provide an array in the packages that fails on each type of validation. if ($options['test-command']) { - $composerLock['packages'] = $this->testPackages(); + $this->composerLock['packages'] = $this->testPackages(); } // Execute all checks. @@ -93,56 +93,23 @@ public function componentCheck(ConsoleIO $io, array $options = [ 'Outdated', 'Abandoned', 'Unsupported', + 'Evaluation', + 'Development', + 'Composer', ]; foreach ($checks as $check) { $io->title("Checking $check components."); $fct = "component$check"; - $this->{$fct}($modules, $composerLock['packages']); + $this->{$fct}(); $io->newLine(); } - // Get vendor list. - $dataTkReqsEndpoint = Website::requirements(); - $vendorList = $dataTkReqsEndpoint['vendor_list'] ?? []; - - $io->title('Checking evaluation status components.'); - // Proceed with 'blocker' option. Loop over the packages. - foreach ($composerLock['packages'] as $package) { - // Check if vendor belongs to the monitored vendor list. - if (in_array(explode('/', $package['name'])['0'], $vendorList)) { - $this->validateComponent($package, $modules); - } - } - if ($this->commandFailed === false) { - $this->say('Evaluation module check passed.'); - } - $io->newLine(); - - $io->title('Checking dev components in require section.'); - $devPackages = array_filter( - array_column($modules, 'dev_component', 'name'), - function ($value) { - return $value == 'true'; - } - ); - foreach ($devPackages as $packageName => $package) { - if (ToolCommands::getPackagePropertyFromComposer($packageName, 'version', 'packages')) { - $this->devCompRequireFailed = true; - $io->warning("Package $packageName cannot be used on require section, must be on require-dev section."); - } - } - if (!$this->devCompRequireFailed) { - $this->say('Dev components in require section check passed'); - } - $io->newLine(); - - $this->validateComposer($composerLock['packages']); - $this->printComponentResults($io); // If the validation fail, return according to the blocker. + $status = 0; if ( - $this->commandFailed || + $this->evaluationFailed || $this->mandatoryFailed || $this->devCompRequireFailed || $this->composerFailed || @@ -207,18 +174,15 @@ protected function prepareSkips(): void /** * Validate composer packages. * - * @param array $packages - * The packages to validate. - * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function validateComposer(array $packages) + protected function componentComposer() { - $this->io->title('Validating composer.'); + $composerJson = $this->getComposerJson(); // Check packages used in dev version. - foreach ($packages as $package) { + foreach ($this->composerLock['packages'] as $package) { $typeBypass = in_array($package['type'], [ 'drupal-custom-module', 'drupal-custom-theme', @@ -229,37 +193,35 @@ protected function validateComposer(array $packages) $this->writeln("Package {$package['name']}:{$package['version']} cannot be used in dev version."); } } - $composer = $this->getWorkingDir() . '/composer.json'; - if (file_exists($composer)) { - $composerArray = json_decode(file_get_contents($composer), true); - // Do not allow setting enable-patching. - if (!empty($composerArray['extra']['enable-patching'])) { - $this->composerFailed = true; - $this->writeln("The composer property 'extras.enable-patching' cannot be set to true."); - } - // Enforce setting composer-exit-on-patch-failure. - if (empty($composerArray['extra']['composer-exit-on-patch-failure'])) { - $this->composerFailed = true; - $this->writeln("The composer property 'extras.composer-exit-on-patch-failure' must be set to true."); - } - // Do not allow remote patches. Check if patches from drupal.org are allowed. - if (!empty($composerArray['extra']['patches'])) { - $allowDOrgPatches = !empty($this->getConfig()->get('toolkit.components.composer.drupal_patches')); - foreach ($composerArray['extra']['patches'] as $packagePatches) { - foreach ($packagePatches as $patch) { - $hostname = parse_url($patch, PHP_URL_HOST); - $isDOrg = str_ends_with($hostname ?? '', 'drupal.org'); - if ($hostname && (!$allowDOrgPatches || !$isDOrg)) { - $this->writeln("The patch '$patch' is not valid."); - $this->composerFailed = true; - } + // Do not allow setting enable-patching. + if (!empty($composerJson['extra']['enable-patching'])) { + $this->composerFailed = true; + $this->writeln("The composer property 'extra.enable-patching' cannot be set to true."); + } + + // Enforce setting composer-exit-on-patch-failure. + if (empty($composerJson['extra']['composer-exit-on-patch-failure'])) { + $this->composerFailed = true; + $this->writeln("The composer property 'extra.composer-exit-on-patch-failure' must be set to true."); + } + + // Do not allow remote patches. Check if patches from drupal.org are allowed. + if (!empty($composerJson['extra']['patches'])) { + $allowDOrgPatches = !empty($this->getConfig()->get('toolkit.components.composer.drupal_patches')); + foreach ($composerJson['extra']['patches'] as $packagePatches) { + foreach ($packagePatches as $patch) { + $hostname = parse_url($patch, PHP_URL_HOST); + $isDOrg = str_ends_with($hostname ?? '', 'drupal.org'); + if ($hostname && (!$allowDOrgPatches || !$isDOrg)) { + $this->writeln("The patch '$patch' is not valid."); + $this->composerFailed = true; } } } } if (!$this->composerFailed) { - $this->say('Composer validation passed.'); + $this->say('Composer validation check passed.'); } $this->io->newLine(); } @@ -283,8 +245,8 @@ protected function printComponentResults(ConsoleIO $io) ['Outdated module check' => $this->getFailedOrPassed($this->outdatedFailed) . $skipOutdated], ['Abandoned module check' => $this->getFailedOrPassed($this->abandonedFailed) . $skipAbandoned], ['Unsupported module check' => $this->getFailedOrPassed($this->unsupportedFailed) . $skipUnsupported], - ['Evaluation module check' => $this->getFailedOrPassed($this->commandFailed)], - ['Dev module in require-dev check' => $this->getFailedOrPassed($this->devCompRequireFailed)], + ['Evaluation module check' => $this->getFailedOrPassed($this->evaluationFailed)], + ['Development module check' => $this->getFailedOrPassed($this->devCompRequireFailed)], ['Composer validation check' => $this->getFailedOrPassed($this->composerFailed)], ); } @@ -293,12 +255,11 @@ protected function printComponentResults(ConsoleIO $io) * Helper function to validate the component. * * @param array $package The package to validate. - * @param array $modules The modules list. * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function validateComponent(array $package, array $modules) + protected function validateComponent(array $package) { // Ignore if the package is a metapackage. if ($package['type'] === 'metapackage') { @@ -310,6 +271,7 @@ protected function validateComponent(array $package, array $modules) return; } $config = $this->getConfig(); + $modules = $this->packageReviews; $packageName = $package['name']; $hasBeenQaEd = isset($modules[$packageName]); $wasRejected = isset($modules[$packageName]['restricted_use']) && $modules[$packageName]['restricted_use'] !== '0'; @@ -324,7 +286,7 @@ protected function validateComponent(array $package, array $modules) // If module was not reviewed yet. if (!$hasBeenQaEd) { $this->writeln("Package $packageName:$packageVersion has not been reviewed by QA."); - $this->commandFailed = true; + $this->evaluationFailed = true; } // If module was rejected. @@ -332,6 +294,9 @@ protected function validateComponent(array $package, array $modules) $projectId = $config->get('toolkit.project_id'); // Check if the module is allowed for this project id. $allowedInProject = in_array($projectId, array_map('trim', explode(',', $modules[$packageName]['restricted_use']))); + if ($allowedInProject) { + $this->writeln("The package $packageName is authorised for the project $projectId"); + } // Check if the module is allowed for this type of project. if (!$allowedInProject && !empty($allowedProjectTypes)) { @@ -339,6 +304,7 @@ protected function validateComponent(array $package, array $modules) // Load the project from the website. $project = Website::projectInformation($projectId); if (in_array($project['type'], $allowedProjectTypes)) { + $this->writeln("The package $packageName is authorised for the type of project {$project['type']}"); $allowedInProject = true; } } @@ -349,6 +315,7 @@ protected function validateComponent(array $package, array $modules) // Load the project from the website. $project = Website::projectInformation($projectId); if (in_array($project['profile'], $allowedProfiles)) { + $this->writeln("The package $packageName is authorised for the profile {$project['profile']}"); $allowedInProject = true; } } @@ -356,7 +323,7 @@ protected function validateComponent(array $package, array $modules) // If module was not allowed in project. if (!$allowedInProject) { $this->writeln("The use of $packageName:$packageVersion is {$modules[$packageName]['status']}. Contact QA Team."); - $this->commandFailed = true; + $this->evaluationFailed = true; } } @@ -366,7 +333,7 @@ protected function validateComponent(array $package, array $modules) $constraintValue = !empty($modules[$packageName][$constraint]) ? $modules[$packageName][$constraint] : null; if (!is_null($constraintValue) && Semver::satisfies($packageVersion, $constraintValue) === $result) { $this->writeln("Package $packageName:$packageVersion does not meet the $constraint version constraint: $constraintValue."); - $this->commandFailed = true; + $this->evaluationFailed = true; } } } @@ -374,12 +341,8 @@ protected function validateComponent(array $package, array $modules) /** * Helper function to check component's review information. - * - * @param array $modules The modules list. - * - * @throws \Robo\Exception\TaskException */ - protected function componentMandatory(array $modules) + protected function componentMandatory() { $enabledPackages = $mandatoryPackages = []; $drushBin = $this->getBin('drush'); @@ -414,8 +377,8 @@ protected function componentMandatory(array $modules) } // Get mandatory packages. - if (!empty($modules)) { - $mandatoryPackages = array_values(array_filter($modules, function ($item) { + if (!empty($this->packageReviews)) { + $mandatoryPackages = array_values(array_filter($this->packageReviews, function ($item) { return $item['mandatory'] === '1'; })); } @@ -437,18 +400,15 @@ protected function componentMandatory(array $modules) /** * Helper function to check component's review information. - * - * @param array $modules The modules list. - * @param array $packages The packages to validate. */ - protected function componentRecommended(array $modules, array $packages) + protected function componentRecommended() { $recommendedPackages = []; // Get project packages. - $projectPackages = array_column($packages, 'name'); + $projectPackages = array_column($this->composerLock['packages'], 'name'); // Get recommended packages. - if (!empty($modules)) { - $recommendedPackages = array_values(array_filter($modules, function ($item) { + if (!empty($this->packageReviews)) { + $recommendedPackages = array_values(array_filter($this->packageReviews, function ($item) { return strtolower($item['usage']) === 'recommended'; })); } @@ -474,14 +434,12 @@ protected function componentRecommended(array $modules, array $packages) /** * Helper function to check component's review information. * - * @param array $modules The modules list. - * * @throws \Robo\Exception\TaskException * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function componentInsecure(array $modules) + protected function componentInsecure() { $packages = []; $drupalReleaseHistory = new DrupalReleaseHistory(); @@ -521,8 +479,8 @@ protected function componentInsecure(array $modules) $messages = []; foreach ($packages as $name => $package) { $msg = "Package $name has a security update, please update to a safe version. (" . $package['title'] . ")"; - if (!empty($modules[$name]['secure'])) { - if (Semver::satisfies($package['version'], $modules[$name]['secure'])) { + if (!empty($this->packageReviews[$name]['secure'])) { + if (Semver::satisfies($package['version'], $this->packageReviews[$name]['secure'])) { $messages[] = "$msg (Version marked as secure)"; continue; } @@ -663,6 +621,51 @@ protected function componentUnsupported() } } + /** + * Helper function to check Evaluation components. + */ + protected function componentEvaluation() + { + // Get vendor list. + $dataTkReqsEndpoint = Website::requirements(); + $vendorList = $dataTkReqsEndpoint['vendor_list'] ?? []; + + // Proceed with 'blocker' option. Loop over the packages. + foreach ($this->composerLock['packages'] as $package) { + // Check if vendor belongs to the monitored vendor list. + if (in_array(explode('/', $package['name'])['0'], $vendorList)) { + $this->validateComponent($package); + } + } + if ($this->evaluationFailed === false) { + $this->say('Evaluation module check passed.'); + } + $this->io->newLine(); + } + + /** + * Helper function to check Development components. + */ + protected function componentDevelopment() + { + $devPackages = array_filter( + array_column($this->packageReviews, 'dev_component', 'name'), + function ($value) { + return $value == 'true'; + } + ); + foreach (array_keys($devPackages) as $packageName) { + if (ToolCommands::getPackagePropertyFromComposer($packageName, 'version', 'packages')) { + $this->devCompRequireFailed = true; + $this->io->warning("Package $packageName cannot be used on require section, must be on require-dev section."); + } + } + if (!$this->devCompRequireFailed) { + $this->say('Development components check passed.'); + } + $this->io->newLine(); + } + /** * Returns a list of packages to test. * diff --git a/src/TaskRunner/Commands/PatchCommands.php b/src/TaskRunner/Commands/PatchCommands.php index af702aa84..2aaa87e1b 100644 --- a/src/TaskRunner/Commands/PatchCommands.php +++ b/src/TaskRunner/Commands/PatchCommands.php @@ -96,26 +96,12 @@ public function toolkitPatchDownload(ConsoleIO $io, array $options = [ return $this->collectionBuilder()->addTaskList($tasks); } - /** - * Returns the composer.json content. - */ - private function getComposer() - { - $composer = $this->input()->getOption('composer'); - $file = $this->getWorkingDir() . '/' . trim($composer, '/'); - if (!file_exists($file)) { - $this->writeln("The file '$file' not found."); - return ResultData::EXITCODE_OK; - } - return json_decode(file_get_contents($file), true); - } - /** * Returns the patches to be downloaded. */ private function getPatches(): array { - $composer = $this->getComposer(); + $composer = $this->getComposerJson(); $patches = $composer['extra']['patches'] ?? []; // Check if there's any patch. if (empty($patches)) { diff --git a/src/TaskRunner/Commands/SymlinkProjectCommands.php b/src/TaskRunner/Commands/SymlinkProjectCommands.php index 85ec9e5b1..2fd4e49e7 100644 --- a/src/TaskRunner/Commands/SymlinkProjectCommands.php +++ b/src/TaskRunner/Commands/SymlinkProjectCommands.php @@ -40,7 +40,7 @@ public function getConfigurationFile() */ public function symlinkProjectValidate(): void { - $composer = $this->getComposer(); + $composer = $this->getComposerJson(); // Check if the project name is present. if (empty($composer['name'])) { throw new \Exception('Could not find the project name in the composer.json file.'); @@ -77,7 +77,7 @@ public function symlinkProject(array $options = [ { Toolkit::ensureArray($options['ignore']); $workingDir = $this->getConfig()->get('runner.working_dir'); - $composer = $this->getComposer(); + $composer = $this->getComposerJson(); $projectId = explode('/', $composer['name'])[1]; $projectType = $this->types[$composer['type']]; $destination = $workingDir . '/' . $options['root'] . '/' . $projectType . '/' . $projectId; @@ -97,15 +97,6 @@ public function symlinkProject(array $options = [ return $this->collectionBuilder()->addTask($task); } - private function getComposer() - { - $composer = $this->getWorkingDir() . '/composer.json'; - if (!file_exists($composer)) { - throw new \Exception("The $composer was not found."); - } - return json_decode(file_get_contents($composer), true); - } - private function scanDir(string $directory, array $ignore = []): array { $ignore = array_merge(['.', '..', '.git'], $ignore); diff --git a/src/TaskRunner/Commands/TestsCommands.php b/src/TaskRunner/Commands/TestsCommands.php index 20876f140..35e9e15cc 100644 --- a/src/TaskRunner/Commands/TestsCommands.php +++ b/src/TaskRunner/Commands/TestsCommands.php @@ -209,14 +209,11 @@ protected function toolkitRunGrumphp() } } - $composerFile = './composer.json'; - if (file_exists($composerFile)) { - $composerArray = json_decode(file_get_contents($composerFile), true); - if (isset($composerArray['extra']['grumphp']['config-default-path'])) { - $configDefaultPath = $composerArray['extra']['grumphp']['config-default-path']; - $this->say('You should remove the following from your composer.json extra array:'); - echo "\n\"grumphp\": {\n \"config-default-path\": \"$configDefaultPath\"\n}\n\n"; - } + $composer = $this->getComposerJson(); + if (isset($composer['extra']['grumphp']['config-default-path'])) { + $configDefaultPath = $composer['extra']['grumphp']['config-default-path']; + $this->say('You should remove the following from your composer.json extra array:'); + echo "\n\"grumphp\": {\n \"config-default-path\": \"$configDefaultPath\"\n}\n\n"; } if ($containsQaConventions) { diff --git a/tests/fixtures/commands/component-check.yml b/tests/fixtures/commands/component-check.yml index a9dbe2722..9f221719c 100644 --- a/tests/fixtures/commands/component-check.yml +++ b/tests/fixtures/commands/component-check.yml @@ -4,6 +4,9 @@ resources: - from: sample-composer.lock to: composer.lock + - file: composer.json + content: | + { "name": "ec-europa/toolkit", "extra": { "composer-exit-on-patch-failure": true } } expectations: - contains: | Checking Mandatory components. @@ -44,38 +47,41 @@ [Simulator] Running ./vendor/bin/drush eval "\Drupal::moduleHandler()->loadInclude('update', 'compare.inc') ; echo json_encode(update_calculate_project_data(\Drupal::keyValueExpirable('update_available_releases')->getAll()))" Failed to get the available releases. - Checking evaluation status components. - ====================================== + Checking Evaluation components. + =============================== The use of drupal/codesnippet:1.8 is restricted. Contact QA Team. The use of drupal/github_connect:2.0.0-alpha1 is restricted. Contact QA Team. The use of drupal/responsive_tables_filter:1.17 is restricted. Contact QA Team. The use of drupal/restui:1.21 is rejected. Contact QA Team. - Checking dev components in require section. - =========================================== - > Dev components in require section check passed + Checking Development components. + ================================ + + > Development components check passed. + - Validating composer. - ==================== + Checking Composer components. + ============================= + + > Composer validation check passed. - > Composer validation passed. Results: ======== - --------------------------------- -------- - Mandatory module check failed - Recommended module check passed - Insecure module check passed - Outdated module check passed - Abandoned module check passed - Unsupported module check passed - Evaluation module check failed - Dev module in require-dev check passed - Composer validation check passed - --------------------------------- -------- + --------------------------- -------- + Mandatory module check failed + Recommended module check passed + Insecure module check passed + Outdated module check passed + Abandoned module check passed + Unsupported module check passed + Evaluation module check failed + Development module check passed + Composer validation check passed + --------------------------- -------- [ERROR] Failed the components check, please verify the report and update the project. @@ -124,12 +130,13 @@ check: false tokens: '' resources: + - touch: composer.json - from: sample-composer.lock to: composer.lock expectations: - - string_contains: Abandoned module check passed (Skipping) - - string_contains: Outdated module check passed (Skipping) - - string_contains: Unsupported module check passed (Skipping) + - string_contains: Abandoned module check passed (Skipping) + - string_contains: Outdated module check passed (Skipping) + - string_contains: Unsupported module check passed (Skipping) - command: 'toolkit:component-check --test-command' configuration: @@ -139,11 +146,12 @@ check: false tokens: '[skip_insecure][skip_d9c]' resources: + - touch: composer.json - from: sample-composer.lock to: composer.lock expectations: - - string_contains: Insecure module check passed (Skipping) - - string_contains: Outdated module check passed (Skipping) + - string_contains: Insecure module check passed (Skipping) + - string_contains: Outdated module check passed (Skipping) - command: 'toolkit:component-check' configuration: @@ -154,32 +162,39 @@ resources: - from: sample-core.extensions-good.yml to: core.extensions-good.yml + - file: composer.json + content: | + { "name": "ec-europa/toolkit", "extra": { "composer-exit-on-patch-failure": true } } - from: sample-composer.lock to: composer.lock expectations: - - string_contains: Mandatory module check passed - - string_contains: Recommended module check passed - - string_contains: Insecure module check passed - - string_contains: Outdated module check passed - - string_contains: Abandoned module check passed - - string_contains: Unsupported module check passed - - string_contains: Evaluation module check failed - - string_contains: Dev module in require-dev check passed - - string_contains: Composer validation check passed + - string_contains: Mandatory module check passed + - string_contains: Recommended module check passed + - string_contains: Insecure module check passed + - string_contains: Outdated module check passed + - string_contains: Abandoned module check passed + - string_contains: Unsupported module check passed + - string_contains: Evaluation module check failed + - string_contains: Development module check passed + - string_contains: Composer validation check passed - command: 'toolkit:component-check' configuration: [ ] tokens: '' resources: + - touch: composer.json - from: sample-internal-dependency.lock to: composer.lock expectations: - - string_contains: Evaluation module check passed + - string_contains: Evaluation module check passed - command: 'toolkit:component-check' configuration: [ ] tokens: '' resources: + - file: composer.json + content: | + { "name": "ec-europa/toolkit", "extra": { "composer-exit-on-patch-failure": true } } - file: composer.lock content: | { "packages": [ @@ -191,7 +206,7 @@ - string_contains: Package test/package:dev-1.0.0 cannot be used in dev version. - string_contains: Package test/package2:1.0.0-dev cannot be used in dev version. - not_string_contains: Package test/module:1.0.0-dev cannot be used in dev version. - - string_contains: Composer validation check failed + - string_contains: Composer validation check failed - command: 'toolkit:component-check' configuration: [ ] @@ -204,8 +219,8 @@ content: | { "packages": [ { "name": "test/package", "type": "library", "version": "1.0.0" } ] } expectations: - - string_contains: The composer property 'extras.enable-patching' cannot be set to true. - - string_contains: Composer validation check failed + - string_contains: The composer property 'extra.enable-patching' cannot be set to true. + - string_contains: Composer validation check failed - command: 'toolkit:component-check' configuration: [ ] @@ -218,8 +233,8 @@ content: | { "packages": [ { "name": "test/package", "type": "library", "version": "1.0.0" } ] } expectations: - - not_string_contains: extras.enable-patching - - string_contains: Composer validation check passed + - not_string_contains: extra.enable-patching + - string_contains: Composer validation check passed - command: 'toolkit:component-check' configuration: [ ] @@ -232,8 +247,8 @@ content: | { "packages": [ { "name": "test/package", "type": "library", "version": "1.0.0" } ] } expectations: - - string_contains: The composer property 'extras.composer-exit-on-patch-failure' must be set to true. - - string_contains: Composer validation check failed + - string_contains: The composer property 'extra.composer-exit-on-patch-failure' must be set to true. + - string_contains: Composer validation check failed - command: 'toolkit:component-check' configuration: [ ] @@ -246,8 +261,8 @@ content: | { "packages": [ { "name": "test/package", "type": "library", "version": "1.0.0" } ] } expectations: - - not_string_contains: extras.composer-exit-on-patch-failure - - string_contains: Composer validation check passed + - not_string_contains: extra.composer-exit-on-patch-failure + - string_contains: Composer validation check passed - command: 'toolkit:component-check' configuration: @@ -281,7 +296,7 @@ - not_string_contains: The patch 'https://www.drupal.org/files/issues/2023-01-01/12345-1.patch' is not valid - not_string_contains: The patch 'https://drupal.org/files/issues/2023-01-01/12345-2.patch' is not valid - not_string_contains: The patch 'http://drupal.org/files/issues/2023-01-01/12345-3.patch' is not valid - - string_contains: Composer validation check passed + - string_contains: Composer validation check passed - command: 'toolkit:component-check' configuration: @@ -317,4 +332,99 @@ - string_contains: The patch 'https://www.drupal.org/files/issues/2023-01-01/12345-1.patch' is not valid - string_contains: The patch 'https://drupal.org/files/issues/2023-01-01/12345-2.patch' is not valid - string_contains: The patch 'http://drupal.org/files/issues/2023-01-01/12345-3.patch' is not valid - - string_contains: Composer validation check failed + - string_contains: Composer validation check failed + +- command: 'toolkit:component-check' + configuration: + toolkit: + project_id: digit-dqa + tokens: '' + resources: + - touch: composer.json + - file: composer.lock + content: | + { "packages": [ { "name": "drupal/codesnippet", "type": "drupal-module", "version": "1.0.0" } ] } + expectations: + - string_contains: The package drupal/codesnippet is authorised for the project digit-dqa + +- command: 'toolkit:component-check' + configuration: [ ] + tokens: '' + resources: + - touch: composer.json + - file: composer.lock + content: | + { "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] } + - file: .toolkit-mock/0.0.2/api/v1/project/ec-europa/toolkit/information.json + content: | + [ { "type": "Drupal 9" ,"profile": "minimal" } ] + - file: .toolkit-mock/0.0.2/api/v1/toolkit-requirements.json + content: | + { "php_version":"8.0", "toolkit": "^3.7.2|^9.11|^10.1", "drupal": "^7.96|^9.5.8|^10.0.9", "vendor_list": [ "drupal" ] } + - file: .toolkit-mock/0.0.2/api/v1/package-reviews.json + content: | + [ { + "type": "drupal-module", + "machine_name": "pipeline", + "name": "drupal/pipeline", + "full_name": "drupal/pipeline", + "version_drupal": "8.x-1.0-alpha3", + "version": "^1.0-alpha3", + "whitelist": "^1.0-alpha3", + "blacklist": false, + "secure": false, + "status": "rejected", + "restricted_use": "1", + "allowed_profiles": "minimal", + "allowed_project_types": "Drupal 9", + "mandatory": "0", + "mandatory_date": false, + "core": "8.x", + "cores": "8.x", + "usage": "Free", + "nid": "10889", + "dev_component": "false" + } ] + expectations: + - string_contains: The package drupal/pipeline is authorised for the type of project Drupal 9 + +- command: 'toolkit:component-check' + configuration: [ ] + tokens: '' + resources: + - touch: composer.json + - file: composer.lock + content: | + { "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] } + - file: .toolkit-mock/0.0.2/api/v1/project/ec-europa/toolkit/information.json + content: | + [ { "type": "Drupal 9" ,"profile": "minimal" } ] + - file: .toolkit-mock/0.0.2/api/v1/toolkit-requirements.json + content: | + { "php_version":"8.0", "toolkit": "^3.7.2|^9.11|^10.1", "drupal": "^7.96|^9.5.8|^10.0.9", "vendor_list": [ "drupal" ] } + - file: .toolkit-mock/0.0.2/api/v1/package-reviews.json + content: | + [ { + "type": "drupal-module", + "machine_name": "pipeline", + "name": "drupal/pipeline", + "full_name": "drupal/pipeline", + "version_drupal": "8.x-1.0-alpha3", + "version": "^1.0-alpha3", + "whitelist": "^1.0-alpha3", + "blacklist": false, + "secure": false, + "status": "rejected", + "restricted_use": "1", + "allowed_profiles": "minimal", + "allowed_project_types": false, + "mandatory": "0", + "mandatory_date": false, + "core": "8.x", + "cores": "8.x", + "usage": "Free", + "nid": "10889", + "dev_component": "false" + } ] + expectations: + - string_contains: The package drupal/pipeline is authorised for the profile minimal diff --git a/tests/fixtures/commands/drupal-symlink-project.yml b/tests/fixtures/commands/drupal-symlink-project.yml index 02f7a296e..ee550c37e 100644 --- a/tests/fixtures/commands/drupal-symlink-project.yml +++ b/tests/fixtures/commands/drupal-symlink-project.yml @@ -2,7 +2,7 @@ configuration: [] resources: [] expectations: - - contains: '[error] The /test/toolkit/tests/sandbox/SymlinkProjectCommandsTest/composer.json was not found.' + - contains: "[error] The '/test/toolkit/tests/sandbox/SymlinkProjectCommandsTest/composer.json' was not found." - command: 'drupal:symlink-project' configuration: diff --git a/tests/fixtures/commands/patch.yml b/tests/fixtures/commands/patch.yml index e65fa4afc..400babdbe 100644 --- a/tests/fixtures/commands/patch.yml +++ b/tests/fixtures/commands/patch.yml @@ -2,8 +2,7 @@ configuration: [] resources: [] expectations: - - string_contains: The section 'extra.patches' is empty. - - string_contains: Nothing to download. + - contains: "[error] The '/test/toolkit/tests/sandbox/PatchCommandsTest/composer.json' was not found." - command: 'toolkit:patch-download' configuration: []