forked from simpletest/simpletest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.php
More file actions
117 lines (103 loc) · 2.97 KB
/
remote.php
File metadata and controls
117 lines (103 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
require_once dirname(__FILE__) . '/browser.php';
require_once dirname(__FILE__) . '/xml.php';
require_once dirname(__FILE__) . '/test_case.php';
/**
* Runs an XML formated test on a remote server.
*/
class RemoteTestCase
{
private $url;
private $dry_url;
private $size;
/**
* Sets the location of the remote test.
*
* @param string $url Test location.
* @param string $dry_url Location for dry run.
*/
public function __construct($url, $dry_url = false)
{
$this->url = $url;
$this->dry_url = $dry_url ? $dry_url : $url;
$this->size = false;
}
/**
* Accessor for the test name for subclasses.
*
* @return string Name of the test.
*/
public function getLabel()
{
return $this->url;
}
/**
* Runs the top level test for this class.
* Currently reads the data as a single chunk.
*
* @todo I'll fix this once I have added iteration to the browser.
*
* @param SimpleReporter $reporter Target of test results.
*
* @returns boolean True if no failures.
*/
public function run($reporter)
{
$browser = $this->createBrowser();
$xml = $browser->get($this->url);
if (! $xml) {
trigger_error('Cannot read remote test URL [' . $this->url . ']');
return false;
}
$parser = $this->createParser($reporter);
if (! $parser->parse($xml)) {
trigger_error('Cannot parse incoming XML from [' . $this->url . ']');
return false;
}
return true;
}
/**
* Creates a new web browser object for fetching the XML report.
*
* @return SimpleBrowser New browser.
*/
protected function createBrowser()
{
return new SimpleBrowser();
}
/**
* Creates the XML parser.
*
* @param SimpleReporter $reporter Target of test results.
*
* @return SimpleTestXmlListener XML reader.
*/
protected function createParser($reporter)
{
return new SimpleTestXmlParser($reporter);
}
/**
* Accessor for the number of subtests.
*
* @return int Number of test cases.
*/
public function getSize()
{
if ($this->size === false) {
$browser = $this->createBrowser();
$xml = $browser->get($this->dry_url);
if (! $xml) {
trigger_error('Cannot read remote test URL [' . $this->dry_url . ']');
return false;
}
$reporter = new SimpleReporter();
$parser = $this->createParser($reporter);
if (! $parser->parse($xml)) {
trigger_error('Cannot parse incoming XML from [' . $this->dry_url . ']');
return false;
}
$this->size = $reporter->getTestCaseCount();
}
return $this->size;
}
}