This error is caused by the fact that Switfmailer determines the constant SWIFT_REQUIRED_LOADED after installing the autoloader. the autoloader checks this constant, and if it is already defined, refuses to install the autoloader. During the isolation process, PHPUnit ensures that all defined constants are overridden in the processes that spawn to run the test. Unfortunately, this means that SWIFT_REQUIRED_LOADED is determined during testing, so the autoloader does not load (see "swift_required.php" in the swiftmailer source folder). Note that if you turn it off, turn on the global state for the test through annotations, the tests will still not work, because the bootstrap file is passed to the test process through the global variable __PHPUNIT_BOOTSTRAP (see TestCaseMethod.tpl in the PHPUnit directory). Without globals, this global undefined was in the process of testing, and the boot file did not include punching tests.
The only work around which I found that the job is to replace the string $constants = PHPUnit_Util_GlobalState::getConstantsAsString(); with $constants = ''; in the execution method TestCase.php in the original PHPUnit distribution. If your code relies on global constants that must be defined before the test runs, this fix will obviously not work for you (class constants are a different story); unless the specified constants are redefined during your test cases.
source share