Page MenuHomePhabricator

Convert tests/phpunit/phpunit.php entrypoint to plain PHPUnit with bootstrap file
Open, LowPublic

Description

Currently, core tests cannot be run by running the phpunit command directly. Instead, we have a custom entrypoint that wraps PHPUnit and calls it programmatically from tests/phpunit/phpunit.php.

We should convert all our logic in the wrapper to a PHPUnit bootstrap file, so that we (and other automated tools) can start PHPUnit through the regular entry point.

Event Timeline

JanZerebecki raised the priority of this task from to Needs Triage.
JanZerebecki updated the task description. (Show Details)
JanZerebecki added a subscriber: JanZerebecki.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 26 2015, 3:08 PM
Aklapper triaged this task as Lowest priority.Feb 27 2015, 11:00 AM
Krinkle moved this task from Inbox to PHPUnit on the MediaWiki-Core-Testing board.Jul 7 2017, 5:17 AM
thiemowmde closed this task as Declined.Dec 7 2017, 3:52 PM
Legoktm reopened this task as Open.Dec 7 2017, 5:23 PM
Legoktm added a project: Technical-Debt.
Legoktm added a subscriber: Legoktm.

This is still something we should do at some point, so we can move to the normal way of running PHPUnit instead of our special thing.

Krinkle renamed this task from move from tests/phpunit/phpunit.php to plain phpunit with bootstrap file to Convert tests/phpunit/phpunit.php entrypoint to plain PHPUnit with bootstrap file.Jan 30 2018, 7:17 PM
Krinkle raised the priority of this task from Lowest to Low.
Krinkle awarded a token.
Krinkle updated the task description. (Show Details)
Krinkle added a subscriber: Krinkle.
kostajh added a subscriber: kostajh.

I hacked around a bit this morning. My goal was to be able to run unit (databaseless) tests on my host, via PhpStorm's PHPUnit run configuration. I was able to get to a pretty-close-to-working state for tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php -- I could click "Run unit tests with coverage" in PhpStorm and have the coverage results imported directly into my editor a few moments later, which was quite nice! :)

There some difficulties getting to this goal though:

  1. Overall there is an assumption in the existing PHPUnit test bootstrapping, and test code (even tests that are not tagged with @group Database), that a database is available and a connection to it exists.
  2. Attempting to work around this in bootstrap.php with a bunch of require_once() is super ugly. Maybe there are utility functions that can help with this that I missed though.
  3. This task might be easier to do once T166010 is done

I may work on this at the hackathon, help welcome :)

Tgr awarded a token.May 15 2019, 5:03 PM

Change 514381 had a related patch set uploaded (by Kosta Harlan; owner: Kosta Harlan):
[mediawiki/core@master] WIP: Use vendor/bin/phpunit for integration and unit test suites

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

Change 514381 abandoned by Kosta Harlan:
WIP: Use vendor/bin/phpunit for integration and unit test suites

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

Change 520316 had a related patch set uploaded (by Kosta Harlan; owner: Kosta Harlan):
[mediawiki/core@master] Bring parser tests suite from suite.xml to phpunit.xml.dist

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

Existing test suites on suite.xml:

<testsuites>
		<testsuite name="includes">
			<directory>includes</directory>
		</testsuite>
		<testsuite name="languages">
			<directory>languages</directory>
		</testsuite>
		<testsuite name="parsertests">
			<file>suites/CoreParserTestSuite.php</file>
			<file>suites/ExtensionsParserTestSuite.php</file>
		</testsuite>
		<testsuite name="skins">
			<directory>skins</directory>
			<directory>structure</directory>
			<file>suites/ExtensionsTestSuite.php</file>
			<file>suites/LessTestSuite.php</file>
		</testsuite>
		<!-- As there is a class Maintenance, we cannot use the name "maintenance" directly -->
		<testsuite name="maintenance_suite">
			<directory>maintenance</directory>
		</testsuite>
		<testsuite name="structure">
			<directory>structure</directory>
		</testsuite>
		<testsuite name="tests">
			<directory>tests</directory>
		</testsuite>
		<testsuite name="uploadfromurl">
			<file>suites/UploadFromUrlTestSuite.php</file>
		</testsuite>
		<testsuite name="extensions">
			<directory>structure</directory>
			<file>suites/ExtensionsTestSuite.php</file>
			<file>suites/ExtensionsParserTestSuite.php</file>
			<file>suites/LessTestSuite.php</file>
		</testsuite>
		<testsuite name="documentation">
			<directory>documentation</directory>
		</testsuite>
		<testsuite name="unit">
			<directory>unit</directory>
		</testsuite>
	</testsuites>

In phpunit.xml.dist we currently have two test suites, "unit" (no DB, no global functions) and "integration" (everything else).

A number of the test suites in suite.xml probably don't need to be defined as test suites, for example you could run vendor/bin/phpunit tests/phpunit/includes just as easily as vendor/bin/phpunit --testsuite=includes. So I would propose that we not bring over those types of test suites into phpunit.xml.dist.

We also want to ensure we don't have testsuites defined which result in the same test being run more than once.

Change 560835 had a related patch set uploaded (by Mainframe98; owner: Mainframe98):
[mediawiki/core@master] Add a bootstrap file to run PHPUnit on vagrant through PhpStorm

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

I've uploaded a change that achieves what this task asks for. I originally intended to use it to debug tests using PhpStorm, until I found out that I could use it without PhpStorm too.
If T173899: autoload.ide.php needs to be updated or removed is a concern, I'll gladly volunteer as owner; I am the one using it after all.

Change 560835 abandoned by Mainframe98:
Add a bootstrap file to run PHPUnit on vagrant through PhpStorm

Reason:
xDebug on Vagrant is currently broken; based on Florianschmidtwelzow's feedback, the solution should probably live elsewhere.

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

Change 520316 abandoned by Kosta Harlan:
Bring parser tests suite from suite.xml to phpunit.xml.dist

Reason:
Will come back to this some other time.

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /520316