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. 10 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 Modifiers Object type Summary Overriden Title
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
@dataProvider providerTestCreateFromOptions
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
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.
UnitTestCase::$root protected property The app root.
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

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