1 | <?php |
||
2 | |||
3 | include_once __DIR__ . '/LoggerAwareTestCase.php'; |
||
4 | |||
5 | use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage; |
||
6 | use PHPUnit\Framework\TestResult; |
||
7 | |||
8 | abstract class PhpXmlRpc_ServerAwareTestCase extends PhpXmlRpc_LoggerAwareTestCase |
||
9 | { |
||
10 | /** @var string */ |
||
11 | protected $baseUrl; |
||
12 | /** @var string */ |
||
13 | protected $testId; |
||
14 | /** @var boolean */ |
||
15 | protected $collectCodeCoverageInformation; |
||
16 | /** @var string */ |
||
17 | protected $coverageScriptUrl; |
||
18 | |||
19 | protected static $randId; |
||
20 | |||
21 | /** |
||
22 | * Reimplemented to allow us to collect code coverage info from the target server. |
||
23 | * Code taken from PHPUnit_Extensions_Selenium2TestCase |
||
24 | * |
||
25 | * @param TestResult $result |
||
26 | * @return TestResult |
||
27 | * @throws Exception |
||
28 | * |
||
29 | * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation |
||
30 | */ |
||
31 | public function _run($result = NULL) |
||
32 | { |
||
33 | $this->testId = get_class($this) . '__' . $this->getName(); |
||
34 | |||
35 | if ($result === NULL) { |
||
36 | $result = $this->createResult(); |
||
37 | } |
||
38 | |||
39 | $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation(); |
||
40 | |||
41 | parent::_run($result); |
||
42 | |||
43 | if ($this->collectCodeCoverageInformation) { |
||
44 | $coverage = new RemoteCoverage( |
||
45 | $this->coverageScriptUrl, |
||
46 | $this->testId |
||
47 | ); |
||
48 | $result->getCodeCoverage()->append( |
||
49 | $coverage->get(), $this |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | // do not call this before to give the time to the Listeners to run |
||
54 | //$this->getStrategy()->endOfTest($this->session); |
||
55 | |||
56 | return $result; |
||
57 | } |
||
58 | |||
59 | public static function set_up_before_class() |
||
60 | { |
||
61 | parent::set_up_before_class(); |
||
62 | |||
63 | // Set up a database connection or other fixture which needs to be available. |
||
64 | self::$randId = uniqid(); |
||
65 | file_put_contents(sys_get_temp_dir() . '/phpunit_rand_id.txt', self::$randId); |
||
66 | } |
||
67 | |||
68 | public static function tear_down_after_class() |
||
69 | { |
||
70 | if (is_file(sys_get_temp_dir() . '/phpunit_rand_id.txt')) { |
||
71 | unlink(sys_get_temp_dir() . '/phpunit_rand_id.txt'); |
||
72 | } |
||
73 | |||
74 | parent::tear_down_after_class(); |
||
75 | } |
||
76 | |||
77 | public function set_up() |
||
78 | { |
||
79 | parent::set_up(); |
||
80 | |||
81 | // assumes HTTPURI to be in the form /tests/index.php?etc... |
||
82 | $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']); |
||
83 | $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']); |
||
84 | } |
||
85 | |||
86 | protected function getClient() |
||
87 | { |
||
88 | $server = explode(':', $this->args['HTTPSERVER']); |
||
89 | if (count($server) > 1) { |
||
90 | $client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
91 | } else { |
||
92 | $client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']); |
||
93 | } |
||
94 | |||
95 | $client->setDebug($this->args['DEBUG']); |
||
96 | |||
97 | $client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId); |
||
98 | |||
99 | if ($this->collectCodeCoverageInformation) { |
||
100 | $client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId); |
||
101 | } |
||
102 | |||
103 | return $client; |
||
104 | } |
||
105 | |||
106 | public function getAvailableUseCurlOptions() |
||
107 | { |
||
108 | $opts = array(array(\PhpXmlRpc\Client::USE_CURL_NEVER)); |
||
109 | if (function_exists('curl_init')) |
||
110 | { |
||
111 | $opts[] = array(\PhpXmlRpc\Client::USE_CURL_ALWAYS); |
||
112 | } |
||
113 | |||
114 | return $opts; |
||
115 | } |
||
116 | } |
||
117 |