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