Passed
Pull Request — master (#17)
by Mihail
15:10
created

ClientFactoryTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
c 1
b 0
f 1
dl 0
loc 70
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A test_head() 0 5 1
A test_curl_factory() 0 4 1
A test_php_factory() 0 4 1
A test_delete() 0 5 1
A test_psr18_client_create() 0 5 1
A test_put() 0 5 1
A test_get() 0 5 1
A test_patch() 0 5 1
A test_post() 0 5 1
1
<?php
2
3
namespace Tests\Koded\Http\Client;
4
5
use Koded\Http\Client\{ClientFactory, CurlClient, PhpClient};
6
use Koded\Http\Interfaces\{ClientType, HttpMethod};
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @group internet
11
 */
12
class ClientFactoryTest extends TestCase
13
{
14
    const URI = 'https://example.com';
15
16
    public function test_php_factory()
17
    {
18
        $instance = (new ClientFactory(ClientType::PHP))->get(self::URI);
19
        $this->assertInstanceOf(PhpClient::class, $instance);
20
    }
21
22
    public function test_curl_factory()
23
    {
24
        $instance = (new ClientFactory)->get(self::URI);
25
        $this->assertInstanceOf(CurlClient::class, $instance, 'CurlClient is the default');
26
    }
27
28
//    public function test_factory_should_throw_exception_for_unknown_client()
29
//    {
30
//        $this->expectException(InvalidArgumentException::class);
31
//        $this->expectExceptionMessage('4 is not a valid HTTP client');
32
//        (new ClientFactory(4))->get('localhost');
33
//    }
34
35
    public function test_get()
36
    {
37
        $client = (new ClientFactory)->get(self::URI, []);
38
//        $this->assertSame(Request::GET, $client->getMethod());
39
        $this->assertSame(HttpMethod::GET->value, $client->getMethod());
40
    }
41
42
    public function test_post()
43
    {
44
        $client = (new ClientFactory)->post(self::URI, []);
45
//        $this->assertSame(Request::POST, $client->getMethod());
46
        $this->assertSame(HttpMethod::POST->value, $client->getMethod());
47
    }
48
49
    public function test_put()
50
    {
51
        $client = (new ClientFactory)->put(self::URI, []);
52
//        $this->assertSame(Request::PUT, $client->getMethod());
53
        $this->assertSame(HttpMethod::PUT->value, $client->getMethod());
54
    }
55
56
    public function test_head()
57
    {
58
        $client = (new ClientFactory)->head(self::URI, []);
59
//        $this->assertSame(Request::HEAD, $client->getMethod());
60
        $this->assertSame(HttpMethod::HEAD->value, $client->getMethod());
61
    }
62
63
    public function test_patch()
64
    {
65
        $client = (new ClientFactory)->patch(self::URI, []);
66
//        $this->assertSame(Request::PATCH, $client->getMethod());
67
        $this->assertSame(HttpMethod::PATCH->value, $client->getMethod());
68
    }
69
70
    public function test_delete()
71
    {
72
        $client = (new ClientFactory)->delete(self::URI, []);
73
//        $this->assertSame(Request::DELETE, $client->getMethod());
74
        $this->assertSame(HttpMethod::DELETE->value, $client->getMethod());
75
    }
76
77
    public function test_psr18_client_create()
78
    {
79
        $client = (new ClientFactory)->client();
80
        $this->assertSame('HEAD', $client->getMethod());
81
        $this->assertEmpty((string)$client->getUri());
82
    }
83
}
84