This follows the same approach as MWHttpRequest, we inject
$wgLocalVirtualHosts, and for each request check whether it matches that
domain list, rewriting the request as necessary.
Unfortunately this requires a decent amount of code duplication because
MultiHttpClient is in includes/libs/ and can't depend on the same code
in MWHttpRequest.
Bug: T288848
Change-Id: Ia16d8f86b1cb20dde9fe487729d67d92af650cfe
With mocking HTTP, we can supply an array of requests
to expect, but if MultiHttpClient or Guzzle client are
used, we can only supply one. Now we can mock a sequence
of requests done via either of these clients.
Change-Id: I350ed59af603a0504704af3265787a4be8f2dc2a
Two enhancements:
1. If the status code of the mocked response is >= 400,
the Status object returned by the mock request should actually
be fatal, not good.
2. Convenience method to create a mock request that will
result in a timeout response, compatible with real timeout.
Change-Id: I4c3aab6ab88695729b4f398dacf3575fbdb4dad4
The signatures of these methods will change in PHPUnit 9, and in
general, having these methods means additional code to maintain. Since
this is test code, any attempt to use these traits from a class which
doesn't have the required methods will fail hard, and as such, there's
no reason to have these methods at all.
Also, MockServiceDependenciesTrait was redeclaring fail() as a
non-static method, but it is actually static in the parent class, which
makes tests fail on PHP 8.
Bug: T243600
Change-Id: I78bf1bdd2eb2e09aed27d1b6bff2302e28600703
If we directly pass [ TestCase::class, 'fail' ] as the callback for a
mock method, then the method will be called with whatever arguments the
caller tried to pass to the original method. Those arguments may not be
compatible with TestCase::fail()’s signature, which requires the first
argument to be a string (or absent). Use a custom callback first which
throws away any arguments before calling TestCase::fail().
Bug: T272998
Change-Id: I3514d3d29355a55a5ca10ccc22981e3972347f35
Don’t fail the test immediately when createMultiClient() or
createGuzzleClient() is called – instead, return service instances that
will fail the test as soon as any method is called on them. This is a
bit friendlier for dependency injection.
Bug: T272998
Change-Id: I79f90ef028867920f6a228991eda59ed4aeadb62
Per I1702c11928f8760, tests should fail when trying to make a
HTTP request, unless they have explicitely defined the desired
response.
This patch implements the same behavior for the newly introduced
createGuzzleClient() method.
Bug: T263816
Bug: T262443
Change-Id: Ie3c2efb1387ecc5bc29ff1749cae4bb33e636e9f
MockHttpTrait can be used by tests that need to simulate HTTP requests.
Bug: T262443
Needed-By: I1832cb1858ef4cf42ec34cb7fda509ce5b951c27
Needed-By: I390856b4609635cee22253071f21ce63ff716791
Needed-By: Iff24b55dfaf7a4e02a4c80aaeaf0366de5660ef1
Needed-By: Ia8213725839e4b697c4985060bc35593fea622bc
Change-Id: I8ce17da7315b87b8dd0e502e601b9ac488089456