Skip to content

Commit b89652b

Browse files
lancewillettarshidkv12
authored andcommitted
Tests: Run the streams transport tests without live external HTTP.
The HTTP transport tests chose a transport with the `use_{$transport}_transport` filters, which only `WP_Http_Curl::test()` and `WP_Http_Streams::test()` read. `WP_Http::request()` passes requests to Requests, which picked cURL, so `Tests_HTTP_streams` was running on cURL. Set the Requests transport for each test class instead, and move the streams tests out of the external-http group. Follow-up to [65320]. Developed in: WordPress#15787 Props shailu25. See #63914. git-svn-id: https://develop.svn.wordpress.org/trunk@65333 602fd350-edb4-49c9-b593-d223f7449a82
1 parent eb79078 commit b89652b

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎tests/phpunit/tests/http/base.php‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,10 @@ public function set_up() {
299299
$this->markTestSkipped( sprintf( 'The transport %s is not supported on this system.', $this->transport ) );
300300
}
301301

302-
// Disable all transports aside from this one.
303-
foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) {
304-
remove_filter( "use_{$t}_transport", '__return_false' ); // Just strip them all...
305-
if ( $t !== $this->transport ) {
306-
add_filter( "use_{$t}_transport", '__return_false' ); // ...and add it back if need be.
307-
}
308-
}
302+
// WP_Http::request() uses Requests directly; force the transport this
303+
// subclass is meant to cover. The empty() check leaves tests that set
304+
// their own transport (e.g. the parent-domain cookie mock) alone.
305+
add_action( 'requests-requests.before_request', array( $this, 'force_requests_transport' ), 10, 5 );
309306

310307
if ( self::$file_stream_fixture_url ) {
311308
$this->file_stream_url = self::$file_stream_fixture_url;
@@ -975,6 +972,27 @@ public function test_parent_domain_cookie_is_sent_on_redirect() {
975972
$this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
976973
}
977974

975+
/**
976+
* Forces Requests to use the transport this subclass is covering.
977+
*
978+
* The legacy use_{$t}_transport filters are only consulted by
979+
* WP_Http_Curl::test() / WP_Http_Streams::test(). Requests picks its own
980+
* transport unless options['transport'] is set.
981+
*
982+
* @param string $url Request URL.
983+
* @param array $headers Request headers.
984+
* @param string|array $data Request data.
985+
* @param string $type HTTP method.
986+
* @param array $options Request options (passed by reference).
987+
*/
988+
public function force_requests_transport( $url, $headers, $data, $type, &$options ) {
989+
if ( empty( $options['transport'] ) ) {
990+
$options['transport'] = 'curl' === $this->transport
991+
? \WpOrg\Requests\Transport\Curl::class
992+
: \WpOrg\Requests\Transport\Fsockopen::class;
993+
}
994+
}
995+
978996
/**
979997
* Injects the parent-domain cookie test transport into Requests options.
980998
*

‎tests/phpunit/tests/http/streams.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
/**
66
* @group http
7-
* @group external-http
7+
*
8+
* @ticket 63914
89
*/
910
class Tests_HTTP_streams extends WP_HTTP_UnitTestCase {
1011
public $transport = 'streams';

0 commit comments

Comments
 (0)