*/
class CharsetTest extends PhpXmlRpc_PolyfillTestCase
{
- // Consolas font should render these properly
+ // Consolas font should render these properly. Of course this file is encoded in UTF-8
protected $runes = "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ";
protected $greek = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ";
protected $russian = "Река неслася; бедный чёлн";
protected $chinese = "我能吞下玻璃而不伤身体。";
- protected $latinString;
-
- /// @todo move to usage of a dataProvider and create the latinString there
- protected function set_up()
- {
- // construct a latin string with all chars (except control ones)
- $this->latinString = "\n\r\t";
- for($i = 32; $i < 127; $i++) {
- $this->latinString .= chr($i);
- }
- for($i = 160; $i < 256; $i++) {
- $this->latinString .= chr($i);
- }
- }
-
protected function utf8ToLatin1($data)
{
return Charset::instance()->encodeEntities(
public function testUtf8ToLatin1All()
{
+ $latinString = "\n\r\t";
+ for($i = 32; $i < 127; $i++) {
+ $latinString .= chr($i);
+ }
+ for($i = 160; $i < 256; $i++) {
+ $latinString .= chr($i);
+ }
+
// the warning suppression is due to utf8_encode being deprecated in php 8.2
- $string = @utf8_encode($this->latinString);
+ $string = @utf8_encode($latinString);
$encoded = $this->utf8ToLatin1($string);
- $this->assertEquals(str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $this->latinString), $encoded);
+ $this->assertEquals(str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $latinString), $encoded);
}
public function testUtf8ToLatin1EuroSymbol()
<?php
-include_once __DIR__ . '/../lib/xmlrpc.inc';
-include_once __DIR__ . '/../lib/xmlrpcs.inc';
-
-include_once __DIR__ . '/parse_args.php';
-
-include_once __DIR__ . '/PolyfillTestCase.php';
-
-use PHPUnit\Runner\BaseTestRunner;
+include_once __DIR__ . '/LogAwareTestCase.php';
/**
* Tests involving the Value class.
* NB: these tests do not involve the parsing of xml into Value objects - look in 03ParsingTest for that
*/
-class ValueTest extends PhpXmlRpc_PolyfillTestCase
+class ValueTest extends PhpXmlRpc_LogAwareTestCase
{
- public $args = array();
-
- protected function set_up()
- {
- $this->args = argParser::getArgs();
- if ($this->args['DEBUG'] == 1)
- ob_start();
- }
-
- protected function tear_down()
- {
- if ($this->args['DEBUG'] != 1)
- return;
- $out = ob_get_clean();
- $status = $this->getStatus();
- if ($status == BaseTestRunner::STATUS_ERROR
- || $status == BaseTestRunner::STATUS_FAILURE) {
- echo $out;
- }
- }
-
public function testMinusOneString()
{
$v = new xmlrpcval('-1');
<?php
-include_once __DIR__ . '/../lib/xmlrpc.inc';
-include_once __DIR__ . '/../lib/xmlrpcs.inc';
-
-include_once __DIR__ . '/parse_args.php';
-
-include_once __DIR__ . '/PolyfillTestCase.php';
-
-use PHPUnit\Runner\BaseTestRunner;
+include_once __DIR__ . '/LogAwareTestCase.php';
/**
* Tests involving Requests and Responses, except for the parsing part
*/
-class MessagesTest extends PhpXmlRpc_PolyfillTestCase
+class MessagesTest extends PhpXmlRpc_LogAwareTestCase
{
- public $args = array();
-
- protected function set_up()
- {
- $this->args = argParser::getArgs();
- // hide parsing errors unless in debug mode
- if ($this->args['DEBUG'] == 1)
- ob_start();
- }
-
- protected function tear_down()
- {
- if ($this->args['DEBUG'] != 1)
- return;
- $out = ob_get_clean();
- $status = $this->getStatus();
- if ($status == BaseTestRunner::STATUS_ERROR
- || $status == BaseTestRunner::STATUS_FAILURE) {
- echo $out;
- }
- }
-
public function testSerializePHPValResponse()
{
$r = new \PhpXmlRpc\Response(array('hello' => 'world'), 0, '', 'phpvals');
<?php
-include_once __DIR__ . '/../lib/xmlrpc.inc';
-include_once __DIR__ . '/../lib/xmlrpcs.inc';
-
-include_once __DIR__ . '/parse_args.php';
-
-include_once __DIR__ . '/PolyfillTestCase.php';
-
-use PHPUnit\Runner\BaseTestRunner;
+include_once __DIR__ . '/LogAwareTestCase.php';
/**
* Tests involving xml parsing.
*
* @todo some tests are here even though they logically belong elsewhere...
*/
-class ParsingTest extends PhpXmlRpc_PolyfillTestCase
+class ParsingTest extends PhpXmlRpc_LogAwareTestCase
{
- public $args = array();
-
- protected function set_up()
- {
- $this->args = argParser::getArgs();
- // hide parsing errors unless in debug mode
- if ($this->args['DEBUG'] < 1)
- ob_start();
- }
-
- protected function tear_down()
- {
- if ($this->args['DEBUG'] >= 1)
- return;
- $out = ob_get_clean();
- $status = $this->getStatus();
- if ($status == BaseTestRunner::STATUS_ERROR
- || $status == BaseTestRunner::STATUS_FAILURE) {
- echo $out;
- }
- }
-
protected function newRequest($methodName, $params = array())
{
$msg = new xmlrpcmsg($methodName, $params);
<?php
-include_once __DIR__ . '/../lib/xmlrpc.inc';
-include_once __DIR__ . '/../lib/xmlrpcs.inc';
-
-include_once __DIR__ . '/parse_args.php';
-
-include_once __DIR__ . '/PolyfillTestCase.php';
-
-use PHPUnit\Runner\BaseTestRunner;
+include_once __DIR__ . '/LogAwareTestCase.php';
/**
* Tests involving automatic encoding/decoding of php values into xmlrpc values (the Encoder class).
* @todo add tests for encoding options: 'encode_php_objs', 'auto_dates', 'null_extension' and 'extension_api'
* @todo add tests for php_xmlrpc_decode options
*/
-class EncoderTest extends PhpXmlRpc_PolyfillTestCase
+class EncoderTest extends PhpXmlRpc_LogAwareTestCase
{
- public $args = array();
-
- protected function set_up()
- {
- $this->args = argParser::getArgs();
- // hide parsing errors unless in debug mode
- if ($this->args['DEBUG'] == 1)
- ob_start();
- }
-
- protected function tear_down()
- {
- if ($this->args['DEBUG'] != 1)
- return;
- $out = ob_get_clean();
- $status = $this->getStatus();
- if ($status == BaseTestRunner::STATUS_ERROR
- || $status == BaseTestRunner::STATUS_FAILURE) {
- echo $out;
- }
- }
-
public function testEncodeArray()
{
$v = php_xmlrpc_encode(array());
<?php
-include_once __DIR__ . '/../lib/xmlrpc.inc';
-
-include_once __DIR__ . '/parse_args.php';
-
-include_once __DIR__ . '/PolyfillTestCase.php';
-
-use PHPUnit\Runner\BaseTestRunner;
+include_once __DIR__ . '/LogAwareTestCase.php';
/**
* Tests involving the Client class (and no server).
*/
-class ClientTes extends PhpXmlRpc_PolyfillTestCase
+class ClientTes extends PhpXmlRpc_LogAwareTestCase
{
/** @var xmlrpc_client $client */
public $client = null;
- public $args = array();
public function set_up()
{
- $this->args = argParser::getArgs();
+ parent::set_up();
$this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80);
$this->client->setDebug($this->args['DEBUG']);
-
- // in debug mode, the client will be very verbose. Avoid showing its output unless there are errors
- if ($this->args['DEBUG'] >= 1)
- ob_start();
- }
-
- protected function tear_down()
- {
- if ($this->args['DEBUG'] < 1)
- return;
- $out = ob_get_clean();
- $status = $this->getStatus();
- if ($status == BaseTestRunner::STATUS_ERROR
- || $status == BaseTestRunner::STATUS_FAILURE) {
- echo $out;
- }
}
public function test404()
<?php
-include_once __DIR__ . '/../lib/xmlrpc.inc';
include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
-include_once __DIR__ . '/parse_args.php';
-
-include_once __DIR__ . '/PolyfillTestCase.php';
-
-use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
-use PHPUnit\Framework\TestResult;
-use PHPUnit\Runner\BaseTestRunner;
+include_once __DIR__ . '/ServerAwareTestCase.php';
/**
* Tests which involve interaction with the server - carried out via the client.
* They are run against the server found in demo/server.php.
* Includes testing of (some of) the Wrapper class
*/
-class ServerTest extends PhpXmlRpc_PolyfillTestCase
+class ServerTest extends PhpXmlRpc_ServerAwareTestCase
{
/** @var xmlrpc_client $client */
protected $client = null;
protected $timeout = 10;
protected $request_compression = null;
protected $accepted_compression = '';
- protected $args = array();
protected static $failed_tests = array();
- protected $testId;
- /** @var boolean $collectCodeCoverageInformation */
- protected $collectCodeCoverageInformation;
- protected $coverageScriptUrl;
-
/**
* @todo instead of overriding fail via _fail, implement Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
*/
parent::_fail($message);
}
- /**
- * Reimplemented to allow us to collect code coverage info from the target server.
- * Code taken from PHPUnit_Extensions_Selenium2TestCase
- *
- * @param TestResult $result
- * @return TestResult
- * @throws Exception
- *
- * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
- */
- public function _run($result = NULL)
- {
- $this->testId = get_class($this) . '__' . $this->getName();
-
- if ($result === NULL) {
- $result = $this->createResult();
- }
-
- $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
-
- parent::_run($result);
-
- if ($this->collectCodeCoverageInformation) {
- $coverage = new RemoteCoverage(
- $this->coverageScriptUrl,
- $this->testId
- );
- $result->getCodeCoverage()->append(
- $coverage->get(), $this
- );
- }
-
- // do not call this before to give the time to the Listeners to run
- //$this->getStrategy()->endOfTest($this->session);
-
- return $result;
- }
-
public function set_up()
{
- $this->args = argParser::getArgs();
+ parent::set_up();
$server = explode(':', $this->args['HTTPSERVER']);
if (count($server) > 1) {
$this->client->setDebug($this->args['DEBUG']);
$this->client->request_compression = $this->request_compression;
$this->client->accepted_compression = $this->accepted_compression;
-
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
-
- // in debug mode, the client will be very verbose. Avoid showing its output unless there are errors
- if ($this->args['DEBUG'] >= 1)
- ob_start();
- }
-
- protected function tear_down()
- {
- if ($this->args['DEBUG'] < 1)
- return;
- $out = ob_get_clean();
- $status = $this->getStatus();
- if ($status == BaseTestRunner::STATUS_ERROR
- || $status == BaseTestRunner::STATUS_FAILURE) {
- echo $out;
- }
}
/**
<?php
-include_once __DIR__ . '/../lib/xmlrpc.inc';
-include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
-
-include_once __DIR__ . '/parse_args.php';
-
include_once __DIR__ . '/08ServerTest.php';
/**
*/
class DemoFilesTest extends PhpXmlRpc_WebTestCase
{
- public function set_up()
- {
- $this->args = argParser::getArgs();
-
- // assumes HTTPURI to be in the form /tests/index.php?etc...
- $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
- }
-
public function testVardemo()
{
$page = $this->request('?demo=vardemo.php');
$this->assertStringContainsString('<name>faultCode</name>', $page);
$this->assertRegexp('#<int>10(5|3)</int>#', $page);
- $c = $this->getClient('?demo=server/codegen.php');
+ $c = $this->newClient('?demo=server/codegen.php');
$r = $c->send(new \PhpXmlRpc\Request('CommentManager.getComments', array(
new \PhpXmlRpc\Value('aCommentId')
)));
$this->assertStringContainsString('<name>faultCode</name>', $page);
$this->assertRegexp('#<int>10(5|3)</int>#', $page);
- $c = $this->getClient('?demo=server/discuss.php');
+ $c = $this->newClient('?demo=server/discuss.php');
$r = $c->send(new \PhpXmlRpc\Request('discuss.addComment', array(
new \PhpXmlRpc\Value('aCommentId'),
*/
class DebuggerTest extends PhpXmlRpc_WebTestCase
{
- public function set_up()
- {
- $this->args = argParser::getArgs();
-
- // assumes HTTPURI to be in the form /tests/index.php?etc...
- $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
- }
-
public function testIndex()
{
$page = $this->request('?debugger=index.php');
*/
class ExtraFilesTest extends PhpXmlRpc_WebTestCase
{
- public function set_up()
- {
- $this->args = argParser::getArgs();
-
- // assumes HTTPURI to be in the form /tests/index.php?etc...
- $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
- }
-
public function testBenchmark()
{
$page = $this->request('?extras=benchmark.php');
--- /dev/null
+<?php
+
+include_once __DIR__ . '/../lib/xmlrpc.inc';
+include_once __DIR__ . '/../lib/xmlrpcs.inc';
+
+include_once __DIR__ . '/parse_args.php';
+
+include_once __DIR__ . '/PolyfillTestCase.php';
+
+use PHPUnit\Runner\BaseTestRunner;
+
+abstract class PhpXmlRpc_LogAwareTestCase extends PhpXmlRpc_PolyfillTestCase
+{
+ protected $args = array();
+
+ protected $buffer = '';
+
+ /**
+ * hide debug messages and errors unless we either are in debug mode or the test fails
+ * @return void
+ */
+ protected function set_up()
+ {
+ $this->args = argParser::getArgs();
+
+ if ($this->args['DEBUG'] == 0) {
+ $this->debugBuffer = '';
+ $this->errorBuffer = '';
+ \PhpXmlRpc\PhpXmlRpc::setLogger($this);
+ }
+ }
+
+ protected function tear_down()
+ {
+ if ($this->args['DEBUG'] > 0) {
+ return;
+ }
+
+ // reset the logger to the default
+ \PhpXmlRpc\PhpXmlRpc::setLogger(\PhpXmlRpc\Helper\Logger::instance());
+
+ $status = $this->getStatus();
+ if ($status == BaseTestRunner::STATUS_ERROR
+ || $status == BaseTestRunner::STATUS_FAILURE) {
+ echo $this->buffer;
+ }
+ }
+
+ // logger API
+
+ public function debug($message, $context = array())
+ {
+ $this->buffer .= $message . "\n";
+ }
+
+ public function error($message, $context = array())
+ {
+ $this->buffer .= $message . "\n";
+ }
+}
--- /dev/null
+<?php
+
+include_once __DIR__ . '/LogAwareTestCase.php';
+
+use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
+use PHPUnit\Framework\TestResult;
+
+abstract class PhpXmlRpc_ServerAwareTestCase extends PhpXmlRpc_LogAwareTestCase
+{
+ /** @var string */
+ protected $baseUrl;
+ /** @var string */
+ protected $testId;
+ /** @var boolean */
+ protected $collectCodeCoverageInformation;
+ /** @var string */
+ protected $coverageScriptUrl;
+
+ /**
+ * Reimplemented to allow us to collect code coverage info from the target server.
+ * Code taken from PHPUnit_Extensions_Selenium2TestCase
+ *
+ * @param TestResult $result
+ * @return TestResult
+ * @throws Exception
+ *
+ * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
+ */
+ public function _run($result = NULL)
+ {
+ $this->testId = get_class($this) . '__' . $this->getName();
+
+ if ($result === NULL) {
+ $result = $this->createResult();
+ }
+
+ $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
+
+ parent::_run($result);
+
+ if ($this->collectCodeCoverageInformation) {
+ $coverage = new RemoteCoverage(
+ $this->coverageScriptUrl,
+ $this->testId
+ );
+ $result->getCodeCoverage()->append(
+ $coverage->get(), $this
+ );
+ }
+
+ // do not call this before to give the time to the Listeners to run
+ //$this->getStrategy()->endOfTest($this->session);
+
+ return $result;
+ }
+
+ public function set_up()
+ {
+ parent::set_up();
+
+ // assumes HTTPURI to be in the form /tests/index.php?etc...
+ $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
+ }
+}
<?php
-include_once __DIR__ . '/parse_args.php';
+include_once __DIR__ . '/ServerAwareTestCase.php';
-include_once __DIR__ . '/PolyfillTestCase.php';
-
-use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
-
-abstract class PhpXmlRpc_WebTestCase extends PhpXmlRpc_PolyfillTestCase
+abstract class PhpXmlRpc_WebTestCase extends PhpXmlRpc_ServerAwareTestCase
{
- public $args = array();
-
- protected $baseUrl;
-
- protected $testId;
- /** @var boolean $collectCodeCoverageInformation */
- protected $collectCodeCoverageInformation;
- protected $coverageScriptUrl;
-
/**
- * Reimplemented to allow us to collect code coverage info for the target php files executed via an http request.
- * Code taken from PHPUnit_Extensions_Selenium2TestCase
+ * Make an HTTP request, check that the result is a 200 OK page with no php fatal error or warning messages.
*
- * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
- */
- public function _run($result = NULL)
- {
- $this->testId = get_class($this) . '__' . $this->getName();
-
- if ($result === NULL) {
- $result = $this->createResult();
- }
-
- $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
-
- parent::_run($result);
-
- if ($this->collectCodeCoverageInformation) {
- $coverage = new RemoteCoverage(
- $this->coverageScriptUrl,
- $this->testId
- );
- $result->getCodeCoverage()->append(
- $coverage->get(), $this
- );
- }
-
- // do not call this before to give the time to the Listeners to run
- //$this->getStrategy()->endOfTest($this->session);
-
- return $result;
- }
-
- /**
* @param string $path
* @param string $method
* @param string $payload
return $page;
}
- protected function getClient($path)
+ /**
+ * Build an xml-rpc client, tweaked if needed to collect code-coverage information of the server
+ *
+ * @param string $path
+ * @return \PhpXmlRpc\Client
+ */
+ protected function newClient($path)
{
- $client = new xmlrpc_client($this->baseUrl . $path);
+ $client = new \PhpXmlRpc\Client($this->baseUrl . $path);
if ($this->collectCodeCoverageInformation) {
$client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
}
- // let's just assume that the client works fine for these tests, and avoid polluting output
+ // let's just assume that the client works fine for these tests, and avoid polluting output, even in debug mode
//$client->setAcceptedCompression(false);
//$client->setDebug($this->args['DEBUG']);
return $client;