Tests
[plcapi.git] / tests / LocalFileTestCase.php
1 <?php
2
3 include_once __DIR__ . '/parse_args.php';
4
5 include_once __DIR__ . '/PolyfillTestCase.php';
6
7 use PHPUnit\Framework\TestResult;
8
9 abstract class PhpXmlRpc_LocalFileTestCase extends PhpXmlRpc_PolyfillTestCase
10 {
11     public $args = array();
12
13     protected $baseUrl;
14
15     protected $testId;
16     /** @var boolean $collectCodeCoverageInformation */
17     protected $collectCodeCoverageInformation;
18     protected $coverageScriptUrl;
19
20     public function _run($result = NULL)
21     {
22         $this->testId = get_class($this) . '__' . $this->getName();
23
24         if ($result === NULL) {
25             $result = $this->createResult();
26         }
27
28         $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
29
30         parent::_run($result);
31
32         if ($this->collectCodeCoverageInformation) {
33             $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
34                 $this->coverageScriptUrl,
35                 $this->testId
36             );
37             $result->getCodeCoverage()->append(
38                 $coverage->get(), $this
39             );
40         }
41
42         // do not call this before to give the time to the Listeners to run
43         //$this->getStrategy()->endOfTest($this->session);
44
45         return $result;
46     }
47
48     protected function request($file, $method = 'GET', $payload = '', $emptyPageOk = false)
49     {
50         $url = $this->baseUrl . $file;
51
52         $ch = curl_init($url);
53         curl_setopt_array($ch, array(
54             CURLOPT_RETURNTRANSFER => true,
55             CURLOPT_FAILONERROR => true
56         ));
57         if ($method == 'POST')
58         {
59             curl_setopt_array($ch, array(
60                 CURLOPT_POST => true,
61                 CURLOPT_POSTFIELDS => $payload
62             ));
63         }
64         if ($this->collectCodeCoverageInformation)
65         {
66             curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
67         }
68         if ($this->args['DEBUG'] > 0) {
69             curl_setopt($ch, CURLOPT_VERBOSE, 1);
70         }
71         $page = curl_exec($ch);
72         curl_close($ch);
73
74         $this->assertNotFalse($page);
75         if (!$emptyPageOk) {
76             $this->assertNotEquals('', $page);
77         }
78         $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page);
79         $this->assertStringNotContainsStringIgnoringCase('Notice:', $page);
80
81         return $page;
82     }
83
84 }