Extensions - Reset container+dispatcher after toggling extensions
authorTim Otten <totten@civicrm.org>
Fri, 24 Jun 2022 08:31:10 +0000 (01:31 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 24 Aug 2022 00:07:53 +0000 (17:07 -0700)
commitc76bdfc08949f2dc9e2ae8a256b153a47a872cd3
treeb945d1f87964c92c2d743116135b3566dcf07faf
parentf5eb7178cdf059be4224d2bd4a85f74694ac658d
Extensions - Reset container+dispatcher after toggling extensions

This fixes an issue in E2E testing. Suppose you have a test like this:

  1: function testFoo() {
  2:   civicrm_api3('Extension', 'enable', ['key' => 'foo']);
  3:   assertTrue(Civi::container()->has('foo_service'));
  4:   civicrm_api3('Extension', 'disable', ['key' => 'foo']);
  5:   assertFalse(Civi::container()->has('foo_service'));
  6: }

The assertion at line 5 would fail -- because the 'disable' step did not
fully reset the `Container`.  This problem could then apply to anything that
lives in the container, such as the dispatcher and its listeners.

There is test-coverage in `mixin/scan-classes@1/example` and
`E2E_Shimmy_LifecycleTest::testLifecycleWithLocalFunctions()`.
The test doesn't specifically mention `Container`, but it focuses on one
important service (*the dispatcher*) that lives in the container.

I'm not sure if the problem affected headless tests.
CRM/Extension/Manager.php
Civi/Core/Container.php