You are here

public function SettingsHelperTest::testPingUri in Acquia Lift Connector 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/Service/Helper/SettingsHelperTest.php \Drupal\Tests\acquia_lift\Unit\Service\Helper\SettingsHelperTest::testPingUri()

Tests the pingUri() method.

@covers ::pingUri

@dataProvider providerTestPingUri

Parameters

string $test_value:

boolean $expected:

File

tests/src/Unit/Service/Helper/SettingsHelperTest.php, line 262

Class

SettingsHelperTest
SettingsHelper Test.

Namespace

Drupal\Tests\acquia_lift\Unit\Service\Helper

Code

public function testPingUri($test_value, $expected) {
  $response = $this
    ->prophesize(\Psr\Http\Message\ResponseInterface::class);
  $response
    ->getStatusCode()
    ->willReturn($expected['statusCode']);
  $response
    ->getReasonPhrase()
    ->willReturn($expected['reasonPhrase']);
  $client = $this
    ->prophesize(\GuzzleHttp\Client::class);
  $client
    ->get($test_value[1], [
    'http_errors' => false,
  ])
    ->willReturn($response
    ->reveal());
  $clientFactory = $this
    ->prophesize(\Drupal\Core\Http\ClientFactory::class);
  $clientFactory
    ->fromOptions(\Prophecy\Argument::any())
    ->willReturn($client
    ->reveal());
  $container = $this
    ->prophesize(\Drupal\Core\DependencyInjection\ContainerBuilder::class);
  $container
    ->get('http_client_factory')
    ->willReturn($clientFactory
    ->reveal());
  \Drupal::setContainer($container
    ->reveal());
  $result = SettingsHelper::pingUri($test_value[0], $test_value[1]);
  $this
    ->assertEquals($expected, $result);
}