From f6313472b50a5a0d836392f047632bee62445a31 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Wed, 3 Aug 2022 16:20:03 -0400 Subject: [PATCH] unit test updates --- Civi/API/Kernel.php | 8 ++++---- Civi/Core/Container.php | 4 ++-- tests/phpunit/Civi/API/Event/PrepareEventTest.php | 6 +++--- tests/phpunit/Civi/API/KernelTest.php | 6 +++--- .../Civi/API/Subscriber/DynamicFKAuthorizationTest.php | 6 +++--- .../Civi/API/Subscriber/WhitelistSubscriberTest.php | 4 ++-- tests/phpunit/Civi/Token/TokenProcessorTest.php | 6 +++--- tests/phpunit/E2E/Core/AssetBuilderTest.php | 7 +++++++ 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Civi/API/Kernel.php b/Civi/API/Kernel.php index 02ca71bfd4..acbebe7020 100644 --- a/Civi/API/Kernel.php +++ b/Civi/API/Kernel.php @@ -23,7 +23,7 @@ use Civi\API\Event\RespondEvent; class Kernel { /** - * @var \Symfony\Component\EventDispatcher\EventDispatcher + * @var \Civi\Core\CiviEventDispatcherInterface */ protected $dispatcher; @@ -33,7 +33,7 @@ class Kernel { protected $apiProviders; /** - * @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher + * @param \Civi\Core\CiviEventDispatcherInterface $dispatcher * The event dispatcher which receives kernel events. * @param array $apiProviders * Array of ProviderInterface. @@ -462,14 +462,14 @@ class Kernel { } /** - * @return \Symfony\Component\EventDispatcher\EventDispatcher + * @return \Civi\Core\CiviEventDispatcherInterface */ public function getDispatcher() { return $this->dispatcher; } /** - * @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher + * @param \Civi\Core\CiviEventDispatcherInterface $dispatcher * The event dispatcher which receives kernel events. * @return Kernel */ diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 23e2639a6b..0f493350ab 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -401,7 +401,7 @@ class Container { } /** - * @return \Symfony\Component\EventDispatcher\EventDispatcher + * @return \Civi\Core\CiviEventDispatcherInterface */ public function createEventDispatcher() { // Continue building on the original dispatcher created during bootstrap. @@ -490,7 +490,7 @@ class Container { } /** - * @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher + * @param \Civi\Core\CiviEventDispatcherInterface $dispatcher * @param $magicFunctionProvider * * @return \Civi\API\Kernel diff --git a/tests/phpunit/Civi/API/Event/PrepareEventTest.php b/tests/phpunit/Civi/API/Event/PrepareEventTest.php index 1eb9b82493..f8be302f3a 100644 --- a/tests/phpunit/Civi/API/Event/PrepareEventTest.php +++ b/tests/phpunit/Civi/API/Event/PrepareEventTest.php @@ -1,7 +1,7 @@ dispatcher = new EventDispatcher(); + $this->dispatcher = new CiviEventDispatcher(); $this->kernel = new Kernel($this->dispatcher); } diff --git a/tests/phpunit/Civi/API/KernelTest.php b/tests/phpunit/Civi/API/KernelTest.php index e5702e2718..f5236d76cc 100644 --- a/tests/phpunit/Civi/API/KernelTest.php +++ b/tests/phpunit/Civi/API/KernelTest.php @@ -1,7 +1,7 @@ actualEventSequence = []; - $this->dispatcher = new EventDispatcher(); + $this->dispatcher = new CiviEventDispatcher(); $this->monitorEvents(Events::allEvents()); $this->kernel = new Kernel($this->dispatcher); } diff --git a/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php b/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php index 8bf1ae9ff0..50c85f9adb 100644 --- a/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php +++ b/tests/phpunit/Civi/API/Subscriber/DynamicFKAuthorizationTest.php @@ -3,7 +3,7 @@ namespace Civi\API\Subscriber; use Civi\API\Kernel; use Civi\API\Provider\StaticProvider; -use Symfony\Component\EventDispatcher\EventDispatcher; +use Civi\Core\CiviEventDispatcher; /** */ @@ -19,7 +19,7 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { const FORBIDDEN_ID = 30; /** - * @var \Symfony\Component\EventDispatcher\EventDispatcher + * @var \Civi\Core\CiviEventDispatcher */ public $dispatcher; @@ -67,7 +67,7 @@ class DynamicFKAuthorizationTest extends \CiviUnitTestCase { ] ); - $this->dispatcher = new EventDispatcher(); + $this->dispatcher = new CiviEventDispatcher(); $this->kernel = new Kernel($this->dispatcher); $this->kernel ->registerApiProvider($fileProvider) diff --git a/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php b/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php index 0da270a689..b54eee9d6d 100644 --- a/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php +++ b/tests/phpunit/Civi/API/Subscriber/WhitelistSubscriberTest.php @@ -3,7 +3,7 @@ namespace Civi\API\Subscriber; use Civi\API\Kernel; use Civi\API\WhitelistRule; -use Symfony\Component\EventDispatcher\EventDispatcher; +use Civi\Core\CiviEventDispatcher; /** * The WhitelistSubscriber enforces security policies @@ -371,7 +371,7 @@ class WhitelistSubscriberTest extends \CiviUnitTestCase { $whitelist = WhitelistRule::createAll($rules); - $dispatcher = new EventDispatcher(); + $dispatcher = new CiviEventDispatcher(); $kernel = new Kernel($dispatcher); $kernel->registerApiProvider($sprocketProvider); $kernel->registerApiProvider($widgetProvider); diff --git a/tests/phpunit/Civi/Token/TokenProcessorTest.php b/tests/phpunit/Civi/Token/TokenProcessorTest.php index 3685a6c3b6..9279978288 100644 --- a/tests/phpunit/Civi/Token/TokenProcessorTest.php +++ b/tests/phpunit/Civi/Token/TokenProcessorTest.php @@ -3,12 +3,12 @@ namespace Civi\Token; use Civi\Token\Event\TokenRegisterEvent; use Civi\Token\Event\TokenValueEvent; -use Symfony\Component\EventDispatcher\EventDispatcher; +use Civi\Core\CiviEventDispatcher; class TokenProcessorTest extends \CiviUnitTestCase { /** - * @var \Symfony\Component\EventDispatcher\EventDispatcher + * @var \Civi\Core\CiviEventDispatcher */ protected $dispatcher; @@ -21,7 +21,7 @@ class TokenProcessorTest extends \CiviUnitTestCase { protected function setUp(): void { $this->useTransaction(TRUE); parent::setUp(); - $this->dispatcher = new EventDispatcher(); + $this->dispatcher = new CiviEventDispatcher(); $this->dispatcher->addListener('civi.token.list', [$this, 'onListTokens']); $this->dispatcher->addListener('civi.token.eval', [$this, 'onEvalTokens']); $this->counts = [ diff --git a/tests/phpunit/E2E/Core/AssetBuilderTest.php b/tests/phpunit/E2E/Core/AssetBuilderTest.php index 6352a8497f..305ce27e8d 100644 --- a/tests/phpunit/E2E/Core/AssetBuilderTest.php +++ b/tests/phpunit/E2E/Core/AssetBuilderTest.php @@ -28,6 +28,13 @@ class AssetBuilderTest extends \CiviEndToEndTestCase { \Civi::dispatcher()->addListener('hook_civicrm_buildAsset', array($this, 'buildSquareJs')); } + protected function tearDown(): void { + \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', array($this, 'counter')); + \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', array($this, 'buildSquareTxt')); + \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', array($this, 'buildSquareJs')); + parent::tearDown(); + } + /** * @param \Civi\Core\Event\GenericHookEvent $e * @see \CRM_Utils_Hook::buildAsset() -- 2.25.1