Commit graph

10 commits

Author SHA1 Message Date
Daimona Eaytoy
7a494d1fa4 tests: Upgrade PHPUnit from 8.5+ to 9.5+
* DeprecatedHooksTest: Don't use assertContains().
* Replace uses of deprecated asserts:
  - assertFileNotExists() -> assertFileDoesNotExist()
* Update hierarchy of MediaWikiPHPUnitResultPrinter, since ResultPrinter
  is an interface in PHPUnit 9.
* Remove temporary forward-compat methods.
* Remove directories that don't exist from tests/phpunit/suite.xml, since
  they now make PHPUnit exit:
   - tests/phpunit/skins, it used to have SideBarTest, then moved to
     tests/phpunit/includes/skins
   - tests/phpunit/documentation, it used to have ReleaseNotesTest, then
     moved to tests/phpunit/unit/documentation
* Update configuration with --migrate-configuration and reformat.
* Avoid redefining getMockBuilder() in
  ActionModuleBasedHandlerTestTrait, use a @method annotation instead.
* In RCCacheEntryFactoryTest, avoid using internal PHPUnit logic for
  HTML validation, and use native PHP methods instead. The code was
  copied from Xml::load (moved to \Xml\Loader::load in PHPUnit 9) and
  simplified for this use case.

Bug: T243600
Bug: T262076
Change-Id: I851b9158b73d0cfc315eed9d63b15c54b05895e3
2022-10-08 02:03:55 +02:00
Timo Tijhof
a05b12a1ce phpunit: Restore default progress reporter and add MWTestDox option
Using TestDox is imho not ideal to use by default:

* Far too noisy as a default, making it difficult to iterate by
  not having previous output nearby.

* The custom "Logs generated" we add for debugging don't actually
  show up, not in the original failure that is buried between success
  mesages, and not in the summary.

  This is imho a requirement both for CI and local dev.

* Test failures are immediately buried and flown past with a lot
  of other information.

Proposal:

* Restore default printer as this commit does, with the previous
  override for adding custom logs.

* Once MWTestDox works correctly per the above, enable it by
  default for CI only, by adding `--printer MWTestDox` to
  phpunit:entrypoint in composer.json, which is basically only
  for use by CI.

  The vendor/bin/php, composer phpunit, and phpunit.php calls,
  and IDE integrations would would remain unaffected.

  One can easily pass `--printer MWTestDox` to bin/phpunit if
  preferred locally, or invoke `composer phpunit:entrypoint -- ...`
  instead at that point.

Bug: T297287
Change-Id: I03391e2da1192156e220819d97ca7d8370199801
2022-06-12 19:22:57 +00:00
Kosta Harlan
5e40a401e9 phpunit: Use customized TestDox output
Switch PHPUnit to use the more verbose TestDox format, which allows
us to see exactly which tests have been executed. This is useful when
making changes to test configuration.

Use the MediaWikiPHPUnitResultPrinter to override the CliTestDoxPrinter
and use the actual class names / test method names, instead of the
prettified versions from TestDox, to improve greppability.

Bug: T297287
Change-Id: I9d8561ff868e6ff0a44d32120f2799b34d25e618
2022-06-05 19:25:50 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Daimona Eaytoy
86c0a64e91 Use PHPUnit hooks for augmented logs
The TestListener interface is deprecated. This replacement has the
downside of using a public static property, but there seems to be no
other way to pass extra data to the printer (BTW: the ResultPrinter
class is internal, so it'd be even better if we could avoid subclassing
it).

Bug: T243600
Change-Id: I083146b7336ac09dfd077c8e6817553738282662
2020-09-22 11:28:10 +00:00
Timo Tijhof
0c910b1684 phpunit: Move "Logs generated by test" from middle to end of result
The previous output meant that when reviewing the build output,
it was quite hard to quickly find what the problem was and in
which test because the start of the result (which mentions the
test suite) and the expected/actual diff, were often separated
by dozens or hundreds of lines of "helpful" debug logs.

These are now moved to the after the expected/actual/stacktrace
portion so that "Name of test" and "expected/actual" remain
together.

Before

> 1) ResourceLoaderFilePathTest::testGetters
> === Logs generated by test case
> …
> …
> …
> …
> …
> …
> …
> ===
> Failed asserting that two strings are identical.
> --- Expected
> +++ Actual
> @@ @@
> -'dummy/pat'
> +'bla'
> /var/mediawiki/tests/phpunit/resourceloader/ResourceLoaderFilePathTest.php:22

After

> 1) ResourceLoaderFilePathTest::testGetters
> Failed asserting that two strings are identical.
> --- Expected
> +++ Actual
> @@ @@
> -'dummy/pat'
> +'bla'
> /var/mediawiki/tests/phpunit/resourceloader/ResourceLoaderFilePathTest.php:22
> === Logs generated by test case
> …
> …
> …
> …
> …
> …
> …
> ===

Change-Id: I31f1a4b730a0dd8597a059034b4e6abdc5f48552
2020-05-22 20:48:28 +01:00
Max Semenik
dd7026585c Backwards-compatible PHPUnit 8 preparations
This commit splits changes from Ic14f5debc53e55d6714 to reduce it to
only strictly needed things. It can be merged immediately.

Bug: T192167
Change-Id: I8c541a66ea13421dbe7fa51d197d5455cc4786eb
2019-11-02 12:40:07 -07: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
Erik Bernhardson
96657099fc Report logs for each individual test failure
The initial implementation of reporting logs with test failures was
incorrect, it always reported the logs of the most recent test run.
Attach logs to the Test when a failure is reported and pull them
back out in the result printer.

Bug: T217489
Change-Id: I5aa55d6fa7a7ec03a2e71636b6b0366ea40605cb
2019-03-06 15:13:53 -08:00
Erik Bernhardson
56ffbc2a4e Print logs generated during unit test when test fails
When a unit test fails it is possible, perhaps even likely in some
cases, that some code that was run logged useful information about
how that failure came to be.

Help people out, tell them what happened!

Change-Id: I30bbc31799a65024868678d052fec9aafacc1aff
2019-02-06 14:43:32 -08:00