New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for phpdbg with fast code coverage #258
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,8 @@ private function createPhpInterpreter() | |
|
||
if (preg_match('#HipHop VM#', $output)) { | ||
$this->interpreter = new HhvmPhpInterpreter($this->options['-p'], $args); | ||
} elseif (strpos($output, 'phpdbg') !== FALSE) { | ||
$this->interpreter = new ZendPhpDbgInterpreter($this->options['-p'], $args); | ||
} else { | ||
$this->interpreter = new ZendPhpInterpreter($this->options['-p'], $args); | ||
} | ||
|
@@ -229,7 +231,8 @@ private function createRunner() | |
private function prepareCodeCoverage() | ||
{ | ||
if (!$this->interpreter->hasXdebug()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imho, this should stay there with modified message. And as a workaround, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't make any sense. PHPDBG may or may not have XDebug loaded, just like normal CLI/CGI SAPI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JanTvrdik Or maybe better |
||
throw new \Exception("Code coverage functionality requires Xdebug extension (used {$this->interpreter->getCommandLine()})"); | ||
$alternative = PHP_VERSION_ID >= 70000 ? ' or phpdbg SAPI' : ''; | ||
throw new \Exception("Code coverage functionality requires Xdebug extension$alternative (used {$this->interpreter->getCommandLine()})"); | ||
} | ||
file_put_contents($this->options['--coverage'], ''); | ||
$file = realpath($this->options['--coverage']); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Nette Tester. | ||
* Copyright (c) 2009 David Grudl (http://davidgrudl.com) | ||
*/ | ||
|
||
namespace Tester\Runner; | ||
|
||
use Tester\Helpers; | ||
|
||
|
||
/** | ||
* Zend phpdbg command-line executable. | ||
*/ | ||
class ZendPhpDbgInterpreter implements PhpInterpreter | ||
{ | ||
/** @var string PHP arguments */ | ||
public $arguments; | ||
|
||
/** @var string PHP executable */ | ||
private $path; | ||
|
||
/** @var string PHP version */ | ||
private $version; | ||
|
||
/** @var string */ | ||
private $error; | ||
|
||
|
||
public function __construct($path, $args = NULL) | ||
{ | ||
$this->path = Helpers::escapeArg($path); | ||
$proc = proc_open( | ||
"$this->path -n $args -V", | ||
array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), | ||
$pipes, | ||
NULL, | ||
NULL, | ||
array('bypass_shell' => TRUE) | ||
); | ||
$output = stream_get_contents($pipes[1]); | ||
|
||
$this->error = trim(stream_get_contents($pipes[2])); | ||
if (proc_close($proc)) { | ||
throw new \Exception("Unable to run '$path': " . preg_replace('#[\r\n ]+#', ' ', $this->error)); | ||
} elseif (!preg_match('#^PHP ([\w.-]+)#im', $output, $matches)) { | ||
throw new \Exception("Unable to detect PHP version (output: $output)."); | ||
} elseif (version_compare($matches[1], '7.0.0', '<')) { | ||
throw new \Exception('Unable to use phpdbg on PHP < 7.0.0.'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've seen some really strange behavior when I ran phpdbg with XDebug loaded as a module. Maybe also check for XDebug not being loaded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What? Phpdbg is only usable on php7 and xdebux is only usable on php5. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. XDebug will be usable on PHP 7 as well, once it's ported. It is already working for debugging (not coverage though). |
||
|
||
$this->version = $matches[1]; | ||
$this->arguments = $args; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCommandLine() | ||
{ | ||
return $this->path . ' -qrrb -S cli' . $this->arguments; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getVersion() | ||
{ | ||
return $this->version; | ||
} | ||
|
||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasXdebug() | ||
{ | ||
return TRUE; | ||
} | ||
|
||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isCgi() | ||
{ | ||
return FALSE; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getErrorOutput() | ||
{ | ||
return $this->error; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
PHP_SAPI === 'phpdbg'
correct? PHP_SAPI is 'cli' when argument-qrrb -S cli
is used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dg Handy when called
phpdbg path/to/test.phpt
manually.