Define unit and integration test suites
authorKosta Harlan <kharlan@wikimedia.org>
Wed, 26 Jun 2019 02:33:14 +0000 (22:33 -0400)
committerKosta Harlan <kharlan@wikimedia.org>
Fri, 28 Jun 2019 16:18:18 +0000 (12:18 -0400)
commit214750d8d224fc7e79d63536915d0dbba9fe969a
tree9e58ab554a4fddd88a958b7b66a750e0f964dddc
parent1e8a3eff9fbc99841e1b294abbc4184db9c44083
Define unit and integration test suites

Following discussion in Ibb8175981092d7f41864e641cc3c118af70a5c76, this patch
proposes to further reduce the scope of what unit tests may access, by removing
the loading of DefaultSettings and GlobalFunctions.php. This also has the
implied effect of disabling the storage backend, as well as the global service
locator.

MediaWikiTestCase is renamed to MediaWikiIntegrationTestCase so it's scope and
purpose is more clear. Whether we still need to keep `@group Database`
annotation around is debatable, as it's unclear to me what the performance costs
are of implying database access for all tests which extend IntegrationTestCase.
As far as I can tell, `@group Database` is primarily used in CI to run faster
tests before slower ones, and with the new UnitTestCase the annotation seems
redundant.

To run all testsuites, use `composer phpunit`. Other composer scripts:

- `composer phpunit:unit` to run unit tests
- `composer phpunit:integration` to run integration tests
- `composer phpunit:coverage` to generate code coverage reports from unit
   tests (requires XDebug).

Note that you can pass arguments to composer scripts with `--`, e.g. `composer
phpunit:integration --exclude-group Dump`.

Other changes:

- Rename bootstrap.php to bootstrap.maintenance.php so it's clear it's part of
  the legacy PHPUnit-as-maintenance-class setup
- Create new bootstrap.php which loads the minimal configuration necessary for
  the tests, and do additional setup in the run() method of the unit/integration
test case classes
- Move the unit-tests.xml file to phpunit.xml.dist in preparation for this being
  the default test configuration

For a follow-up patch:

- Find unit/integration tests for extensions/skins
- Migrate other test suites from suite.xml
- Support running all tests via vendor/bin/phpunit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76
19 files changed:
.gitattributes
.gitignore
.phpcs.xml
composer.json
includes/DefaultSettings.php
includes/Setup.php
maintenance/findHooks.php
phpunit.xml.dist [new file with mode: 0644]
tests/common/TestsAutoLoader.php
tests/phpunit/MediaWikiIntegrationTestCase.php [new file with mode: 0644]
tests/phpunit/MediaWikiTestCase.php [deleted file]
tests/phpunit/MediaWikiUnitTestCase.php
tests/phpunit/bootstrap.maintenance.php [new file with mode: 0644]
tests/phpunit/bootstrap.php
tests/phpunit/includes/db/DatabaseSqliteTest.php [deleted file]
tests/phpunit/integration/includes/db/DatabaseSqliteTest.php [new file with mode: 0644]
tests/phpunit/suite.xml
tests/phpunit/unit-tests.xml [deleted file]
tests/phpunit/unit/initUnitTests.php [deleted file]