foreach ($opts['cookies'] as $name => $cookie) {
$cookieHeader .= $name . '=' . $cookie['value'] . '; ';
}
-var_dump(substr($cookieHeader, 0, -2));
curl_setopt($curl, CURLOPT_COOKIE, substr($cookieHeader, 0, -2));
}
<?php
-include_once __DIR__ . '/LoggerAwareTestCase.php';
+include_once __DIR__ . '/ServerAwareTestCase.php';
/**
- * Tests involving the Client class (and no server).
+ * Tests involving the Client class (and mostly no server).
*/
-class ClientTest extends PhpXmlRpc_LoggerAwareTestCase
+class ClientTest extends PhpXmlRpc_ServerAwareTestCase
{
/** @var xmlrpc_client $client */
public $client = null;
}
$this->client->server = $server[0];
$this->client->path = $this->args['HTTPURI'];
-
+ $this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
$r = $this->client->send($m, 5, 'http11');
$this->assertEquals(0, $r->faultCode());
$ro = $r->value();
$this->client->setDebug($this->args['DEBUG']);
$this->client->request_compression = $this->request_compression;
$this->client->accepted_compression = $this->accepted_compression;
+
+ $this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
+
+ if ($this->collectCodeCoverageInformation) {
+ $this->client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
+ }
}
/**
*/
protected function send($msg, $errorCode = 0, $returnResponse = false)
{
- if ($this->collectCodeCoverageInformation) {
- $this->client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
- }
-
$r = $this->client->send($msg, $this->timeout, $this->method);
// for multicall, return directly array of responses
if (is_array($r)) {
$v = $r->value();
$v = php_xmlrpc_decode($v);
- // take care for the extra cookie used for coverage collection
+ // take care of the extra cookies used for coverage collection and test mechanics
if (isset($v['PHPUNIT_SELENIUM_TEST_ID'])) {
unset($v['PHPUNIT_SELENIUM_TEST_ID']);
}
+ if (isset($v['PHPUNIT_RANDOM_TEST_ID'])) {
+ unset($v['PHPUNIT_RANDOM_TEST_ID']);
+ }
// on IIS and Apache getallheaders returns something slightly different...
$this->assertEquals($cookies, $v);
protected $buffer = '';
/**
- * hide debug messages and errors unless we either are in debug mode or the test fails
+ * Hide debug messages and errors unless we either are in debug mode or the test fails.
* @return void
*/
protected function set_up()
}
}
- // logger API
+ // logger API implementation
public function debug($message, $context = array())
{
/** @var string */
protected $coverageScriptUrl;
+ protected static $randId;
+
/**
* Reimplemented to allow us to collect code coverage info from the target server.
* Code taken from PHPUnit_Extensions_Selenium2TestCase
return $result;
}
+ public static function set_up_before_class()
+ {
+ parent::set_up_before_class();
+
+ // Set up a database connection or other fixture which needs to be available.
+ self::$randId = uniqid();
+ file_put_contents(sys_get_temp_dir() . '/phpunit_rand_id.txt', self::$randId);
+ }
+
+ public static function tear_down_after_class()
+ {
+ if (is_file(sys_get_temp_dir() . '/phpunit_rand_id.txt')) {
+ unlink(sys_get_temp_dir() . '/phpunit_rand_id.txt');
+ }
+
+ parent::tear_down_after_class();
+ }
+
public function set_up()
{
parent::set_up();
CURLOPT_POSTFIELDS => $payload
));
}
+ curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_RANDOM_TEST_ID=' . static::$randId);
if ($this->collectCodeCoverageInformation)
{
curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID='.$this->testId);
}
/**
- * Build an xml-rpc client, tweaked if needed to collect code-coverage information of the server
+ * Build an xml-rpc client, tweaked if needed to collect code-coverage information of the server.
+ * @see also ServerTest::set_up
*
* @param string $path
* @return \PhpXmlRpc\Client
protected function newClient($path)
{
$client = new \PhpXmlRpc\Client($this->baseUrl . $path);
+ $client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
if ($this->collectCodeCoverageInformation) {
$client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
}
// It makes all errors visible, triggers generation of code-coverage information, and runs the target file,
// which is specified as GET param.
+// In case this file is made available on an open-access server, avoid it being useable by anyone who can not also
+// write a specific file to disk.
+// NB: keep filename, cookie name in sync with the code within the TestCase classes sending http requests to this file
+$idFile = sys_get_temp_dir() . '/phpunit_rand_id.txt';
+$randId = isset($_COOKIE['PHPUNIT_RANDOM_TEST_ID']) ? $_COOKIE['PHPUNIT_RANDOM_TEST_ID'] : '';
+$fileId = file_exists($idFile) ? file_get_contents($idFile) : '';
+if ($randId == '' || $fileId == '' || $fileId !== $randId) {
+ die('This url can only be accessed by the test suite');
+}
+
// Make errors visible
ini_set('display_errors', true);
error_reporting(E_ALL);