wiki.techinc.nl/tests/phpunit/mocks
Daimona Eaytoy 19f8127ef0 Make it possible to override the session in REST API tests
The current signature of the various execute methods only takes a
boolean parameter to determine if the session should be safe against
CSRF, but that does not give callers fine-grained control over the
Session object, including setting a specific token.

Also, do not use createNoOpMock in getSession(), since it implies
strong assertions on what methods are called. This way, getSession
can also be used to get a simple mock session that tests may further
manipulate.

Make $csrfSafe parameter of SessionHelperTestTrait::getSession
mandatory. This way, callers are forced to think what makes sense in
each use case. The various methods in HandlerTestTrait now default to
a session that is safe against CSRF. This assumes that most REST
handlers don't care about the session, and that any handler that does
care about the session and where someone needs to test the behaviour
in case of bad/missing token will explicitly provide a Session that
is NOT safe against CSRF.

Typehint the return value of Session(Backend)::getUser so that PHPUnit
will automatically make it return a mock User object even if the method
is not explicitly mocked. Remove a useless PHPUnit assertion -- setting
the return value to be X and then veryfing that is equal to X is a
tautology, and can only fail if the test itself is flawed (as was the
case, since it was using stdClass as the return type for all
methods). Remove the getUser test case altogether, there's no way to
make it work given the DummySessionBackend, and the test isn't that
helpful anyway. More and more methods will have the same issue as soon
as their return value is typehinted.

Follow-up: I2a9215bf909b83564247ded95ecdb4ead0615150
Change-Id: Ic51dc3e7bf47c81f2ac4705308bb9ecd8275bbaf
2023-02-06 18:56:51 +01:00
..
content tests: Handle dynamic created properties on test classes 2023-01-13 21:03:42 +00:00
filebackend
filerepo
json JsonCodec: fix en/decoding of nested objects and stdClass objects 2023-01-12 14:12:32 -05:00
languages Language: Turn public properties into Getters in LanguageConverter based hierarchy 2021-02-03 15:17:42 +02:00
media
permissions DeletePage: add option to delete the associated talk page 2022-01-11 14:48:56 +01:00
poolcounter
search tests: Handle dynamic created properties on test classes 2023-01-13 21:03:42 +00:00
session Make it possible to override the session in REST API tests 2023-02-06 18:56:51 +01:00
DummyServicesTrait.php Tests: add LanguageNameUtils to DummyServicesTrait 2023-02-02 20:50:48 +00:00
GhostFieldTestClass.php tests: Allow dynamic properties on PHP 8.2 for GhostFieldTestClass 2023-01-06 03:06:06 +01:00
MockChangesListFilter.php
MockChangesListFilterGroup.php
MockHttpTrait.php Use MainConfigNames instead of string literals, #5 2022-04-27 18:46:29 +03:00
MockMessageLocalizer.php
MockServiceDependenciesTrait.php phpunit: Don't redefine methods in traits 2021-03-23 12:59:34 +00:00
MockTitleTrait.php Set page id to 0 for pages in virtual namespaces 2022-03-10 20:12:27 +00:00
NullGuzzleClient.php Use mock Guzzle client during tests 2022-01-18 13:14:51 +11:00
NullHttpRequestFactory.php Use MainConfigNames instead of string literals, #5 2022-04-27 18:46:29 +03:00
NullMultiHttpClient.php Use native array_column() in tests instead of loops 2022-08-16 15:41:14 +02:00
TestLocalisationCache.php Use MainConfigNames instead of string literals, #5 2022-04-27 18:46:29 +03:00
TestLogger.php Remove unused default values from class properties 2021-05-12 13:44:28 +02:00