Wikidata build tests are failing because hamcrest functions are not being autoloaded (not included in mediawiki's vendor/composer/autoload_files.php)
https://integration.wikimedia.org/ci/job/mwext-testextension-hhvm/37857/console
These are being autoloaded for Wikibase tests (alone, outside the build). The issue seems to be just with the build. It works locally for me.
10:02:33 Fatal error: Call to undefined function Wikibase\Client\Tests\RecentChanges\both() in /srv/jenkins-workspace/workspace/mwext-testextension-hhvm/src/extensions/Wikidata/extensions/Wikibase/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php on line 177
The slave script bin/mw-fetch-composer-dev.sh apparently manage to inject the dev dependencies and they get installed:
00:00:48.043 - Installing hamcrest/hamcrest-php (v2.0.0) 00:00:48.045 Loading from cache 00:00:48.045 Extracting archive 00:00:48.123 00:00:48.137 - Installing wmde/hamcrest-html-matchers (v0.1.0) 00:00:48.138 Loading from cache 00:00:48.138 Extracting archive
vendor/composer/autoload_files.php and or composer.lock might end up missing them though :(
Reproduction
mediawiki/core
mediawiki/vendor cloned in the vendor subdirectory
integration/jenkins
The CI script mw-composer-fetch-dev.sh grabs the list of packages from require-dev and then require them in the vendor subdirectory.
The dev dependencies:
(cd vendor; ~/projects/integration/jenkins/tools/composer-dev-args.js ~/projects/mediawiki/core/composer.json) /Users/amusso/projects/mediawiki/core/vendor composer/spdx-licenses=1.1.4 jakub-onderka/php-parallel-lint=0.9.2 justinrainbow/json-schema=~3.0 mediawiki/mediawiki-codesniffer=0.7.2 jetbrains/phpstorm-stubs=dev-master#1b9906084d6635456fcf3f3a01f0d7d5b99a578a monolog/monolog=~1.18.2 nikic/php-parser=2.1.0 nmred/kafka-php=0.1.5 phpunit/phpunit=4.8.31 wikimedia/avro=1.7.7 hamcrest/hamcrest-php=^2.0 wmde/hamcrest-html-matchers=^0.1.0
For each we invoke composer require --dev --ansi --no-progress --prefer-dist -v . The result is available as https://gerrit.wikimedia.org/r/339404
Then (cd vendor && composer dump-autoload --optimize) which apparently is a noop.
Given a dummy test file:
<?php use Hamcrest\Matchers; class BlaTest extends MediaWikiTestCase { function testHamcrest() { both(); } }
That fails to load one of Hamcrest function:
$ php tests/phpunit/phpunit.php tests/phpunit/BlaTest.php PHPUnit 4.8.31 by Sebastian Bergmann and contributors. PHP Fatal error: Call to undefined function both() in /Users/amusso/projects/mediawiki/core/tests/phpunit/BlaTest.php on line 8
Case that works
Instead of trying to lookup the static method via namespace, if we refer to the canonical class path it seems to work:
<?php class CanonicalPathTest extends MediaWikiTestCase { function testHamcrest() { \Hamcrest\Matchers::both(); } }
Global functions
One has to explicitly register them with Hamcrest\Util::registerGlobalFunctions();:
<?php Hamcrest\Util::registerGlobalFunctions(); class BlaTest extends MediaWikiTestCase { function testHamcrest() { assertThat(); } }
Other findings
vendor/composer/autoload_files.php refers to $vendorDir . '/mediawiki/at-ease/src/Functions.php'. That is because at-ease composer.json has:
"autoload": { "files": [ "src/Functions.php" ] }