Page MenuHomePhabricator

Add a test-friendly entry point mechanism to MediaWiki
Closed, DeclinedPublic

Description

We define entry points by doing something like define( 'MW_ENTRY_POINT', 'index' ) in the entry point file, and check with if ( MW_ENTRY_POINT === 'index' ). This makes the logic untestable since there is no way to undefine or change a constant (short of using process isolation, which comes with its own drawbacks). We should have a trivial service for checking the entry point, which can be mocked during tests.

Event Timeline

Change #1087923 had a related patch set uploaded (by D3r1ck01; author: Derick Alangi):

[mediawiki/core@master] exception: Use OutputPage rendering in PHPUnit test environment

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

I think we already have MW_PHPUNIT_TEST for this and we can just use that.

Change #1087937 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/core@master] [WIP] Add an override mechanism for entry point checks.

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

The PR @Tgr introduced made me wonder again - can we have a place where can store request-based state? We decided not to keep any state in MediaWikiServices (T218555). We have to god class RequestContext - and every time I see it, I want to get rid of it.

I think (sorry, it's a bit late and I may be not making sense ) how bad would it be to introduce something like MediaWikiState, a container that would hold everything that is state or request-based. Having such would simplify code this, or projects like Telemetry.

The more I think about it, the more I think that even RequestContext could be just container with set of factories/services.

Change #1087937 abandoned by Gergő Tisza:

[mediawiki/core@master] Add an override mechanism for entry point checks

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

matmarex added subscribers: Krinkle, matmarex.

Per discussion on the patch, particularly @Krinkle's comment here: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1087937/comments/025ac4d8_5ab8220c it seems that this isn't strictly necessary to allow unit testing, and we'd rather not complicate these checks further.

Change #1087923 abandoned by Bartosz Dziewoński:

[mediawiki/core@master] exception: Use OutputPage rendering in PHPUnit test environment

Reason:

As far as I can tell, this is no longer needed, per discussion on the other patches.

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