You are here

public function ResourceFetcherTest::testFetchTimeout in Drupal 10

Same name and namespace in other branches
  1. 9 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\Unit

Code

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);
}