Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Afform Tests - Fix extension tests when run via civi-test-run #18511

Merged
merged 2 commits into from
Sep 18, 2020

Conversation

totten
Copy link
Member

@totten totten commented Sep 18, 2020

Overview

The afform tests were previously run locally with a script bin/test-all.sh. They were recently added to thecivi-test-run sequence for core test jobs, but the environment is slightly different.

This involves two distinct changes.

Technical Details

  • Change 1: Most of the tests include an installation step (eg Civi\Test::headless()->installMe()...). This had a problem that wasn't apparent when running locally on a heady dev-build, but it does appear in a clean-environment -- i.e. it wasn't sufficiently aggressive in clearing the Container. In other extensions (e.g. flexmailer and mosaico), the test-suite specifically disables the Container cache to avoid this problem. But it's kind of annoying to remember to do this on all test-suites.
    • Before: Tests fail unless (a) you pre-install the extension or (b) specifically set the container-cache policy to never.
    • After: Tests pass. When running any tests, the container-cache policy is effectively never.
  • Change 2: When adding/editing/deleting afforms, it has the effect of updating the list of Angular modules. This requires clearing some metadata/caches.
    • Before: It clears the angular service-object. The Symfony Container allows this sometimes; but other times it doesn't.
    • After: It keeps the angular service-object, but asks it do it its own (more fine-tuned) cache-clear.

After switching the tests from an effective policy of `CIVICRM_CONTAINER_CACHE=auto`
to an effective policy of `CIVICRM_CONTAINER_CACHE=never`, this started to fail:

```
1) api_v4_AfformTest::testGetUpdateRevert with data set #0 ('mockPage', array('', '', 'civicrm/mock-page', 'access Foobar'))
Symfony\Component\DependencyInjection\Exception\BadMethodCallException: Setting service "angular" for an unknown or non-synthetic service definition on a compiled container is not allowed.

/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/vendor/symfony/dependency-injection/ContainerBuilder.php:532
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/ext/afform/core/afform.php:520
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/ext/afform/core/Civi/Api4/Afform.php:99
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Generic/BasicBatchAction.php:88
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Generic/BasicBatchAction.php:68
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Provider/ActionObjectProvider.php:68
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/API/Kernel.php:150
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Generic/AbstractAction.php:238
/home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php:53
/home/me/bknix/extern/phpunit6/phpunit6.phar:570
```
@civibot
Copy link

civibot bot commented Sep 18, 2020

(Standard links)

@civibot civibot bot added the master label Sep 18, 2020
@seamuslee001
Copy link
Contributor

This works for me assuming jenkins likes it LGTM

@seamuslee001 seamuslee001 merged commit d6ae26b into civicrm:master Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants