wiki.techinc.nl/tests/phpunit/unit/includes/Rest
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
..
BasicAccess REST: introduce getPrivateRouteUrl 2022-07-14 13:12:35 +00:00
Handler Make it possible to override the session in REST API tests 2023-02-06 18:56:51 +01:00
HeaderParser tests: Remove @param docs from test code that just repeat the signature 2021-01-21 03:41:23 +00:00
PathTemplateMatcher
Validator Tests: add ObjectFactory to DummyServicesTrait 2023-01-23 19:35:50 +00:00
ConditionalHeaderUtilTest.php ConditionalHeaderUtil: Handle If-None-Match: * 2022-10-07 09:06:04 +00:00
CorsUtilsTest.php unit tests: Use MainConfigNames constant to refer configs 2022-08-17 22:33:58 +02:00
HeaderContainerTest.php Use short array destructuring instead of list() 2022-10-21 15:33:37 +11:00
ResponseFactoryTest.php REST: Hide exception message when wgShowExceptionDetails=false 2022-05-26 14:45:50 +01:00
RestTestTrait.php Make it possible to override the session in REST API tests 2023-02-06 18:56:51 +01:00
RouterTest.php REST: introduce getPrivateRouteUrl 2022-07-14 13:12:35 +00:00
SessionHelperTestTrait.php Make it possible to override the session in REST API tests 2023-02-06 18:56:51 +01:00
StringStreamTest.php tests: Swap assertion order in unit tests 2021-08-04 20:21:01 +02:00
testAdditionalRoutes.json
testRoutes.json REST: gracefully handle all exceptions. 2021-11-02 20:33:13 +01:00
TokenAwareHandlerTraitTest.php Rest: Add helper method for validating the CSRF token 2023-02-01 22:39:24 -08:00