Skip to content
Snippets Groups Projects
Commit 955794b1 authored by omkar podey's avatar omkar podey Committed by Ted Bowman
Browse files

Issue #3330140 by omkar.podey, tedbow, Wim Leers: Update...

Issue #3330140 by omkar.podey, tedbow, Wim Leers: Update StatusCheckTrait::runStatusCheck() to reorder/avoid dispatching CollectIgnoredPathsEvent earlier than StatusCheckEvent
parent 338cac97
Branches 8.x-1.x
Tags 2.0.0-beta1 8.x-1.0-beta1
1 merge request!654Issue #3330140: Update StatusCheckTrait::runStatusCheck to reorder/avoid dispatching CollectIgnoredPathsEvent earlier than StatusCheckEvent
...@@ -36,9 +36,14 @@ trait StatusCheckTrait { ...@@ -36,9 +36,14 @@ trait StatusCheckTrait {
*/ */
protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL, bool $do_readiness_check = FALSE): array { protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL, bool $do_readiness_check = FALSE): array {
$event_dispatcher ??= \Drupal::service('event_dispatcher'); $event_dispatcher ??= \Drupal::service('event_dispatcher');
try {
$ignored_paths = new CollectIgnoredPathsEvent($stage); $ignored_paths = new CollectIgnoredPathsEvent($stage);
$event_dispatcher->dispatch($ignored_paths); $event_dispatcher->dispatch($ignored_paths);
}
catch (\Exception $e) {
// We can't dispatch the status check event without the ignored paths.
return [ValidationResult::createErrorFromThrowable($e, t("Unable to collect ignored paths, therefore can't perform status checks."))];
}
$event = new StatusCheckEvent($stage, $ignored_paths->getAll()); $event = new StatusCheckEvent($stage, $ignored_paths->getAll());
$event_dispatcher->dispatch($event); $event_dispatcher->dispatch($event);
......
...@@ -7,6 +7,7 @@ namespace Drupal\Tests\package_manager\Kernel; ...@@ -7,6 +7,7 @@ namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\Event\CollectIgnoredPathsEvent; use Drupal\package_manager\Event\CollectIgnoredPathsEvent;
use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\StatusCheckTrait; use Drupal\package_manager\StatusCheckTrait;
use Drupal\package_manager\ValidationResult;
/** /**
* @covers \Drupal\package_manager\StatusCheckTrait * @covers \Drupal\package_manager\StatusCheckTrait
...@@ -34,4 +35,25 @@ class StatusCheckTraitTest extends PackageManagerKernelTestBase { ...@@ -34,4 +35,25 @@ class StatusCheckTraitTest extends PackageManagerKernelTestBase {
$this->assertTrue($status_check_called); $this->assertTrue($status_check_called);
} }
/**
* Tests StatusCheckTrait returns an error when unable to get ignored paths.
*/
public function testErrorIgnoredPathsCollected(): void {
$composer_json_path = $this->container->get('package_manager.path_locator')->getProjectRoot() . '/composer.json';
// Delete composer.json, so we won't be able to get excluded paths.
unlink($composer_json_path);
$this->addEventTestListener(function (CollectIgnoredPathsEvent $event): void {
// Try to get composer.
$event->getStage()->getActiveComposer();
}, CollectIgnoredPathsEvent::class);
$results = $this->runStatusCheck($this->createStage(), $this->container->get('event_dispatcher'));
$expected_results = [
ValidationResult::createErrorFromThrowable(
new \Exception("Composer could not find the config file: $composer_json_path\n"),
t("Unable to collect ignored paths, therefore can't perform status checks."),
),
];
$this->assertValidationResultsEqual($expected_results, $results);
}
} }
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