wiki.techinc.nl/tests/phpunit/mocks/NullMultiHttpClient.php
Thiemo Kreuz 68ec2661d2 Use native array_column() in tests instead of loops
It's just a nice, lesser known convenience function. Exists since
PHP 5.5.

The changes to SerializationTestTrait ended being a little different.
Original I tried to use array_column() as well. But it drops the
array keys, which is relevant here.

We found that calling the two methods getTestInstances(AndAssertions)
multiple times is quite expensive and should be avoided. I changed
the code slightly so it's much less likely this is done unintentionally.

Change-Id: Ifaba3c370871a7c97b4d81ec21ff6ec134433fc0
2022-08-16 15:41:14 +02:00

30 lines
745 B
PHP

<?php
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\AssertionFailedError;
/**
* A simple {@link MultiHttpClient} implementation that can be used to prevent
* HTTP requests in tests. All attempts to execute a request will fail.
*
* Use MockHttpTrait for controlling responses to mock HTTP requests.
*
* @author Daniel Kinzler
* @license GPL-2.0-or-later
*/
class NullMultiHttpClient extends MultiHttpClient {
/**
* Always fails.
*
* @param array $reqs
* @param array $opts
*
* @throws AssertionFailedError always
*/
public function runMulti( array $reqs, array $opts = [] ) {
$urls = implode( ', ', array_column( $reqs, 'url' ) );
Assert::fail( "HTTP requests to {$urls} blocked. Use MockHttpTrait." );
}
}