- Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Hi, we are using Go-Aop (https://github.com/goaop) to manage database transactions in our source code.
Our AOP aspects should be executed inside our unit and integrations tests, Go-Aop is using its own Autoloader to implement its "weaving".
Since we updated to the last version of PHP_CodeSniffer our transactions do not work anymore because PHP_CodeSniffer defines its own autoloader. This disables the Go-Aop autoloader.
The code in Go-Aop which replaces the Composer autoloader is here https://github.com/goaop/framework/blob/master/src/Instrument/ClassLoading/AopComposerLoader.php#L107.
In their implementation the Composer autoloader is replaced by the Go-Aop autoloader, but now Go-Aop does not work because it cannot detect any Composer autoloader.
This is because PHP_CodeSniffer unplugged it here https://github.com/squizlabs/PHP_CodeSniffer/blob/3.0/autoload.php#L66.
Ideally it would be great to allow Go-Aop to detect that the autoloader in use is the PHP_CodeSniffer autoloader or vice versa.
But other frameworks could define their own autoloaders, in my opinion we should have a mecanism to disable the PHP_CodeSniffer autoloader while we run unit tests.
I'm thinking about 2 solutions.
Add a global variable to disable the PHP_CodeSniffer autoloader
Replace https://github.com/squizlabs/PHP_CodeSniffer/blob/3.0/autoload.php#L239 by the following peace of code.
if(!(defined('DISABLE_PHP_CODE_SNIFFER_AUTOLOADER') && DISABLE_PHP_CODE_SNIFFER_AUTOLOADER)) { spl_autoload_register([__NAMESPACE__.'\Autoload', 'load'], true, true); }
Then we simply have to add the following instruction in our PHPUnit bootstrap code to disable the PHP_CodeSniffer autoloader.
// Disables the PHP_CodeSniffer autoloader because its not useful to execute unit tests define('DISABLE_PHP_CODE_SNIFFER_AUTOLOADER', true);
Better
Simply remove https://github.com/squizlabs/PHP_CodeSniffer/blob/3.0/composer.json#L32 and load the PHP_CodeSniffer autoloader only from the CLI scripts to not have any impact on unit tests.
What's your opinion about this feature ?