Page MenuHomePhabricator

Early PHP warnings do not make CI jobs fail
Closed, DuplicatePublic

Description

I r1084859, merged just a couple hours ago, a new class was introduced, BundleSizeTest. However, the same class name is already defined as an alias of BundleSizeTestBase. You would think that defining the same class twice would make most of the CI jobs scream and fail, but no. All tests passed for that patch, and PHP just shyly emits a warning just before running PHPUnit tests (and probably elsewhere), as can be seen in https://integration.wikimedia.org/ci/job/wmf-quibble-core-vendor-mysql-php74/15740/console:

> phpunit '--testsuite' 'extensions' '--exclude-group' 'Broken,ParserFuzz,Stub,Database,Standalone'
Using PHP 7.4.33
Running with MediaWiki settings because there might be integration tests
PHP Warning:  Cannot declare class MediaWiki\Tests\Structure\BundleSizeTest, because the name is already in use in /workspace/src/tests/phpunit/structure/BundleSizeTestBase.php on line 105
PHPUnit 9.6.19 by Sebastian Bergmann and contributors.

...........................................................    59 / 27394 (  0%)

The same is true for extensions: we get the same warning in CI, but no fails whatsoever. Clearly this is just absurd and makes no sense at all, and it needs to be caught somewhere.

Event Timeline

The first thing I'm wondering is when exactly this might happen. We know from the above that it can happen with PHPUnit test classes. But for non-test classes, I assume we may have other checks in place to detect duplicated entries in the autoloader. A working solution would be to catch PHP warnings in AutoLoader::autoload, but I believe that can only be done by replacing the error handler and then restoring it, and I'm not sure if that's a good idea, given that the autoloader code is relatively hot.