Problem
- Global variables of the parent site/test runner are leaking into each test.
- Global variables set/changed by one test case are leaking into subsequent test cases.
- TestBase and WebTestBase back up and restore countless of individual global variables to combat particular environment leaking problems that have been identified in the past.
Goal
- Prevent any global variable from leaking into any test.
Proposed solution
- Back up and restore all global variables before and after test execution.
- Empty out all global variables directly before executing a test's setUp().
- Adjust Drupal bootstrap to allow to re-bootstrap the early environment setter functions
drupal_environment_initialize()anddrupal_settings_initialize().
Notes
- Attached patch is a first prototype, extracted from #1774388: Unit Tests Remastered™.
Related issues
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | drupal8.test-globals.patch | 4.11 KB | lyricnz |
| drupal8.test-globals.0.patch | 4.37 KB | sun |
Comments
Comment #1
lyricnz commentedReroll, post #1774388: Unit Tests Remastered™.
Is there any reason why the theme (originalTheme,originalThemeKey) are still handled separately?
Comment #2
Crell commentedComment #3
sunComment #4
sunSince we currently experience many random test failures, I've created a separate issue to quick-fix
global $conf:#2217087: global $conf leaks into all tests
Comment #5
sunImplicitly fixed by using PHPUnit. PHPUnit properly handles this (and much more).