AbstractRequestTest::testSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the beebot 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\Message\Request
10
 */
11
12
namespace Bee4\Test\Transport\Message\Request;
13
14
use Bee4\PHPUnit\HttpClientTestCase;
15
use Bee4\Transport\Client;
16
use Bee4\Transport\Url;
17
18
/**
19
 * AbstractRequest test definition
20
 * @package Bee4\Test\Transport\Message\Request
21
 */
22
class AbstractRequestTest extends HttpClientTestCase
23
{
24
    /**
25
     * @var Url
26
     */
27
    protected $url;
28
29
    /**
30
     * Build an Url object which represent BaseUrl
31
     */
32
    public function setUp()
33
    {
34
        $this->url = new Url(self::getBaseUrl());
35
    }
36
37
    /**
38
     * Check that constructor works well
39
     */
40
    public function testConstructor()
41
    {
42
        $headers = ['Content-Type' => 'text/html'];
43
44
        $mock = $this->getMockForAbstractClass(
45
            '\Bee4\Transport\Message\Request\AbstractRequest',
46
            [$this->url, $headers]
47
        );
48
49
        $this->assertEquals($headers, $mock->getHeaders());
50
        $this->assertEquals(
51
            self::getBaseUrl(),
52
            (string)$mock->getUrl()
53
        );
54
    }
55
56
    /**
57
     * Check curl option collection manipulation
58
     */
59
    public function testOptions()
60
    {
61
        $mock = $this->getMockForAbstractClass('\Bee4\Transport\Message\Request\AbstractRequest', [$this->url]);
62
63
        $this->assertEmpty($mock->getOptions());
64
        $mock->addOption(CURL_HTTP_VERSION_1_1, true);
65
        $mock->addOptions([CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 10]);
66
67
        $options = $mock->getOptions();
68
        $this->assertArrayHasKey(CURLOPT_CONNECTTIMEOUT, $options);
69
        $this->assertArrayHasKey(CURLOPT_AUTOREFERER, $options);
70
        $this->assertArrayHasKey(CURL_HTTP_VERSION_1_1, $options);
71
72
        $this->assertTrue($options[CURLOPT_AUTOREFERER]);
73
        $this->assertEquals(10, $options[CURLOPT_CONNECTTIMEOUT]);
74
    }
75
76
    /**
77
     * @expectedException \RuntimeException
78
     */
79
    public function testInvalidClient()
80
    {
81
        $mock = $this->getMockForAbstractClass('\Bee4\Transport\Message\Request\AbstractRequest', [$this->url]);
82
        $mock->send();
83
    }
84
85
    /**
86
     * Check that request send method return a valid response object
87
     */
88
    public function testSend()
89
    {
90
        $mock = $this->getMockForAbstractClass('\Bee4\Transport\Message\Request\AbstractRequest', [$this->url]);
91
        $mock->setClient(new Client());
92
        $response = $mock->send();
93
94
        $this->assertInstanceOf('\Bee4\Transport\Message\Response', $response);
95
    }
96
}
97