public function ResourceFetcherTest::testFetchTimeout in Drupal 9
Same name and namespace in other branches
- 10 core/modules/media/tests/src/Unit/ResourceFetcherTest.php \Drupal\Tests\media\Unit\ResourceFetcherTest::testFetchTimeout()
Tests that resources are fetched with a hard-coded timeout.
File
- core/
modules/ media/ tests/ src/ Unit/ ResourceFetcherTest.php, line 26
Class
- ResourceFetcherTest
- @group media
Namespace
Drupal\Tests\media\UnitCode
public function testFetchTimeout() : void {
$url = 'https://example.com/oembed?url=resource';
$headers = [
'Content-Type' => [
'text/javascript',
],
];
$body = Json::encode([
'version' => '1.0',
'type' => 'video',
'html' => 'test',
]);
$response = new Response(200, $headers, $body);
$client = $this
->prophesize(Client::class);
$client
->request('GET', $url, [
RequestOptions::TIMEOUT => 5,
])
->shouldBeCalled()
->willReturn($response);
$fetcher = new ResourceFetcher($client
->reveal(), $this
->createMock('\\Drupal\\media\\OEmbed\\ProviderRepositoryInterface'), new NullBackend('default'));
$fetcher
->fetchResource($url);
}