Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Http / ClientFactoryTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Http;
4
5 use Drupal\Core\Http\ClientFactory;
6 use Drupal\Core\Site\Settings;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * @coversDefaultClass \Drupal\Core\Http\ClientFactory
11  * @group Http
12  */
13 class ClientFactoryTest extends UnitTestCase {
14
15   /**
16    * The client factory under test.
17    *
18    * @var \Drupal\Core\Http\ClientFactory
19    */
20   protected $factory;
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     $stack = $this->getMockBuilder('GuzzleHttp\HandlerStack')
27       ->disableOriginalConstructor()
28       ->getMock();
29     $this->factory = new ClientFactory($stack);
30   }
31
32   /**
33    * @covers ::fromOptions
34    * @dataProvider providerTestCreateFromOptions
35    *
36    * @param array $settings_config
37    * @param array $parameter_config
38    * @param array $expected_config_keys
39    */
40   public function testCreateFromOptions($settings_config, $parameter_config, $expected_config_keys) {
41     if ($settings_config) {
42       new Settings(['http_client_config' => $settings_config]);
43     }
44     else {
45       new Settings([]);
46     }
47
48     $client = $this->factory->fromOptions($parameter_config);
49
50     foreach ($expected_config_keys as $key => $expected) {
51       $this->assertSame($expected, $client->getConfig($key));
52     }
53   }
54
55   /**
56    * Data provider for testCreateFromOptions
57    *
58    * @return array
59    */
60   public function providerTestCreateFromOptions() {
61     return [
62       [[], [], ['verify' => TRUE, 'timeout' => 30]],
63       [['timeout' => 40], [], ['verify' => TRUE, 'timeout' => 40]],
64       [[], ['timeout' => 50], ['verify' => TRUE, 'timeout' => 50]],
65       [['timeout' => 40], ['timeout' => 50], ['verify' => TRUE, 'timeout' => 50]],
66     ];
67   }
68
69 }