Merge remote branch 'hidenorigoto/feature/add-server-param-method'
* hidenorigoto/feature/add-server-param-method: [BrowserKit] added tests for setServerParameter/getServerParameter methods [BrowserKit] added getServerParameter method which makes setServerParameters/setServerParameter methods testable [BrowserKit] added the method to Client which enables to set single server parameter
This commit is contained in:
commit
62737c2495
@ -108,6 +108,29 @@ abstract class Client
|
||||
), $server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets single server parameter.
|
||||
*
|
||||
* @param string $key A key of the parameter
|
||||
* @param string $value A value of the parameter
|
||||
*/
|
||||
public function setServerParameter($key, $value)
|
||||
{
|
||||
$this->server[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets single server parameter for specified key.
|
||||
*
|
||||
* @param string $key A key of the parameter to get
|
||||
* @param string $default A default value when key is undefined
|
||||
* @return string A value of the parameter
|
||||
*/
|
||||
public function getServerParameter($key, $default = '')
|
||||
{
|
||||
return (isset($this->server[$key])) ? $this->server[$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the History instance.
|
||||
*
|
||||
|
@ -308,4 +308,27 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInstanceof('RuntimeException', $e, '->request() throws a \RuntimeException if the script has an error');
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetServerParameter()
|
||||
{
|
||||
$client = new TestClient();
|
||||
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
|
||||
$this->assertEquals('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3', $client->getServerParameter('HTTP_USER_AGENT'));
|
||||
|
||||
$this->assertEquals('testvalue', $client->getServerParameter('testkey', 'testvalue'));
|
||||
}
|
||||
|
||||
public function testSetServerParameter()
|
||||
{
|
||||
$client = new TestClient();
|
||||
|
||||
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
|
||||
$this->assertEquals('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3', $client->getServerParameter('HTTP_USER_AGENT'));
|
||||
|
||||
$client->setServerParameter('HTTP_HOST', 'testhost');
|
||||
$this->assertEquals('testhost', $client->getServerParameter('HTTP_HOST'));
|
||||
|
||||
$client->setServerParameter('HTTP_USER_AGENT', 'testua');
|
||||
$this->assertEquals('testua', $client->getServerParameter('HTTP_USER_AGENT'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user