[HttpFoundation] Split the tests into two methods / data providers.
This commit is contained in:
parent
80030fb28e
commit
f0c4ab663a
@ -739,40 +739,20 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider testGetClientIpsProvider
|
* @dataProvider testGetClientIpProvider
|
||||||
*/
|
*/
|
||||||
public function testGetClientIps($expected, $proxy, $remoteAddr, $httpForwardedFor, $trustedProxies, $multiple = false)
|
public function testGetClientIp($expected, $proxy, $remoteAddr, $httpForwardedFor, $trustedProxies)
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = $this->getRequestInstanceForClientIpTests($proxy, $remoteAddr, $httpForwardedFor, $trustedProxies);
|
||||||
|
|
||||||
$server = array('REMOTE_ADDR' => $remoteAddr);
|
$this->assertEquals($expected, $request->getClientIp());
|
||||||
if (null !== $httpForwardedFor) {
|
|
||||||
$server['HTTP_X_FORWARDED_FOR'] = $httpForwardedFor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($proxy || $trustedProxies) {
|
|
||||||
Request::setTrustedProxies(null === $trustedProxies ? array($remoteAddr) : $trustedProxies);
|
|
||||||
}
|
|
||||||
|
|
||||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
|
||||||
$result = $multiple ? $request->getClientIps() : $request->getClientIp();
|
|
||||||
$this->assertEquals($expected, $result);
|
|
||||||
|
|
||||||
Request::setTrustedProxies(array());
|
Request::setTrustedProxies(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetClientIpsProvider()
|
public function testGetClientIpProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(array('88.88.88.88'), false, '88.88.88.88', null, null, true),
|
|
||||||
array(array('127.0.0.1'), false, '127.0.0.1', null, null, true),
|
|
||||||
array(array('::1'), false, '::1', null, null, true),
|
|
||||||
array(array('127.0.0.1'), false, '127.0.0.1', '88.88.88.88', null, true),
|
|
||||||
array(array('88.88.88.88'), true, '127.0.0.1', '88.88.88.88', null, true),
|
|
||||||
array(array('2620:0:1cfe:face:b00c::3'), true, '::1', '2620:0:1cfe:face:b00c::3', null, true),
|
|
||||||
array(array('127.0.0.1', '87.65.43.21', '88.88.88.88'), true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', null, true),
|
|
||||||
array(array('127.0.0.1', '87.65.43.21'), true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88'), true),
|
|
||||||
array(array('127.0.0.1', '87.65.43.21'), false, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88'), true),
|
|
||||||
array('88.88.88.88', false, '88.88.88.88', null, null),
|
array('88.88.88.88', false, '88.88.88.88', null, null),
|
||||||
array('127.0.0.1', false, '127.0.0.1', null, null),
|
array('127.0.0.1', false, '127.0.0.1', null, null),
|
||||||
array('::1', false, '::1', null, null),
|
array('::1', false, '::1', null, null),
|
||||||
@ -785,6 +765,33 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider testGetClientIpsProvider
|
||||||
|
*/
|
||||||
|
public function testGetClientIps($expected, $proxy, $remoteAddr, $httpForwardedFor, $trustedProxies)
|
||||||
|
{
|
||||||
|
$request = $this->getRequestInstanceForClientIpTests($proxy, $remoteAddr, $httpForwardedFor, $trustedProxies);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $request->getClientIps());
|
||||||
|
|
||||||
|
Request::setTrustedProxies(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetClientIpsProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(array('88.88.88.88'), false, '88.88.88.88', null, null),
|
||||||
|
array(array('127.0.0.1'), false, '127.0.0.1', null, null),
|
||||||
|
array(array('::1'), false, '::1', null, null),
|
||||||
|
array(array('127.0.0.1'), false, '127.0.0.1', '88.88.88.88', null),
|
||||||
|
array(array('88.88.88.88'), true, '127.0.0.1', '88.88.88.88', null),
|
||||||
|
array(array('2620:0:1cfe:face:b00c::3'), true, '::1', '2620:0:1cfe:face:b00c::3', null),
|
||||||
|
array(array('127.0.0.1', '87.65.43.21', '88.88.88.88'), true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', null),
|
||||||
|
array(array('127.0.0.1', '87.65.43.21'), true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88')),
|
||||||
|
array(array('127.0.0.1', '87.65.43.21'), false, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetContentWorksTwiceInDefaultMode()
|
public function testGetContentWorksTwiceInDefaultMode()
|
||||||
{
|
{
|
||||||
$req = new Request;
|
$req = new Request;
|
||||||
@ -1283,6 +1290,24 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
$property->setValue(false);
|
$property->setValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getRequestInstanceForClientIpTests($proxy, $remoteAddr, $httpForwardedFor, $trustedProxies)
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
|
||||||
|
$server = array('REMOTE_ADDR' => $remoteAddr);
|
||||||
|
if (null !== $httpForwardedFor) {
|
||||||
|
$server['HTTP_X_FORWARDED_FOR'] = $httpForwardedFor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($proxy || $trustedProxies) {
|
||||||
|
Request::setTrustedProxies(null === $trustedProxies ? array($remoteAddr) : $trustedProxies);
|
||||||
|
}
|
||||||
|
|
||||||
|
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
|
return $request;
|
||||||
|
}
|
||||||
|
|
||||||
public function testTrustedProxies()
|
public function testTrustedProxies()
|
||||||
{
|
{
|
||||||
$request = Request::create('http://example.com/');
|
$request = Request::create('http://example.com/');
|
||||||
|
Reference in New Issue
Block a user