class ClientFactoryTest

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Http/ClientFactoryTest.php \Drupal\Tests\Core\Http\ClientFactoryTest
  2. 8.9.x core/tests/Drupal/Tests/Core/Http/ClientFactoryTest.php \Drupal\Tests\Core\Http\ClientFactoryTest
  3. 11.x core/tests/Drupal/Tests/Core/Http/ClientFactoryTest.php \Drupal\Tests\Core\Http\ClientFactoryTest

@coversDefaultClass \Drupal\Core\Http\ClientFactory
@group Http

Hierarchy

Expanded class hierarchy of ClientFactoryTest

File

core/tests/Drupal/Tests/Core/Http/ClientFactoryTest.php, line 15

Namespace

Drupal\Tests\Core\Http
View source
class ClientFactoryTest extends UnitTestCase {
  
  /**
   * The client factory under test.
   *
   * @var \Drupal\Core\Http\ClientFactory
   */
  protected $factory;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $stack = $this->getMockBuilder('GuzzleHttp\\HandlerStack')
      ->disableOriginalConstructor()
      ->getMock();
    $this->factory = new ClientFactory($stack);
  }
  
  /**
   * @covers ::fromOptions
   * @dataProvider providerTestCreateFromOptions
   *
   * @param array $settings_config
   *   The settings configuration.
   * @param array $parameter_config
   *   The parameter configuration.
   * @param array $expected_config_keys
   *   The expected config keys.
   */
  public function testCreateFromOptions($settings_config, $parameter_config, $expected_config_keys) : void {
    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 static 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,
        ],
      ],
    ];
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
ClientFactoryTest::$factory protected property The client factory under test.
ClientFactoryTest::providerTestCreateFromOptions public static function Data provider for testCreateFromOptions.
ClientFactoryTest::setUp protected function Overrides UnitTestCase::setUp
ClientFactoryTest::testCreateFromOptions public function @covers ::fromOptions[[api-linebreak]]
@dataProvider providerTestCreateFromOptions
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.