Skip to content
Snippets Groups Projects
Commit 842998e3 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3336247 by tedbow, yash.rode, Wim Leers: Throw an exception if...

Issue #3336247 by tedbow, yash.rode, Wim Leers: Throw an exception if stopPropagation() called for `PreOperationStageEvent` and no error has been added
parent 2f247c73
No related branches found
No related tags found
1 merge request!674Issue #3336247: Throw an exception if stopPropagation() called for `PreOperationStageEvent` and no error has been added
......@@ -6,6 +6,7 @@ namespace Drupal\package_manager\Event;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\package_manager\ValidationResult;
use Drupal\system\SystemManager;
/**
* Base class for events dispatched before a stage life cycle operation.
......@@ -63,4 +64,14 @@ abstract class PreOperationStageEvent extends StageEvent {
$this->results[] = ValidationResult::createErrorFromThrowable($throwable, $summary);
}
/**
* {@inheritdoc}
*/
public function stopPropagation(): void {
if (empty($this->getResults(SystemManager::REQUIREMENT_ERROR))) {
$this->addErrorFromThrowable(new \LogicException('Event propagation stopped without any errors added to the event. This bypasses the package_manager validation system.'));
}
parent::stopPropagation();
}
}
......@@ -194,4 +194,19 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
(new PreApplyEvent($stage))->excludePath('/junk/drawer');
}
/**
* Tests exception is thrown if error is not added before stopPropagation().
*/
public function testExceptionIfNoErrorBeforeStopPropagation(): void {
$listener = function (PreCreateEvent $event): void {
$event->stopPropagation();
};
$this->addEventTestListener($listener, PreCreateEvent::class);
$this->expectException(TestStageValidationException::class);
$this->expectExceptionMessage('Event propagation stopped without any errors added to the event. This bypasses the package_manager validation system.');
$stage = $this->createStage();
$stage->create();
}
}
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