Commit graph

5 commits

Author SHA1 Message Date
Bartosz Dziewoński
b2c83a0721 Deprecate $wgCommandLineMode
The global variable is now exactly the same as
`MW_ENTRY_POINT === 'cli'`.

Bug: T313841
Change-Id: I254bf4aa426e4834705be351cc9eb06d18a33f79
2024-01-02 22:21:50 +01:00
Daimona Eaytoy
7e44adf4a9 phpunit: Set the MW_INSTALL_PATH env variable if needed
phpunit.php did that, and also the bootstrap file before
Ie20617ac80d12f99ceaeae53b852cc6ed76b3feb. I was under the impression
that wfDetectInstallPath would also set this variable, but it doesn't --
it only sets $IP and the MW_INSTALL_PATH constant.

So restore the bit of code that sets the env variable, but do that only
in the bootstrap, and not in wfDetectInstallPath, because it's
presumably not needed there.

Change-Id: Icbd718bdea3567fb85d39926bed93af72de60c9b
2023-07-17 15:28:26 +02:00
Daimona Eaytoy
97690990e1 phpunit: More improvements for PHPUnit bootstrap files
- Move handling of PHPUNIT_WIKI to the common bootstrap, the values
  might be needed in integration tests.
- Add method to TestSetup for checking composer.lock, and use it in both
  bootstraps. This cannot be moved to the common bootstrap yet, because
  it needs to run after loading MW.
- In MediaWikiIntegrationTestCase::
  initializeForStandardPhpunitEntrypointIfNeeded, use global $IP instead
  of redefining it.

Bug: T227900
Change-Id: I050dcc36b814abd7b909eaaf6d356ecd0d3a0c80
2023-07-13 00:48:31 +02: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
43015d5d87 phpunit: Simplify PHPUnit bootstrap files
- Consolidate the common parts into a shared bootstrap.common.php file
- Rearrange the code a bit to clarify when certain things (like globals)
  are actually needed.
- Replace the bootstrap class with two global functions, and inline two
  other functions.

This change should be a no-op for both unit and integration tests.

Change-Id: Ie20617ac80d12f99ceaeae53b852cc6ed76b3feb
2023-07-12 20:27:42 +00:00