[Wikidata.org] AutoLoaderStructureTest::testPSR4Completeness fails
Closed, ResolvedPublic

Description

The Wikidata.org mediawiki extensions fails a mediawiki/core structure test:

$ php tests/phpunit/phpunit.php --testsuite structure
1) AutoLoaderStructureTest::testPSR4Completeness with data set #71 ('WikidataOrg\', '/mediawi...org/./', 'mediawi...ks.php')
Class not autoloaded properly
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'WikidataOrg\oks'
+'WikidataOrg\Hooks'

tests/phpunit/structure/AutoLoaderStructureTest.php:55
tests/phpunit/MediaWikiTestCase.php:469
maintenance/doMaintenance.php:94

Apparently due to extension.json having:

extension.json
{
    "AutoloadNamespaces": {
        "WikidataOrg\\": "./"
    },
}
hashar created this task.Jun 25 2018, 10:47 AM
hashar triaged this task as Normal priority.
Restricted Application added a project: Wikidata. · View Herald TranscriptJun 25 2018, 10:47 AM
hashar updated the task description. (Show Details)

This *might* be an issue with the test itself, I'm not sure how it handles a path of ./...but really the Hooks file should be in includes/ or src/.

hashar added a comment.EditedJun 25 2018, 11:30 AM

Extension registry does not normalizes the path at:

protected function processAutoLoader( $dir, array $files ) { 
    // Make paths absolute, relative to the JSON file
    foreach ( $files as &$file ) { 
        $file = "$dir/$file";
    }

So one end up with: /home/hashar/projects/mediawiki/extensions/Wikidata.org/./Hooks.php

The test then:

$abbrFileName = substr( substr( $file, strlen( $dir ) ), 0, -4 );

Which gives: oks because $dir is too long (it has an extra ./).

Using an empty string as a value for AutoloadNamespaces works fine. The autoloader works in either case.

In the test we can assume the file exists (since it does a file_get_contents), so probably the test should use real_path() to obtain the canonical and absolute path then use path_info() to retrieve the filename:

php > var_dump( pathinfo( 'wikidata.org/./Hooks.php' ) );
array(4) {
  ["dirname"]=>
  string(14) "wikidata.org/."
  ["basename"]=>
  string(9) "Hooks.php"
  ["extension"]=>
  string(3) "php"
  ["filename"]=>
  string(5) "Hooks"
}

php > var_dump( pathinfo( '/home/hashar/projects/mediawiki/extensions/Wikidata.org/Hooks.php', PATHINFO_FILENAME ) );
string(5) "Hooks"

Ie:

- $abbrFileName = substr( substr( $file, strlen( $dir ) ), 0, -4 );
+ $abbrFileName = pathinfo( $file, PATHINFO_FILENAME );

Change 441832 had a related patch set uploaded (by Hashar; owner: Hashar):
[mediawiki/core@master] Use pathinfo() in testPSR4Completeness

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

Change 441832 merged by jenkins-bot:
[mediawiki/core@master] Use pathinfo() in AutoLoaderStructureTest::testPSR4Completeness

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

Change 441852 had a related patch set uploaded (by Hashar; owner: Hashar):
[mediawiki/core@master] Revert "Use pathinfo() in AutoLoaderStructureTest::testPSR4Completeness"

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

Change 441853 had a related patch set uploaded (by Hashar; owner: Hashar):
[mediawiki/extensions/Wikidata.org@master] Do not use ./ in AutoloadNamespaces

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

Change 441852 merged by jenkins-bot:
[mediawiki/core@master] Revert "Use pathinfo() in AutoLoaderStructureTest::testPSR4Completeness"

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

Change 441853 merged by jenkins-bot:
[mediawiki/extensions/Wikidata.org@master] Do not use ./ in AutoloadNamespaces

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

Change 441859 had a related patch set uploaded (by Hashar; owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikidata.org@master] Move PHP source file to src/ directory

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

hashar closed this task as Resolved.Jun 26 2018, 7:35 AM
hashar assigned this task to Lucas_Werkmeister_WMDE.

Change 441859 merged by jenkins-bot:
[mediawiki/extensions/Wikidata.org@master] Move PHP source file to src/ directory

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

Vvjjkkii renamed this task from [Wikidata.org] AutoLoaderStructureTest::testPSR4Completeness fails to 6caaaaaaaa.Jul 1 2018, 1:01 AM
Vvjjkkii reopened this task as Open.
Vvjjkkii raised the priority of this task from Normal to High.
Vvjjkkii removed Lucas_Werkmeister_WMDE as the assignee of this task.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii edited subscribers, added: Lucas_Werkmeister_WMDE; removed: gerritbot, Aklapper.
JJMC89 renamed this task from 6caaaaaaaa to [Wikidata.org] AutoLoaderStructureTest::testPSR4Completeness fails.Jul 1 2018, 3:33 AM
JJMC89 closed this task as Resolved.
JJMC89 lowered the priority of this task from High to Normal.
JJMC89 assigned this task to Lucas_Werkmeister_WMDE.
JJMC89 updated the task description. (Show Details)
JJMC89 edited subscribers, added: Aklapper; removed: Lucas_Werkmeister_WMDE.