From 39b870b8909a488c58ab35e5ec4656e65e190a8a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 5 May 2020 19:37:40 -0700 Subject: [PATCH] dev/core#1744 - Civi/API - Simplify event naming --- Civi/API/Event/AuthorizeEvent.php | 6 ++++ Civi/API/Event/ExceptionEvent.php | 5 +-- Civi/API/Event/PrepareEvent.php | 4 +++ Civi/API/Event/ResolveEvent.php | 6 ++++ Civi/API/Event/RespondEvent.php | 4 +++ Civi/API/Events.php | 35 ++++++++----------- Civi/API/Kernel.php | 10 +++--- Civi/API/Provider/AdhocProvider.php | 4 +-- Civi/API/Provider/MagicFunctionProvider.php | 2 +- Civi/API/Provider/ReflectionProvider.php | 4 +-- Civi/API/Provider/StaticProvider.php | 4 +-- Civi/API/Subscriber/APIv3SchemaAdapter.php | 2 +- Civi/API/Subscriber/ChainSubscriber.php | 2 +- Civi/API/Subscriber/DebugSubscriber.php | 5 ++- .../API/Subscriber/DynamicFKAuthorization.php | 2 +- Civi/API/Subscriber/I18nSubscriber.php | 4 +-- Civi/API/Subscriber/PermissionCheck.php | 2 +- Civi/API/Subscriber/TransactionSubscriber.php | 6 ++-- Civi/API/Subscriber/WhitelistSubscriber.php | 4 +-- Civi/API/Subscriber/WrapperAdapter.php | 4 +-- .../Generic/AbstractPrepareSubscriber.php | 3 +- .../Subscriber/PermissionCheckSubscriber.php | 2 +- Civi/Api4/Provider/ActionObjectProvider.php | 2 +- .../Civi/API/Event/PrepareEventTest.php | 3 +- tests/phpunit/Civi/API/KernelTest.php | 16 ++++----- 25 files changed, 77 insertions(+), 64 deletions(-) diff --git a/Civi/API/Event/AuthorizeEvent.php b/Civi/API/Event/AuthorizeEvent.php index 82c6343824..9d146a9b40 100644 --- a/Civi/API/Event/AuthorizeEvent.php +++ b/Civi/API/Event/AuthorizeEvent.php @@ -14,6 +14,12 @@ namespace Civi\API\Event; /** * Class AuthorizeEvent * @package Civi\API\Event + * + * Determine whether the API request is allowed for the current user. + * For successful execution, at least one listener must invoke + * $event->authorize(). + * + * Event name: 'civi.api.authorize' */ class AuthorizeEvent extends Event { /** diff --git a/Civi/API/Event/ExceptionEvent.php b/Civi/API/Event/ExceptionEvent.php index 8860e51724..3b95ea539b 100644 --- a/Civi/API/Event/ExceptionEvent.php +++ b/Civi/API/Event/ExceptionEvent.php @@ -12,8 +12,9 @@ namespace Civi\API\Event; /** - * Class ExceptionEvent - * @package Civi\API\Event + * Handle any exceptions that occur while processing an API request. + * + * Event name: 'civi.api.exception' */ class ExceptionEvent extends Event { diff --git a/Civi/API/Event/PrepareEvent.php b/Civi/API/Event/PrepareEvent.php index 8fcf7fb134..1c6576173c 100644 --- a/Civi/API/Event/PrepareEvent.php +++ b/Civi/API/Event/PrepareEvent.php @@ -16,6 +16,10 @@ use Civi\API\Provider\WrappingProvider; /** * Class PrepareEvent * @package Civi\API\Event + * + * Apply any pre-execution filtering to the API request. + * + * Event name: 'civi.api.prepare' */ class PrepareEvent extends Event { diff --git a/Civi/API/Event/ResolveEvent.php b/Civi/API/Event/ResolveEvent.php index b0f6f01a31..8d574a0327 100644 --- a/Civi/API/Event/ResolveEvent.php +++ b/Civi/API/Event/ResolveEvent.php @@ -14,6 +14,12 @@ namespace Civi\API\Event; /** * Class ResolveEvent * @package Civi\API\Event + * + * Determine which API provider executes the given request. For successful + * execution, at least one listener must invoke + * $event->setProvider($provider). + * + * Event name: 'civi.api.resolve' */ class ResolveEvent extends Event { diff --git a/Civi/API/Event/RespondEvent.php b/Civi/API/Event/RespondEvent.php index 8f560b6109..462cc6edab 100644 --- a/Civi/API/Event/RespondEvent.php +++ b/Civi/API/Event/RespondEvent.php @@ -14,6 +14,10 @@ namespace Civi\API\Event; /** * Class RespondEvent * @package Civi\API\Event + * + * Apply post-execution filtering to the API request/response. + * + * Event name: 'civi.api.respond' */ class RespondEvent extends Event { /** diff --git a/Civi/API/Events.php b/Civi/API/Events.php index ff6f4caa1d..6bbecb8f03 100644 --- a/Civi/API/Events.php +++ b/Civi/API/Events.php @@ -22,27 +22,20 @@ namespace Civi\API; class Events { /** - * Determine whether the API request is allowed for the current user. - * For successful execution, at least one listener must invoke - * $event->authorize(). - * * @see AuthorizeEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const AUTHORIZE = 'civi.api.authorize'; /** - * Determine which API provider executes the given request. For successful - * execution, at least one listener must invoke - * $event->setProvider($provider). - * * @see ResolveEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const RESOLVE = 'civi.api.resolve'; /** - * Apply pre-execution logic - * * @see PrepareEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const PREPARE = 'civi.api.prepare'; @@ -50,6 +43,7 @@ class Events { * Apply post-execution logic * * @see RespondEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const RESPOND = 'civi.api.respond'; @@ -57,6 +51,7 @@ class Events { * Handle any exceptions. * * @see ExceptionEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const EXCEPTION = 'civi.api.exception'; @@ -80,11 +75,11 @@ class Events { */ public static function allEvents() { return [ - self::AUTHORIZE, - self::EXCEPTION, - self::PREPARE, - self::RESOLVE, - self::RESPOND, + 'civi.api.authorize', + 'civi.api.exception', + 'civi.api.prepare', + 'civi.api.resolve', + 'civi.api.respond', ]; } @@ -93,11 +88,11 @@ class Events { * @see \CRM_Utils_Hook::eventDefs */ public static function hookEventDefs($e) { - $e->inspector->addEventClass(self::AUTHORIZE, 'Civi\API\Event\AuthorizeEvent'); - $e->inspector->addEventClass(self::EXCEPTION, 'Civi\API\Event\ExceptionEvent'); - $e->inspector->addEventClass(self::PREPARE, 'Civi\API\Event\PrepareEvent'); - $e->inspector->addEventClass(self::RESOLVE, 'Civi\API\Event\ResolveEvent'); - $e->inspector->addEventClass(self::RESPOND, 'Civi\API\Event\RespondEvent'); + $e->inspector->addEventClass('civi.api.authorize', 'Civi\API\Event\AuthorizeEvent'); + $e->inspector->addEventClass('civi.api.exception', 'Civi\API\Event\ExceptionEvent'); + $e->inspector->addEventClass('civi.api.prepare', 'Civi\API\Event\PrepareEvent'); + $e->inspector->addEventClass('civi.api.resolve', 'Civi\API\Event\ResolveEvent'); + $e->inspector->addEventClass('civi.api.respond', 'Civi\API\Event\RespondEvent'); } } diff --git a/Civi/API/Kernel.php b/Civi/API/Kernel.php index 13e55c3445..feb8b662e4 100644 --- a/Civi/API/Kernel.php +++ b/Civi/API/Kernel.php @@ -83,7 +83,7 @@ class Kernel { } catch (\Exception $e) { if ($apiRequest) { - $this->dispatcher->dispatch(Events::EXCEPTION, new ExceptionEvent($e, NULL, $apiRequest, $this)); + $this->dispatcher->dispatch('civi.api.exception', new ExceptionEvent($e, NULL, $apiRequest, $this)); } if ($e instanceof \PEAR_Exception) { @@ -197,7 +197,7 @@ class Kernel { */ public function resolve($apiRequest) { /** @var \Civi\API\Event\ResolveEvent $resolveEvent */ - $resolveEvent = $this->dispatcher->dispatch(Events::RESOLVE, new ResolveEvent($apiRequest, $this)); + $resolveEvent = $this->dispatcher->dispatch('civi.api.resolve', new ResolveEvent($apiRequest, $this)); $apiRequest = $resolveEvent->getApiRequest(); if (!$resolveEvent->getApiProvider()) { throw new \Civi\API\Exception\NotImplementedException("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)"); @@ -216,7 +216,7 @@ class Kernel { */ public function authorize($apiProvider, $apiRequest) { /** @var \Civi\API\Event\AuthorizeEvent $event */ - $event = $this->dispatcher->dispatch(Events::AUTHORIZE, new AuthorizeEvent($apiProvider, $apiRequest, $this)); + $event = $this->dispatcher->dispatch('civi.api.authorize', new AuthorizeEvent($apiProvider, $apiRequest, $this)); if (!$event->isAuthorized()) { throw new \Civi\API\Exception\UnauthorizedException("Authorization failed"); } @@ -235,7 +235,7 @@ class Kernel { */ public function prepare($apiProvider, $apiRequest) { /** @var \Civi\API\Event\PrepareEvent $event */ - $event = $this->dispatcher->dispatch(Events::PREPARE, new PrepareEvent($apiProvider, $apiRequest, $this)); + $event = $this->dispatcher->dispatch('civi.api.prepare', new PrepareEvent($apiProvider, $apiRequest, $this)); return [$event->getApiProvider(), $event->getApiRequest()]; } @@ -253,7 +253,7 @@ class Kernel { */ public function respond($apiProvider, $apiRequest, $result) { /** @var \Civi\API\Event\RespondEvent $event */ - $event = $this->dispatcher->dispatch(Events::RESPOND, new RespondEvent($apiProvider, $apiRequest, $result, $this)); + $event = $this->dispatcher->dispatch('civi.api.respond', new RespondEvent($apiProvider, $apiRequest, $result, $this)); return $event->getResponse(); } diff --git a/Civi/API/Provider/AdhocProvider.php b/Civi/API/Provider/AdhocProvider.php index fcab72e182..f7855635a8 100644 --- a/Civi/API/Provider/AdhocProvider.php +++ b/Civi/API/Provider/AdhocProvider.php @@ -27,10 +27,10 @@ class AdhocProvider implements EventSubscriberInterface, ProviderInterface { // to override standard implementations -- which is // handy for testing/mocking. return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_EARLY], ], - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_EARLY], ], ]; diff --git a/Civi/API/Provider/MagicFunctionProvider.php b/Civi/API/Provider/MagicFunctionProvider.php index 8fab3ff19c..febcaa0622 100644 --- a/Civi/API/Provider/MagicFunctionProvider.php +++ b/Civi/API/Provider/MagicFunctionProvider.php @@ -25,7 +25,7 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa */ public static function getSubscribedEvents() { return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_MIDDLE], ], ]; diff --git a/Civi/API/Provider/ReflectionProvider.php b/Civi/API/Provider/ReflectionProvider.php index 87b95bb18b..ac432b8fa3 100644 --- a/Civi/API/Provider/ReflectionProvider.php +++ b/Civi/API/Provider/ReflectionProvider.php @@ -24,11 +24,11 @@ class ReflectionProvider implements EventSubscriberInterface, ProviderInterface */ public static function getSubscribedEvents() { return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ // TODO decide if we really want to override others ['onApiResolve', Events::W_EARLY], ], - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ // TODO decide if we really want to override others ['onApiAuthorize', Events::W_EARLY], ], diff --git a/Civi/API/Provider/StaticProvider.php b/Civi/API/Provider/StaticProvider.php index 31dc36c7a6..138d561b1f 100644 --- a/Civi/API/Provider/StaticProvider.php +++ b/Civi/API/Provider/StaticProvider.php @@ -29,10 +29,10 @@ class StaticProvider extends AdhocProvider { */ public static function getSubscribedEvents() { return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_MIDDLE], ], - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_MIDDLE], ], ]; diff --git a/Civi/API/Subscriber/APIv3SchemaAdapter.php b/Civi/API/Subscriber/APIv3SchemaAdapter.php index a2ebabd450..fa15949348 100644 --- a/Civi/API/Subscriber/APIv3SchemaAdapter.php +++ b/Civi/API/Subscriber/APIv3SchemaAdapter.php @@ -25,7 +25,7 @@ class APIv3SchemaAdapter implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => [ + 'civi.api.prepare' => [ ['onApiPrepare', Events::W_MIDDLE], ['onApiPrepare_validate', Events::W_LATE], ], diff --git a/Civi/API/Subscriber/ChainSubscriber.php b/Civi/API/Subscriber/ChainSubscriber.php index 8834495633..ff4f79256e 100644 --- a/Civi/API/Subscriber/ChainSubscriber.php +++ b/Civi/API/Subscriber/ChainSubscriber.php @@ -40,7 +40,7 @@ class ChainSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::RESPOND => ['onApiRespond', Events::W_EARLY], + 'civi.api.respond' => ['onApiRespond', Events::W_EARLY], ]; } diff --git a/Civi/API/Subscriber/DebugSubscriber.php b/Civi/API/Subscriber/DebugSubscriber.php index 88f529f972..ac1abad894 100644 --- a/Civi/API/Subscriber/DebugSubscriber.php +++ b/Civi/API/Subscriber/DebugSubscriber.php @@ -11,7 +11,6 @@ namespace Civi\API\Subscriber; -use Civi\API\Events; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -30,8 +29,8 @@ class DebugSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', 999], - Events::RESPOND => ['onApiRespond', -999], + 'civi.api.prepare' => ['onApiPrepare', 999], + 'civi.api.respond' => ['onApiRespond', -999], ]; } diff --git a/Civi/API/Subscriber/DynamicFKAuthorization.php b/Civi/API/Subscriber/DynamicFKAuthorization.php index ecaf5ff428..6a19cded03 100644 --- a/Civi/API/Subscriber/DynamicFKAuthorization.php +++ b/Civi/API/Subscriber/DynamicFKAuthorization.php @@ -36,7 +36,7 @@ class DynamicFKAuthorization implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_EARLY], ], ]; diff --git a/Civi/API/Subscriber/I18nSubscriber.php b/Civi/API/Subscriber/I18nSubscriber.php index f89964c0b2..d3b732972a 100644 --- a/Civi/API/Subscriber/I18nSubscriber.php +++ b/Civi/API/Subscriber/I18nSubscriber.php @@ -32,8 +32,8 @@ class I18nSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', Events::W_MIDDLE], - Events::RESPOND => ['onApiRespond', Events::W_LATE], + 'civi.api.prepare' => ['onApiPrepare', Events::W_MIDDLE], + 'civi.api.respond' => ['onApiRespond', Events::W_LATE], ]; } diff --git a/Civi/API/Subscriber/PermissionCheck.php b/Civi/API/Subscriber/PermissionCheck.php index bc2f18af6a..9441800733 100644 --- a/Civi/API/Subscriber/PermissionCheck.php +++ b/Civi/API/Subscriber/PermissionCheck.php @@ -26,7 +26,7 @@ class PermissionCheck implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_LATE], ], ]; diff --git a/Civi/API/Subscriber/TransactionSubscriber.php b/Civi/API/Subscriber/TransactionSubscriber.php index 8e7ff6a31b..88f34f69b2 100644 --- a/Civi/API/Subscriber/TransactionSubscriber.php +++ b/Civi/API/Subscriber/TransactionSubscriber.php @@ -34,9 +34,9 @@ class TransactionSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', Events::W_EARLY], - Events::RESPOND => ['onApiRespond', Events::W_MIDDLE], - Events::EXCEPTION => ['onApiException', Events::W_EARLY], + 'civi.api.prepare' => ['onApiPrepare', Events::W_EARLY], + 'civi.api.respond' => ['onApiRespond', Events::W_MIDDLE], + 'civi.api.exception' => ['onApiException', Events::W_EARLY], ]; } diff --git a/Civi/API/Subscriber/WhitelistSubscriber.php b/Civi/API/Subscriber/WhitelistSubscriber.php index 2efd8eef96..3a43128364 100644 --- a/Civi/API/Subscriber/WhitelistSubscriber.php +++ b/Civi/API/Subscriber/WhitelistSubscriber.php @@ -30,8 +30,8 @@ class WhitelistSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => ['onApiAuthorize', Events::W_EARLY], - Events::RESPOND => ['onApiRespond', Events::W_MIDDLE], + 'civi.api.authorize' => ['onApiAuthorize', Events::W_EARLY], + 'civi.api.respond' => ['onApiRespond', Events::W_MIDDLE], ]; } diff --git a/Civi/API/Subscriber/WrapperAdapter.php b/Civi/API/Subscriber/WrapperAdapter.php index 6b90161e91..c721673142 100644 --- a/Civi/API/Subscriber/WrapperAdapter.php +++ b/Civi/API/Subscriber/WrapperAdapter.php @@ -26,8 +26,8 @@ class WrapperAdapter implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', Events::W_MIDDLE], - Events::RESPOND => ['onApiRespond', Events::W_EARLY * 2], + 'civi.api.prepare' => ['onApiPrepare', Events::W_MIDDLE], + 'civi.api.respond' => ['onApiRespond', Events::W_EARLY * 2], ]; } diff --git a/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php b/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php index aae758b2a8..3835c70d28 100644 --- a/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php +++ b/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php @@ -22,7 +22,6 @@ namespace Civi\Api4\Event\Subscriber\Generic; use Civi\API\Event\PrepareEvent; -use Civi\API\Events; use Symfony\Component\EventDispatcher\EventSubscriberInterface; abstract class AbstractPrepareSubscriber implements EventSubscriberInterface { @@ -32,7 +31,7 @@ abstract class AbstractPrepareSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => 'onApiPrepare', + 'civi.api.prepare' => 'onApiPrepare', ]; } diff --git a/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php b/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php index 500b0c6930..70fecac907 100644 --- a/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php +++ b/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php @@ -26,7 +26,7 @@ class PermissionCheckSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_LATE], ], ]; diff --git a/Civi/Api4/Provider/ActionObjectProvider.php b/Civi/Api4/Provider/ActionObjectProvider.php index b31c3d323f..9fa607c65e 100644 --- a/Civi/Api4/Provider/ActionObjectProvider.php +++ b/Civi/Api4/Provider/ActionObjectProvider.php @@ -31,7 +31,7 @@ class ActionObjectProvider implements EventSubscriberInterface, ProviderInterfac // to override standard implementations -- which is // handy for testing/mocking. return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_EARLY], ], ]; diff --git a/tests/phpunit/Civi/API/Event/PrepareEventTest.php b/tests/phpunit/Civi/API/Event/PrepareEventTest.php index 258a7bf642..ce5516c98b 100644 --- a/tests/phpunit/Civi/API/Event/PrepareEventTest.php +++ b/tests/phpunit/Civi/API/Event/PrepareEventTest.php @@ -2,7 +2,6 @@ namespace Civi\API\Event; use Symfony\Component\EventDispatcher\EventDispatcher; -use Civi\API\Events; use Civi\API\Kernel; /** @@ -45,7 +44,7 @@ class PrepareEventTest extends \CiviUnitTestCase { * @dataProvider getPrepareExamples */ public function testOnPrepare($onPrepare, $inputApiCall, $expectResult) { - $this->dispatcher->addListener(Events::PREPARE, [$this, $onPrepare]); + $this->dispatcher->addListener('civi.api.prepare', [$this, $onPrepare]); $this->kernel->registerApiProvider($this->createWidgetFrobnicateProvider()); $result = call_user_func_array([$this->kernel, 'runSafe'], $inputApiCall); $this->assertEquals($expectResult, $result['values']); diff --git a/tests/phpunit/Civi/API/KernelTest.php b/tests/phpunit/Civi/API/KernelTest.php index 6d8829b01d..32ef294712 100644 --- a/tests/phpunit/Civi/API/KernelTest.php +++ b/tests/phpunit/Civi/API/KernelTest.php @@ -39,10 +39,10 @@ class KernelTest extends \CiviUnitTestCase { ]); $expectedEventSequence = [ - ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'], - ['name' => Events::AUTHORIZE, 'class' => 'Civi\API\Event\AuthorizeEvent'], - ['name' => Events::PREPARE, 'class' => 'Civi\API\Event\PrepareEvent'], - ['name' => Events::RESPOND, 'class' => 'Civi\API\Event\RespondEvent'], + ['name' => 'civi.api.resolve', 'class' => 'Civi\API\Event\ResolveEvent'], + ['name' => 'civi.api.authorize', 'class' => 'Civi\API\Event\AuthorizeEvent'], + ['name' => 'civi.api.prepare', 'class' => 'Civi\API\Event\PrepareEvent'], + ['name' => 'civi.api.respond', 'class' => 'Civi\API\Event\RespondEvent'], ]; $this->assertEquals($expectedEventSequence, $this->actualEventSequence); $this->assertEquals('frob', $result['values'][98]); @@ -50,10 +50,10 @@ class KernelTest extends \CiviUnitTestCase { public function testResolveException() { $test = $this; - $this->dispatcher->addListener(Events::RESOLVE, function () { + $this->dispatcher->addListener('civi.api.resolve', function () { throw new \API_Exception('Oh My God', 'omg', ['the' => 'badzes']); }, Events::W_EARLY); - $this->dispatcher->addListener(Events::EXCEPTION, function (\Civi\API\Event\ExceptionEvent $event) use ($test) { + $this->dispatcher->addListener('civi.api.exception', function (\Civi\API\Event\ExceptionEvent $event) use ($test) { $test->assertEquals('Oh My God', $event->getException()->getMessage()); }); @@ -63,8 +63,8 @@ class KernelTest extends \CiviUnitTestCase { ]); $expectedEventSequence = [ - ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'], - ['name' => Events::EXCEPTION, 'class' => 'Civi\API\Event\ExceptionEvent'], + ['name' => 'civi.api.resolve', 'class' => 'Civi\API\Event\ResolveEvent'], + ['name' => 'civi.api.exception', 'class' => 'Civi\API\Event\ExceptionEvent'], ]; $this->assertEquals($expectedEventSequence, $this->actualEventSequence); $this->assertEquals('Oh My God', $result['error_message']); -- 2.25.1