Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Support custom event listener property setup
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored Aug 5, 2020
1 parent 33624be commit 23cc0ba
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/EventTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ protected function objectHasHandlers()
return true;
}

protected function getEventListeners($provider)
{
$property = (new ReflectionClass($provider))->getProperty('listen');
$property->setAccessible(true);

return $property->getValue($provider);
}

protected function getEventServiceProvider()
{
$split = explode('\\', (new ReflectionClass($this))->getName());
Expand All @@ -59,12 +67,8 @@ public function testEventHasRegisteredHandlers()
$this->setFrameworkExpectations();

$provider = $this->getEventServiceProvider();

$property = (new ReflectionClass($provider))->getProperty('listen');
$property->setAccessible(true);

$class = get_class($this->getObjectAndParams()['object']);
$mappings = $property->getValue(new $provider($this->app));
$mappings = $this->getEventListeners(new $provider($this->app));

$this->assertTrue(isset($mappings[$class]), "Expected '{$class}' to exists as a key in the event mappings.");

Expand Down

0 comments on commit 23cc0ba

Please sign in to comment.