Page MenuHomePhabricator

AutoLoaderStructureTest works incorrectly on extensions using PSR-4 autoloading and class_alias
Open, Needs TriagePublic

Description

When fixing up https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/Echo/+/465562/

If we add these classes below in AutoloadClasses

		"EchoAttributeManager": "includes/AttributeManager.php",
		"EchoCallbackIterator": "includes/Iterator/CallbackIterator.php",
		"EchoDbFactory": "includes/DbFactory.php",
		"EchoDiscussionParser": "includes/DiscussionParser.php",
		"EchoEvent": "includes/Model/Event.php",
		"EchoEventMapper": "includes/Mapper/EventMapper.php",
		"EchoEventPresentationModel": "includes/Formatters/EventPresentationModel.php",
		"EchoModerationController": "includes/Controller/ModerationController.php",
		"EchoNotificationController": "includes/Controller/NotificationController.php",
		"EchoUserLocator": "includes/UserLocator.php",

We get a failure in AutoLoaderStructureTest::testAutoLoadConfig over at https://integration.wikimedia.org/ci/job/wmf-quibble-vendor-mysql-hhvm-docker/7577/console

01:42:24 1) AutoLoaderStructureTest::testAutoLoadConfig
01:42:24 Failed asserting that two arrays are equal.
01:42:24 --- Expected
01:42:24 +++ Actual
01:42:24 @@ @@
01:42:24      'ZeroPortal\ZeroConfigView' => '/workspace/src/extensions/Zer...ew.php'
01:42:24 +    'MediaWiki\Notifications\AttributeManager' => '/workspace/src/extensions/Ech...er.php'
01:42:24 +    'MediaWiki\Notifications\Iterator\CallbackIterator' => '/workspace/src/extensions/Ech...or.php'
01:42:24 +    'MediaWiki\Notifications\DbFactory' => '/workspace/src/extensions/Ech...ry.php'
01:42:24 +    'MediaWiki\Notifications\DiscussionParser' => '/workspace/src/extensions/Ech...er.php'
01:42:24 +    'MediaWiki\Notifications\Model\Event' => '/workspace/src/extensions/Ech...nt.php'
01:42:24 +    'MediaWiki\Notifications\Mapper\EventMapper' => '/workspace/src/extensions/Ech...er.php'
01:42:24 +    'MediaWiki\Notifications\Formatters\EventPresentationModel' => '/workspace/src/extensions/Ech...el.php'
01:42:24 +    'MediaWiki\Notifications\Controller\ModerationController' => '/workspace/src/extensions/Ech...er.php'
01:42:24 +    'MediaWiki\Notifications\Controller\NotificationController' => '/workspace/src/extensions/Ech...er.php'
01:42:24 +    'MediaWiki\Notifications\UserLocator' => '/workspace/src/extensions/Ech...or.php'
01:42:24  )
01:42:24 
01:42:24 /workspace/src/tests/phpunit/structure/AutoLoaderStructureTest.php:19
01:42:24 /workspace/src/tests/phpunit/MediaWikiTestCase.php:416
01:42:24 /workspace/src/maintenance/doMaintenance.php:94

If we remove those.... https://integration.wikimedia.org/ci/job/wmf-quibble-vendor-mysql-hhvm-docker/7578/console

01:48:40 Fatal error: unknown class EchoEventPresentationModel in /workspace/src/extensions/Flow/includes/Notifications/FlowPresentationModel.php on line 9

It seems to be an issue related to AutoLoaderStructureTest, as the class_alias classes should be in AutoloadClasses for the correct behaviour

Event Timeline

Reedy renamed this task from PSR-4 autoload doesn't seem to work with class_alias to AutoLoaderStructureTest works incorrectly on extensions using PSR-4 autoloading and class_alias.Oct 11 2018, 1:42 AM
Reedy added a project: MediaWiki-Core-Tests.
Reedy updated the task description. (Show Details)

Change 472202 had a related patch set uploaded (by D3r1ck01; owner: Alangi Derick):
[mediawiki/core@master] Remove array_unique() on expected classes in checkAutoLoadConf()

https://gerrit.wikimedia.org/r/472202

Change 472202 merged by jenkins-bot:
[mediawiki/core@master] Remove array_unique() on expected classes in checkAutoLoadConf()

https://gerrit.wikimedia.org/r/472202

Some good progress so far by @Reedy (thanks), @thiemowmde (for reviewing thoroughly) and finally @Legoktm (for landing the patch). So now with this patch: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/GuidedTour/+/466675 with 1 autoloaded class via class aliases and psr-4, we have the following error;

10:47:05 1) AutoLoaderStructureTest::testAutoLoadConfig
10:47:05 Failed asserting that two arrays are equal.
10:47:05 --- Expected
10:47:05 +++ Actual
10:47:05 @@ @@
10:47:05      'ZeroPortal\ZeroConfigView' => '/workspace/src/extensions/Zer...ew.php'
10:47:05 +    'MediaWiki\GuidedTour\Launcher' => '/workspace/src/extensions/Gui...er.php'
10:47:05  )
10:47:05 
10:47:05 /workspace/src/tests/phpunit/structure/AutoLoaderStructureTest.php:19
10:47:05 /workspace/src/tests/phpunit/MediaWikiTestCase.php:424
10:47:05 /workspace/src/maintenance/doMaintenance.php:94
10:47:05

So still for some reason, when autoload classes via class aliases and psr-4 are used at the same time, the mapping of classes to their corresponding files is not still composed correctly. A follow up patch to AutoloaderStructureTest coming soon...

I encountered the same issue while working on https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/502278. After renaming MenuBuilder to Group and registering it via PSR-4 the AutoLoaderStructureTest started to fail. After adding MediaWiki\Minerva\Menu\Group also to AutoloadClasses it works again.