forked from zendframework/zendframework
/
ProxyAdapterTest.php
executable file
·120 lines (104 loc) · 3.89 KB
/
ProxyAdapterTest.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Http_Client
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\Http\Client;
use Zend\Http\Client;
/**
* Zend_Http_Client_Adapter_Proxy test suite.
*
* In order to run, TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY must point to a working
* proxy server, which can access TESTS_ZEND_HTTP_CLIENT_BASEURI.
*
* See TestConfiguration.php.dist for more information.
*
* @category Zend
* @package Zend_Http_Client
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Http
* @group Zend_Http_Client
*/
class ProxyAdapterTest extends SocketTest
{
/**
* Configuration array
*
* @var array
*/
protected function setUp()
{
$this->markTestIncomplete('Proxy adapter incomplete at the moment');
if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY') &&
TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY) {
list($host, $port) = explode(':', TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY, 2);
if (! $host)
$this->markTestSkipped('No valid proxy host name or address specified.');
$port = (int) $port;
if ($port == 0) {
$port = 8080;
} else {
if (($port < 1 || $port > 65535))
$this->markTestSkipped("$port is not a valid proxy port number. Should be between 1 and 65535.");
}
$user = '';
$pass = '';
if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER') &&
TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER)
$user = TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER;
if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS') &&
TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS)
$pass = TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS;
$this->config = array(
'adapter' => '\Zend\Http\Client\Adapter\Proxy',
'proxy_host' => $host,
'proxy_port' => $port,
'proxy_user' => $user,
'proxy_pass' => $pass,
);
parent::setUp();
} else {
$this->markTestSkipped('Zend\Http\Client proxy server tests are not enabled in TestConfiguration.php');
}
}
/**
* Test that when no proxy is set the adapter falls back to direct connection
*/
public function testFallbackToSocket()
{
$this->_adapter->setConfig(array(
'proxy_host' => null,
));
$this->client->setUri($this->baseuri . 'testGetLastRequest.php');
$res = $this->client->request(Client::TRACE);
if ($res->getStatus() == 405 || $res->getStatus() == 501) {
$this->markTestSkipped('Server does not allow the TRACE method');
}
$this->assertEquals($this->client->getLastRawRequest(), $res->getBody(), 'Response body should be exactly like the last request');
}
public function testGetLastRequest()
{
/**
* This test will never work for the proxy adapter (and shouldn't!)
* because the proxy server modifies the request which is sent back in
* the TRACE response
*/
}
}