Completed
Pull Request — master (#594)
by Andreas
03:19
created

HttpClientsFactoryTest::httpClientsProvider()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 2
eloc 12
nc 2
nop 0
dl 0
loc 17
rs 9.4285
c 2
b 1
f 1
1
<?php
2
/**
3
 * Copyright 2016 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
namespace Facebook\Tests\HttpClients;
25
26
use Facebook\HttpClients\FacebookCurlHttpClient;
27
use Facebook\HttpClients\FacebookGuzzleHttpClient;
28
use Facebook\HttpClients\FacebookStreamHttpClient;
29
use Facebook\HttpClients\HttpClientsFactory;
30
use GuzzleHttp\Client;
31
use PHPUnit_Framework_TestCase;
32
33
class HttpClientsFactoryTest extends PHPUnit_Framework_TestCase
34
{
35
    const COMMON_NAMESPACE = 'Facebook\HttpClients\\';
36
    const COMMON_INTERFACE = 'Facebook\HttpClients\FacebookHttpClientInterface';
37
38
    /**
39
     * @param mixed  $handler
40
     * @param string $expected
41
     *
42
     * @dataProvider httpClientsProvider
43
     */
44
    public function testCreateHttpClient($handler, $expected)
45
    {
46
        $httpClient = HttpClientsFactory::createHttpClient($handler);
47
48
        $this->assertInstanceOf(self::COMMON_INTERFACE, $httpClient);
49
        $this->assertInstanceOf($expected, $httpClient);
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    public function httpClientsProvider()
56
    {
57
        $clients = [
58
          ['guzzle', self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'],
59
          ['stream', self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'],
60
          [new Client(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'],
61
          [new FacebookGuzzleHttpClient(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'],
62
          [new FacebookStreamHttpClient(), self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'],
63
          [null, self::COMMON_INTERFACE],
64
        ];
65
        if (extension_loaded('curl')) {
66
            $clients[] = ['curl', self::COMMON_NAMESPACE . 'FacebookCurlHttpClient'];
67
            $clients[] = [new FacebookCurlHttpClient(), self::COMMON_NAMESPACE . 'FacebookCurlHttpClient'];
68
        }
69
70
        return $clients;
71
    }
72
}
73