Skip to content

Commit

Permalink
Php8 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
fritz-gerneth committed Mar 31, 2021
1 parent 60d7c57 commit ddc6aea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/Plugin/Router/RegexRouter.php
Expand Up @@ -129,7 +129,8 @@ private function onRouteToSingleHandler(ActionEvent $actionEvent): void
$alreadyMatched = false;

foreach ($this->patternMap as $map) {
list($pattern, $handler) = \each($map);
$pattern = \key($map);
$handler = \current($map);
if (\preg_match($pattern, $messageName)) {
if ($alreadyMatched) {
throw new Exception\RuntimeException(\sprintf(
Expand All @@ -155,7 +156,8 @@ private function onRouteEvent(ActionEvent $actionEvent): void
}

foreach ($this->patternMap as $map) {
list($pattern, $handler) = \each($map);
$pattern = \key($map);
$handler = \current($map);
if (\preg_match($pattern, $messageName)) {
$listeners = $actionEvent->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, []);
$listeners[] = $handler;
Expand Down
2 changes: 1 addition & 1 deletion tests/Plugin/ListenerExceptionCollectionModeTest.php
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void
$this->eventBus = new class() extends EventBus {
public function isCollectExceptionsModeOn(): bool
{
return (bool)$this->collectExceptions;
return (bool) $this->collectExceptions;
}
};

Expand Down
30 changes: 21 additions & 9 deletions tests/QueryBusTest.php
Expand Up @@ -211,9 +211,13 @@ function () {

$promise = $this->queryBus->dispatch('throw it');

$promise->otherwise(function ($ex) use (&$exception): void {
$exception = $ex;
});
$promise->then(
function () {
},
function (\Throwable $ex) use (&$exception): void {
$exception = $ex;
}
);

$this->assertInstanceOf(MessageDispatchException::class, $exception);
}
Expand All @@ -235,9 +239,13 @@ function (ActionEvent $e): void {

$promise = $this->queryBus->dispatch('throw it');

$promise->otherwise(function ($ex) use (&$exception): void {
$exception = $ex;
});
$promise->then(
function () {
},
function (\Throwable $ex) use (&$exception): void {
$exception = $ex;
}
);

$this->assertInstanceOf(RuntimeException::class, $exception);
$this->assertEquals('Message dispatch failed. See previous exception for details.', $exception->getMessage());
Expand All @@ -260,9 +268,13 @@ function (ActionEvent $e): void {

$promise = $this->queryBus->dispatch('throw it');

$promise->otherwise(function ($ex) use (&$exception): void {
$exception = $ex;
});
$promise->then(
function () {
},
function (\Throwable $ex) use (&$exception): void {
$exception = $ex;
}
);

$this->assertInstanceOf(MessageDispatchException::class, $exception);
$this->assertEquals('Message dispatch failed. See previous exception for details.', $exception->getMessage());
Expand Down

0 comments on commit ddc6aea

Please sign in to comment.