3 include_once __DIR__ . '/parse_args.php';
5 include_once __DIR__ . '/PolyfillTestCase.php';
7 use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
12 abstract class PhpXmlRpc_LocalFileTestCase extends PhpXmlRpc_PolyfillTestCase
14 public $args = array();
19 /** @var boolean $collectCodeCoverageInformation */
20 protected $collectCodeCoverageInformation;
21 protected $coverageScriptUrl;
24 * Reimplemented to allow us to collect code coverage info for the target php files executed via an http request.
25 * Code taken from PHPUnit_Extensions_Selenium2TestCase
27 * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
29 public function _run($result = NULL)
31 $this->testId = get_class($this) . '__' . $this->getName();
33 if ($result === NULL) {
34 $result = $this->createResult();
37 $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
39 parent::_run($result);
41 if ($this->collectCodeCoverageInformation) {
42 $coverage = new RemoteCoverage(
43 $this->coverageScriptUrl,
46 $result->getCodeCoverage()->append(
47 $coverage->get(), $this
51 // do not call this before to give the time to the Listeners to run
52 //$this->getStrategy()->endOfTest($this->session);
57 protected function request($file, $method = 'GET', $payload = '', $emptyPageOk = false)
59 $url = $this->baseUrl . $file;
61 $ch = curl_init($url);
62 curl_setopt_array($ch, array(
63 CURLOPT_RETURNTRANSFER => true,
64 CURLOPT_FAILONERROR => true
66 if ($method == 'POST')
68 curl_setopt_array($ch, array(
70 CURLOPT_POSTFIELDS => $payload
73 if ($this->collectCodeCoverageInformation)
75 curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID='.$this->testId);
77 if ($this->args['DEBUG'] > 0) {
78 curl_setopt($ch, CURLOPT_VERBOSE, 1);
80 $page = curl_exec($ch);
83 $this->assertNotFalse($page);
85 $this->assertNotEquals('', $page);
87 $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page);
88 $this->assertStringNotContainsStringIgnoringCase('Notice:', $page);