Skip to content

Commit

Permalink
use event type
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Oct 5, 2019
1 parent d810e4b commit 3b03819
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"prefer-stable": true,
"require": {
"php": "^7.1",
"phpgears/event": "~0.2",
"phpgears/event": "~0.3.1",
"symfony/event-dispatcher": "^4.3"
},
"require-dev": {
Expand Down
10 changes: 5 additions & 5 deletions src/ContainerAwareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function addListener($eventName, $listener, $priority = 0): void
{
if (!\is_string($listener)) {
throw new \InvalidArgumentException(\sprintf(
'Event handler must be a container entry, %s given',
'Event handler must be a container entry, "%s" given',
\is_object($listener) ? \get_class($listener) : \gettype($listener)
));
}
Expand All @@ -105,14 +105,14 @@ public function dispatch($eventEnvelope): SymfonyEvent

if (!$eventEnvelope instanceof EventEnvelope) {
throw new \InvalidArgumentException(\sprintf(
'Dispatched event must implement %s, %s given',
'Dispatched event must implement "%s", "%s" given',
EventEnvelope::class,
\get_class($eventEnvelope)
));
}

$eventName = \get_class($eventEnvelope->getWrappedEvent());
$this->dispatchEvent($this->getListeners($eventName), $eventEnvelope);
$eventListeners = $this->getListeners($eventEnvelope->getWrappedEvent()->getEventType());
$this->dispatchEvent($eventListeners, $eventEnvelope);

return $eventEnvelope;
}
Expand All @@ -133,7 +133,7 @@ private function dispatchEvent(array $listeners, EventEnvelope $event): void

if (!$handler instanceof EventHandler) {
throw new \RuntimeException(\sprintf(
'Event handler should implement %s, %s given',
'Event handler should implement "%s", "%s" given',
EventHandler::class,
\is_object($handler) ? \get_class($handler) : \gettype($handler)
));
Expand Down
8 changes: 4 additions & 4 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function addListener($eventName, $listener, $priority = 0): void
{
if (!$listener instanceof EventHandler) {
throw new \InvalidArgumentException(\sprintf(
'Event handler must be an instance of %s, %s given',
'Event handler must be an instance of "%s", "%s" given',
EventHandler::class,
\is_object($listener) ? \get_class($listener) : \gettype($listener)
));
Expand All @@ -95,14 +95,14 @@ public function dispatch($eventEnvelope): SymfonyEvent

if (!$eventEnvelope instanceof EventEnvelope) {
throw new \InvalidArgumentException(\sprintf(
'Dispatched event must implement %s, %s given',
'Dispatched event must implement "%s", "%s" given',
EventEnvelope::class,
\get_class($eventEnvelope)
));
}

$eventName = \get_class($eventEnvelope->getWrappedEvent());
$this->dispatchEvent($this->getListeners($eventName), $eventEnvelope);
$eventListeners = $this->getListeners($eventEnvelope->getWrappedEvent()->getEventType());
$this->dispatchEvent($eventListeners, $eventEnvelope);

return $eventEnvelope;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Dispatcher/ContainerAwareDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContainerAwareDispatcherTest extends TestCase
public function testInvalidListener(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Event handler must be a container entry, stdClass given');
$this->expectExceptionMessage('Event handler must be a container entry, "stdClass" given');

/** @var ContainerInterface $containerMock */
$containerMock = $this->getMockBuilder(ContainerInterface::class)
Expand Down Expand Up @@ -58,7 +58,7 @@ public function testEmptyEvent(): void
public function testInvalidEvent(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/^Dispatched event must implement .+\\\EventEnvelope, .+ given$/');
$this->expectExceptionMessageRegExp('/^Dispatched event must implement ".+\\\EventEnvelope", ".+" given$/');

/** @var ContainerInterface $containerMock */
$containerMock = $this->getMockBuilder(ContainerInterface::class)
Expand All @@ -73,7 +73,7 @@ public function testInvalidEvent(): void
public function testInvalidHandler(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Event handler should implement Gears\Event\EventHandler, string given');
$this->expectExceptionMessage('Event handler should implement "Gears\Event\EventHandler", "string" given');

$containerMock = $this->getMockBuilder(ContainerInterface::class)
->disableOriginalConstructor()
Expand Down
4 changes: 2 additions & 2 deletions tests/Dispatcher/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testInvalidListener(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp(
'/^Event handler must be an instance of .+\\\EventHandler, stdClass given$/'
'/^Event handler must be an instance of ".+\\\EventHandler", "stdClass" given$/'
);

new Dispatcher([\stdClass::class => new \stdClass()]);
Expand All @@ -49,7 +49,7 @@ public function testEmptyEvent(): void
public function testInvalidEvent(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/^Dispatched event must implement .+\\\EventEnvelope, .+ given$/');
$this->expectExceptionMessageRegExp('/^Dispatched event must implement ".+\\\EventEnvelope", ".+" given$/');

$eventDispatcher = new Dispatcher();

Expand Down

0 comments on commit 3b03819

Please sign in to comment.