3 include_once __DIR__ . '/parse_args.php';
5 include_once __DIR__ . '/PolyfillTestCase.php';
7 use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
9 abstract class PhpXmlRpc_WebTestCase extends PhpXmlRpc_PolyfillTestCase
11 public $args = array();
16 /** @var boolean $collectCodeCoverageInformation */
17 protected $collectCodeCoverageInformation;
18 protected $coverageScriptUrl;
21 * Reimplemented to allow us to collect code coverage info for the target php files executed via an http request.
22 * Code taken from PHPUnit_Extensions_Selenium2TestCase
24 * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
26 public function _run($result = NULL)
28 $this->testId = get_class($this) . '__' . $this->getName();
30 if ($result === NULL) {
31 $result = $this->createResult();
34 $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
36 parent::_run($result);
38 if ($this->collectCodeCoverageInformation) {
39 $coverage = new RemoteCoverage(
40 $this->coverageScriptUrl,
43 $result->getCodeCoverage()->append(
44 $coverage->get(), $this
48 // do not call this before to give the time to the Listeners to run
49 //$this->getStrategy()->endOfTest($this->session);
56 * @param string $method
57 * @param string $payload
58 * @param false $emptyPageOk
61 protected function request($path, $method = 'GET', $payload = '', $emptyPageOk = false)
63 $url = $this->baseUrl . $path;
65 $ch = curl_init($url);
66 curl_setopt_array($ch, array(
67 CURLOPT_RETURNTRANSFER => true,
68 CURLOPT_FAILONERROR => true
70 if ($method == 'POST')
72 curl_setopt_array($ch, array(
74 CURLOPT_POSTFIELDS => $payload
77 if ($this->collectCodeCoverageInformation)
79 curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID='.$this->testId);
81 if ($this->args['DEBUG'] > 0) {
82 curl_setopt($ch, CURLOPT_VERBOSE, 1);
84 $page = curl_exec($ch);
87 $this->assertNotFalse($page);
89 $this->assertNotEquals('', $page);
91 $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page);
92 $this->assertStringNotContainsStringIgnoringCase('Notice:', $page);