You are here

public function BrowserTestBaseTest::testGetHttpClient in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest::testGetHttpClient()

@covers ::getHttpClient

File

core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php, line 40

Class

BrowserTestBaseTest
@coversDefaultClass \Drupal\Tests\BrowserTestBase @group Test

Namespace

Drupal\Tests\Core\Test

Code

public function testGetHttpClient() {

  // Our stand-in for the Guzzle client object.
  $expected = new \stdClass();
  $browserkit_client = $this
    ->getMockBuilder(DrupalTestBrowser::class)
    ->setMethods([
    'getClient',
  ])
    ->getMockForAbstractClass();
  $browserkit_client
    ->expects($this
    ->once())
    ->method('getClient')
    ->willReturn($expected);

  // Because the driver is a BrowserKitDriver, we'll get back a client.
  $driver = new BrowserKitDriver($browserkit_client);
  $btb = $this
    ->mockBrowserTestBaseWithDriver($driver);
  $ref_gethttpclient = new \ReflectionMethod($btb, 'getHttpClient');
  $ref_gethttpclient
    ->setAccessible(TRUE);
  $this
    ->assertSame(get_class($expected), get_class($ref_gethttpclient
    ->invoke($btb)));
}