-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace PHPUnit\Extensions\SeleniumCommon; | ||
|
||
use Exception; | ||
use SebastianBergmann\CodeCoverage\RawCodeCoverageData; | ||
|
||
class RemoteCoverage | ||
{ | ||
public function __construct($coverageScriptUrl, $testId) | ||
{ | ||
$this->coverageScriptUrl = $coverageScriptUrl; | ||
$this->testId = $testId; | ||
} | ||
|
||
public function get() | ||
{ | ||
if (!empty($this->coverageScriptUrl)) { | ||
$url = sprintf( | ||
'%s?PHPUNIT_SELENIUM_TEST_ID=%s', | ||
$this->coverageScriptUrl, | ||
urlencode($this->testId) | ||
); | ||
|
||
$buffer = @file_get_contents($url); | ||
|
||
if ($buffer !== FALSE) { | ||
$coverageData = unserialize($buffer); | ||
if (is_array($coverageData)) { | ||
//throw new Exception('Here is the data from url "' . $url . '" (' . var_export($buffer, true) . ')'); | ||
|
||
$coverageWithLocalPaths = $this->matchLocalAndRemotePaths($coverageData); | ||
return RawCodeCoverageData::fromXdebugWithoutPathCoverage($coverageWithLocalPaths); | ||
} else { | ||
throw new Exception('Empty or invalid code coverage data received from url "' . $url . '" (' . var_export($buffer, true) . ')'); | ||
} | ||
} | ||
} | ||
|
||
return array(); | ||
} | ||
|
||
/** | ||
* @param array $coverage | ||
* @return array | ||
* @author Mattis Stordalen Flister <mattis@xait.no> | ||
*/ | ||
protected function matchLocalAndRemotePaths(array $coverage) | ||
{ | ||
$coverageWithLocalPaths = array(); | ||
|
||
foreach ($coverage as $originalRemotePath => $data) { | ||
$remotePath = $originalRemotePath; | ||
$separator = $this->findDirectorySeparator($remotePath); | ||
|
||
while (!($localpath = stream_resolve_include_path($remotePath)) && | ||
strpos($remotePath, $separator) !== FALSE) { | ||
$remotePath = substr($remotePath, strpos($remotePath, $separator) + 1); | ||
} | ||
|
||
if ($localpath && md5_file($localpath) == $data['md5']) { | ||
$coverageWithLocalPaths[$localpath] = $data['coverage']; | ||
} | ||
} | ||
|
||
return $coverageWithLocalPaths; | ||
} | ||
|
||
/** | ||
* @param string $path | ||
* @return string | ||
* @author Mattis Stordalen Flister <mattis@xait.no> | ||
*/ | ||
protected function findDirectorySeparator($path) | ||
{ | ||
if (strpos($path, '/') !== FALSE) { | ||
return '/'; | ||
} | ||
|
||
return '\\'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters