Skip to content
Snippets Groups Projects
Commit 4b1e77b4 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3246194 by phenaproxima: All of Package Manager's events should carry a...

Issue #3246194 by phenaproxima: All of Package Manager's events should carry a reference to the stage
parent e568c5f7
No related branches found
No related tags found
1 merge request!95Issue #3246194: All of Package Manager's events should carry a reference to the stage
......@@ -2,6 +2,7 @@
namespace Drupal\package_manager\Event;
use Drupal\package_manager\Stage;
use Drupal\package_manager\ValidationResult;
use Symfony\Contracts\EventDispatcher\Event;
......@@ -17,6 +18,33 @@ abstract class StageEvent extends Event {
*/
protected $results = [];
/**
* The stage which fired this event.
*
* @var \Drupal\package_manager\Stage
*/
protected $stage;
/**
* Constructs a StageEvent object.
*
* @param \Drupal\package_manager\Stage $stage
* The stage which fired this event.
*/
public function __construct(Stage $stage) {
$this->stage = $stage;
}
/**
* Returns the stage which fired this event.
*
* @return \Drupal\package_manager\Stage
* The stage which fired this event.
*/
public function getStage(): Stage {
return $this->stage;
}
/**
* Gets the validation results.
*
......
......@@ -102,11 +102,11 @@ class Stage {
$active_dir = $this->pathLocator->getActiveDirectory();
$stage_dir = $this->pathLocator->getStageDirectory();
$event = new PreCreateEvent();
$event = new PreCreateEvent($this);
$this->dispatch($event);
$this->beginner->begin($active_dir, $stage_dir, $event->getExcludedPaths());
$this->dispatch(new PostCreateEvent());
$this->dispatch(new PostCreateEvent($this));
}
/**
......@@ -119,9 +119,9 @@ class Stage {
$command = array_merge(['require'], $constraints);
$command[] = '--update-with-all-dependencies';
$this->dispatch(new PreRequireEvent());
$this->dispatch(new PreRequireEvent($this));
$this->stager->stage($command, $this->pathLocator->getStageDirectory());
$this->dispatch(new PostRequireEvent());
$this->dispatch(new PostRequireEvent($this));
}
/**
......@@ -131,23 +131,23 @@ class Stage {
$active_dir = $this->pathLocator->getActiveDirectory();
$stage_dir = $this->pathLocator->getStageDirectory();
$event = new PreApplyEvent();
$event = new PreApplyEvent($this);
$this->dispatch($event);
$this->committer->commit($stage_dir, $active_dir, $event->getExcludedPaths());
$this->dispatch(new PostApplyEvent());
$this->dispatch(new PostApplyEvent($this));
}
/**
* Deletes the staging area.
*/
public function destroy(): void {
$this->dispatch(new PreDestroyEvent());
$this->dispatch(new PreDestroyEvent($this));
$stage_dir = $this->pathLocator->getStageDirectory();
if (is_dir($stage_dir)) {
$this->cleaner->clean($stage_dir);
}
$this->dispatch(new PostDestroyEvent());
$this->dispatch(new PostDestroyEvent($this));
}
/**
......
......@@ -19,6 +19,8 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Tests that the staging area fires events during its lifecycle.
*
* @covers \Drupal\package_manager\Event\StageEvent
*
* @group package_manager
*/
class StageEventsTest extends KernelTestBase implements EventSubscriberInterface {
......@@ -63,6 +65,9 @@ class StageEventsTest extends KernelTestBase implements EventSubscriberInterface
public function handleEvent(StageEvent $event): void {
array_push($this->events, get_class($event));
// The event should have a reference to the stage which fired it.
$this->assertSame($event->getStage(), $this->container->get('package_manager.stage'));
// Adding a warning to the event, should not trigger an exception.
$result = ValidationResult::createWarning([
'This is a public service announcement, this is only a test.',
......
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