File: MockTest.php

package info (click to toggle)
php-horde-http 2.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 208 kB
  • ctags: 256
  • sloc: php: 943; xml: 491; sh: 3; makefile: 2
file content (105 lines) | stat: -rw-r--r-- 3,438 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
 * Test the remote server handler.
 *
 * PHP version 5
 *
 * @category   Horde
 * @package    Http
 * @subpackage UnitTests
 * @author     Gunnar Wrobel <wrobel@pardus.de>
 * @license    http://www.horde.org/licenses/bsd
 * @link       http://www.horde.org/libraries/Horde_Http
 */

/**
 * Test the remote server handler.
 *
 * PHP version 5
 *
 * @category   Horde
 * @package    Http
 * @subpackage UnitTests
 * @author     Gunnar Wrobel <wrobel@pardus.de>
 * @license    http://www.horde.org/licenses/bsd
 * @link       http://www.horde.org/libraries/Horde_Http
 */
class Horde_Http_MockTest extends PHPUnit_Framework_TestCase
{
    public function testNoResponses()
    {
        $mock = new Horde_Http_Request_Mock();
        $client = new Horde_Http_Client(array('request' => $mock));
        $this->assertNull($client->get());
    }

    public function testPreparedResponse()
    {
        $body = 'Test';
        $stream = new Horde_Support_StringStream($body);
        $response = new Horde_Http_Response_Mock('', $stream->fopen());
        $mock = new Horde_Http_Request_Mock();
        $mock->setResponse($response);
        $client = new Horde_Http_Client(array('request' => $mock));
        $this->assertEquals('Test', $client->get()->getBody());
    }

    public function testAddResponseBody()
    {
        $mock = new Horde_Http_Request_Mock();
        $mock->addResponse('Test');
        $client = new Horde_Http_Client(array('request' => $mock));
        $this->assertEquals('Test', $client->get()->getBody());
    }

    public function testAddResponseCode()
    {
        $mock = new Horde_Http_Request_Mock();
        $mock->addResponse('Test', 404);
        $client = new Horde_Http_Client(array('request' => $mock));
        $this->assertEquals(404, $client->get()->code);
    }

    public function testAddResponseUri()
    {
        $mock = new Horde_Http_Request_Mock();
        $mock->addResponse('Test', 404, 'http://example.org');
        $client = new Horde_Http_Client(array('request' => $mock));
        $this->assertEquals('http://example.org', $client->get()->uri);
    }

    public function testAddResponseHeader()
    {
        $mock = new Horde_Http_Request_Mock();
        $mock->addResponse('Test', 404, 'http://example.org', array('test: TEST'));
        $client = new Horde_Http_Client(array('request' => $mock));
        $this->assertEquals('TEST', $client->get()->getHeader('test'));
    }

    public function testAddStringResponses()
    {
        $mock = new Horde_Http_Request_Mock();
        $mock->addResponses(array('A', 'B'));
        $client = new Horde_Http_Client(array('request' => $mock));
        $client->get();
        $this->assertEquals('B', $client->get()->getBody());
    }

    public function testAddArrayResponses()
    {
        $mock = new Horde_Http_Request_Mock();
        $mock->addResponses(
            array(
                array('body' => 'A'),
                array('code' => 404),
                array('uri' => 'http://example.org'),
                array('headers' => 'test: TEST'),
            )
        );
        $client = new Horde_Http_Client(array('request' => $mock));
        $this->assertEquals('A', $client->get()->getBody());
        $this->assertEquals(404, $client->get()->code);
        $this->assertEquals('http://example.org', $client->get()->uri);
        $this->assertEquals('TEST', $client->get()->getHeader('test'));
    }
}