You are here

public function BrowserTestBaseTest::testGetHttpClient in Drupal 8

Same name and namespace in other branches
  1. 9 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(Client::class)
    ->setMethods([
    'getClient',
  ])
    ->getMockForAbstractClass();
  $browserkit_client
    ->expects($this
    ->once())
    ->method('getClient')
    ->willReturn($expected);

  // Because the driver is a GoutteDriver, we'll get back a client.
  $driver = $this
    ->getMockBuilder(GoutteDriver::class)
    ->setMethods([
    'getClient',
  ])
    ->getMock();
  $driver
    ->expects($this
    ->once())
    ->method('getClient')
    ->willReturn($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)));
}