CurlHandleTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testAll() 0 22 1
A testClose() 0 5 1
A testInvalidUrl() 0 5 1
1
<?php
2
/**
3
 * This file is part of the bee4/httpclient package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2015
8
 * @author  Stephane HULARD <[email protected]>
9
 * @package Bee4\Test\Transport\Handle
10
 */
11
12
namespace Bee4\Test\Transport\Handle;
13
14
use Bee4\PHPUnit\HttpClientTestCase;
15
use Bee4\Transport\Handle\CurlHandle;
16
17
/**
18
 * Check behaviour of Url helper
19
 * @package Bee4\Test\Transport\Handle
20
 */
21
class CurlHandleTest extends HttpClientTestCase
22
{
23
    /**
24
     * @var CurlHandle
25
     */
26
    protected $object;
27
28
    public function setUp()
29
    {
30
        $this->object = new CurlHandle();
31
    }
32
33
    public function testAll()
34
    {
35
        $this->assertTrue($this->object->hasOption(CURLOPT_HEADER));
36
        $this->assertTrue($this->object->hasOption(CURLINFO_HEADER_OUT));
37
38
        $this->object->addOption(CURLOPT_FOLLOWLOCATION, false);
39
        $this->assertTrue($this->object->hasOption(CURLINFO_HEADER_OUT));
40
41
        $this->object->addOption(CURLOPT_URL, self::getBaseUrl());
42
        $this->assertTrue($this->object->hasOption(CURLOPT_URL));
43
44
        $result = $this->object->execute();
45
46
        $this->assertTrue($this->object->hasInfo('request_header'));
47
        $this->assertEquals(200, $this->object->getInfo('http_code'));
48
        $this->assertNull($this->object->getInfo('unknown_property'));
49
        $this->assertTrue(is_string($result));
50
51
        $this->assertArrayHasKey('content_type', $this->object->getInfos());
52
53
        unset($this->object);
54
    }
55
56
    /**
57
     * @expectedException \RuntimeException
58
     */
59
    public function testClose()
60
    {
61
        $this->object->close();
62
        $this->object->execute();
63
    }
64
65
    /**
66
     * @expectedException \Bee4\Transport\Exception\CurlException
67
     */
68
    public function testInvalidUrl()
69
    {
70
        $this->object->addOptions([CURLOPT_URL => 'invalidUrlToGet']);
71
        $this->object->execute();
72
    }
73
}
74