Completed
Push — master ( bd558f...6391f6 )
by WEBEWEB
02:19
created

CURLFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGetInstance() 0 40 2
1
<?php
2
3
/**
4
 * This file is part of the curl-library package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\CURL\Tests\Factory;
13
14
use Exception;
15
use PHPUnit_Framework_TestCase;
16
use WBW\Library\Core\Exception\IO\InvalidHTTPMethodException;
17
use WBW\Library\Core\Network\HTTP\HTTPInterface;
18
use WBW\Library\CURL\Factory\CURLFactory;
19
use WBW\Library\CURL\Request\CURLDeleteRequest;
20
use WBW\Library\CURL\Request\CURLGetRequest;
21
use WBW\Library\CURL\Request\CURLHeadRequest;
22
use WBW\Library\CURL\Request\CURLOptionsRequest;
23
use WBW\Library\CURL\Request\CURLPatchRequest;
24
use WBW\Library\CURL\Request\CURLPostRequest;
25
use WBW\Library\CURL\Request\CURLPutRequest;
26
27
/**
28
 * cURL factory test.
29
 *
30
 * @author webeweb <https://github.com/webeweb/>
31
 * @package WBW\Library\CURL\Factory
32
 * @final
33
 */
34
final class CURLFactoryTest extends PHPUnit_Framework_TestCase {
35
36
    /**
37
     * Tests the getInstance() method.
38
     *
39
     * @return void
40
     */
41
    public function testGetInstance() {
42
43
        // ===
44
        try {
45
46
            CURLFactory::getInstance("exception");
47
        } catch (Exception $ex) {
48
49
            $this->assertInstanceOf(InvalidHTTPMethodException::class, $ex);
50
            $this->assertEquals("The HTTP method \"exception\" is invalid", $ex->getMessage());
51
        }
52
53
        // ===
54
        $res1 = CURLFactory::getInstance(HTTPInterface::HTTP_METHOD_DELETE);
55
        $this->assertInstanceOf(CURLDeleteRequest::class, $res1);
56
57
        // ===
58
        $res2 = CURLFactory::getInstance(HTTPInterface::HTTP_METHOD_GET);
59
        $this->assertInstanceOf(CURLGetRequest::class, $res2);
60
61
        // ===
62
        $res3 = CURLFactory::getInstance(HTTPInterface::HTTP_METHOD_HEAD);
63
        $this->assertInstanceOf(CURLHeadRequest::class, $res3);
64
65
        // ===
66
        $res4 = CURLFactory::getInstance(HTTPInterface::HTTP_METHOD_OPTIONS);
67
        $this->assertInstanceOf(CURLOptionsRequest::class, $res4);
68
69
        // ===
70
        $res5 = CURLFactory::getInstance(HTTPInterface::HTTP_METHOD_PATCH);
71
        $this->assertInstanceOf(CURLPatchRequest::class, $res5);
72
73
        // ===
74
        $res6 = CURLFactory::getInstance(HTTPInterface::HTTP_METHOD_POST);
75
        $this->assertInstanceOf(CURLPostRequest::class, $res6);
76
77
        // ===
78
        $res7 = CURLFactory::getInstance(HTTPInterface::HTTP_METHOD_PUT);
79
        $this->assertInstanceOf(CURLPutRequest::class, $res7);
80
    }
81
82
}
83