Commit graph

13 commits

Author SHA1 Message Date
jenkins-bot
7289075661 Merge "Avoid mentioning tests/phpunit.php in documentation" 2023-07-24 16:32:47 +00:00
Daimona Eaytoy
3b32e90931 phpunit: Improve PHPUnit bootstrap files
- Remove display_errors override. This was copied from the Maintenance
  class in Id6d7e9db, but it's unnecessary here because we configure
  PHPUnit to fail if a PHP notice/warning is emitted. This causes the
  warning/notice to be converted to a failed assertion handled by
  PHPUnit.
- Remove code that turned off output buffering, also copied from
  Maintenance. I'd say it's unlikely for output buffering to enabled at
  that point, and most importantly, we would enable output buffering a
  bit later anyway.
- Call ob_start earlier, so that it also works for anything that prints
  messages even before dataProviders are run (e.g., setup or
  bootstrap code).
- Move the ob_start call to the common bootstrap, as unit tests are
  still affected by the same issue that the call aimed to fix.
- Print the PHP version immediately, and do that for unit tests too.
- Get rid of MediaWikiCliOptions in favour of private code in
  MediaWikiIntegrationTestCase, which is the only class supposed to
  access those settings.
- Set wgCommandLineMode in the common bootstrap. Assume that nobody is
  changing its value randomly in config files because that'd be
  ill-advised.
- Inline code for setting memory_limit and max_execution_time, and run
  it only after loading the settings. Doing that earlier is pointless,
  because these values are already set in suite.xml.
- Update obsolete comment mentioning PHPUnitMaintClass, which is long
  gone. In the current code, this is the only way (besides PHPUnit
  hooks/events) to run code before PHP exits. Also remove the second
  part because we're now on PHPUnit 9, so this should be actionable now.
  Remove link to the PHPUnit documentation as it no longer works. There
  doesn't seem to be an equivalent link for PHPUnit 9, perhaps because
  hooks were replaced with events. There //is// an equivalent link in
  the PHPUnit 10 documentation (for events), but we're not yet using it.

Change-Id: I79bbbfcfe4eab3ff5ae81b2deb6450ba06ad7611
2023-07-13 00:46:13 +02:00
Daimona Eaytoy
d2a30096f1 phpunit: Deprecate tests/phpunit/phpunit.php script
`composer phpunit:entrypoint` should be used instead. Copy all the
setup to a new bootstrap file, with some adjustments for the bootstrap
not being in the global scope when PHPUnit loads it.

Leave the old script and bootstrap in place (e.g., for CI), but make
them print deprecation warnings.

Update the composer scripts to use the standard `phpunit` entrypoint.

The bootstrap code was copied almost verbatim from the phpunit.php
entrypoint to minimize changes. Any improvements can be done in other
patches.

Bug: T90875
Change-Id: I95a80c44f8d88c3c498efe1ae64008f0ff1eea55
2023-07-12 19:28:39 +00:00
Daimona Eaytoy
01cd57267c Avoid mentioning tests/phpunit.php in documentation
The script should never be used directly, to allow an easier migration
to vendor/bin/phpunit.

Bug: T90875
Change-Id: I8d0c4c3a9007d50f39a6bef37a0db62fe83de4d7
2023-07-02 17:35:17 +02:00
Lucas Werkmeister (WMDE)
acae1c5107 Revert "phpunit: Default to vendor/bin/phpunit, remove suites.xml"
This caused unexpected problems with no obvious fixes. Needs more work.

This reverts commit 7238dff532.

Bug: T310255
Bug: T90875
Change-Id: I3758cbb6d0029b20ec1b0f67dbf2f422031c50ae
2022-06-09 14:15:54 +00:00
Kosta Harlan
7238dff532 phpunit: Default to vendor/bin/phpunit, remove suites.xml
* switch to phpunit.xml.dist instead of suites.xml
* switch composer.json to vendor/bin/phpunit
  * tests/phpunit/phpunit.php is retained but will be removed after CI
    jobs and other references on
    codesearch (https://codesearch.wmcloud.org/search/?q=tests%2Fphpunit%2Fphpunit.php&i=nope&files=&excludeFiles=&repos=)
    are removed
* add a default bootstrap.integration.php; unit tests in
  composer.json use the non-MW bootstrap file (bootstrap.php)
  * Migrate the phpunit.php logic into tests/phpunit/BootstrapIntegrationWrapper.php

Depends-On: I19d560bdcdb2ee914ab055e094841f2b5db8be55
Depends-On: Ib23209fc3b095e3c012ed84ce5c11f8b2d27b898
Co-authored-by: Daimona Eaytoy <daimona.wiki@gmail.com>
Bug: T227900
Bug: T90875
Change-Id: I82045c207738d152d5b0006f353637cfaa40bb66
2022-06-08 18:31:16 +00:00
Daimona Eaytoy
75150e1e4e phpunit: Remove or inline phpunit.php loadSettings() and fatalError()
Bug: T90875
Change-Id: I4c78e91ee7fbd4a4a0ffd36d02856f06d6335a00
2022-03-31 18:49:18 +00:00
Daimona Eaytoy
204776e42c phpunit: Remove custom MediaWikiPHPUnitCommand and use default directly
Move the relevant options to the config file instead, and add some hacky
code to force that config file if none was passed. "--help" works even
without the previous hack.

Bug: T90875
Change-Id: I84421e3eeaad0f88be83477cb99d6524abe13b77
2022-03-31 17:58:41 +00:00
Alexander Vorwerk
296b485d9a Add deprecation warnings to wfLogProfilingData()
The logic has been moved to the MediaWiki class in If78c37046cf86.

Bug: T292269
Bug: T292253
Change-Id: I563c6529fc045c2ce3c2d67ba17ae31a388901dd
2021-11-17 21:58:45 +00:00
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +01:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Max Semenik
fb06e4cd85 Update tests to use PHPUnit 6 class names
Bug: T192167
Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
2019-10-06 01:01:28 -07:00
Kosta Harlan
214750d8d2 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
2019-06-28 12:18:18 -04:00