You are here

ClientFactoryTest.php in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Http/ClientFactoryTest.php

File

core/tests/Drupal/Tests/Core/Http/ClientFactoryTest.php
View source
<?php

/**
 * @file
 * Contains \Drupal\Tests\Core\Http\ClientFactoryTest.
 */
namespace Drupal\Tests\Core\Http;

use Drupal\Core\Http\ClientFactory;
use Drupal\Core\Site\Settings;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\Core\Http\ClientFactory
 * @group Http
 */
class ClientFactoryTest extends UnitTestCase {

  /**
   * The client factory under test.
   *
   * @var \Drupal\Core\Http\ClientFactory
   */
  protected $factory;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $stack = $this
      ->getMockBuilder('GuzzleHttp\\HandlerStack')
      ->disableOriginalConstructor()
      ->getMock();
    $this->factory = new ClientFactory($stack);
  }

  /**
   * @covers ::fromOptions
   * @dataProvider providerTestCreateFromOptions
   *
   * @param array $settings_config
   * @param array $parameter_config
   * @param array $expected_config_keys
   */
  public function testCreateFromOptions($settings_config, $parameter_config, $expected_config_keys) {
    if ($settings_config) {
      new Settings([
        'http_client_config' => $settings_config,
      ]);
    }
    else {
      new Settings([]);
    }
    $client = $this->factory
      ->fromOptions($parameter_config);
    foreach ($expected_config_keys as $key => $expected) {
      $this
        ->assertSame($expected, $client
        ->getConfig($key));
    }
  }

  /**
   * Data provider for testCreateFromOptions
   *
   * @return array
   */
  public function providerTestCreateFromOptions() {
    return [
      [
        [],
        [],
        [
          'verify' => TRUE,
          'timeout' => 30,
        ],
      ],
      [
        [
          'timeout' => 40,
        ],
        [],
        [
          'verify' => TRUE,
          'timeout' => 40,
        ],
      ],
      [
        [],
        [
          'timeout' => 50,
        ],
        [
          'verify' => TRUE,
          'timeout' => 50,
        ],
      ],
      [
        [
          'timeout' => 40,
        ],
        [
          'timeout' => 50,
        ],
        [
          'verify' => TRUE,
          'timeout' => 50,
        ],
      ],
    ];
  }

}

Classes

Namesort descending Description
ClientFactoryTest @coversDefaultClass \Drupal\Core\Http\ClientFactory @group Http