1 | <?php |
||
19 | class RemoteCoverageHelper |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Remote URL. |
||
24 | * |
||
25 | * @var RemoteUrl |
||
26 | */ |
||
27 | private $_remoteUrl; |
||
28 | |||
29 | /** |
||
30 | * Creates an instance of remote coverage class. |
||
31 | * |
||
32 | * @param RemoteUrl $remote_url Remote URL. |
||
33 | */ |
||
34 | 12 | public function __construct(RemoteUrl $remote_url) |
|
38 | |||
39 | /** |
||
40 | * Retrieves remote coverage information. |
||
41 | * |
||
42 | * @param string $coverage_script_url Coverage script irl. |
||
43 | * @param string $test_id Test ID. |
||
44 | * |
||
45 | * @throws \RuntimeException Broken code coverage retrieved. |
||
46 | * @return array |
||
47 | */ |
||
48 | 7 | public function get($coverage_script_url, $test_id) |
|
49 | { |
||
50 | 7 | $url = $this->createUrl($coverage_script_url, $test_id); |
|
51 | 4 | $buffer = $this->_remoteUrl->getPageContent($url); |
|
52 | |||
53 | 4 | if ( $buffer !== false ) { |
|
54 | 2 | $coverage_data = unserialize($buffer); |
|
55 | |||
56 | 2 | if ( is_array($coverage_data) ) { |
|
57 | 1 | return $this->matchLocalAndRemotePaths($coverage_data); |
|
58 | } |
||
59 | |||
60 | 1 | throw new \RuntimeException('Empty or invalid code coverage data received from url "' . $url . '"'); |
|
61 | } |
||
62 | |||
63 | 2 | return array(); |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Returns url for remote code coverage collection. |
||
68 | * |
||
69 | * @param string $coverage_script_url Coverage script irl. |
||
70 | * @param string $test_id Test ID. |
||
71 | * |
||
72 | * @return string |
||
73 | * @throws \InvalidArgumentException When empty coverage script url given. |
||
74 | */ |
||
75 | 7 | protected function createUrl($coverage_script_url, $test_id) |
|
92 | |||
93 | /** |
||
94 | * Returns only files from remote server, that are matching files on test machine. |
||
95 | * |
||
96 | * @param array $coverage Remote coverage information. |
||
97 | * |
||
98 | * @return array |
||
99 | * @author Mattis Stordalen Flister <[email protected]> |
||
100 | */ |
||
101 | 1 | protected function matchLocalAndRemotePaths(array $coverage) |
|
121 | |||
122 | /** |
||
123 | * Returns path separator in given path. |
||
124 | * |
||
125 | * @param string $path Path to file. |
||
126 | * |
||
127 | * @return string |
||
128 | * @author Mattis Stordalen Flister <[email protected]> |
||
129 | */ |
||
130 | 1 | protected function findDirectorySeparator($path) |
|
138 | |||
139 | } |
||
140 |