-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Functional tests compatible with PHPUnit 6. #3694
Changes from all commits
19f3232
d35b127
9b3757b
395b4fd
61e5580
f0f05b3
84c43de
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[PHP] | ||
variables_order = GPCS |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
use Symfony\Component\Process\Process; | ||
use Symfony\Component\Process\Exception\ProcessTimedOutException; | ||
use Webmozart\PathUtil\Path; | ||
use PHPUnit\Framework\TestResult; | ||
|
||
abstract class CommandUnishTestCase extends UnishTestCase | ||
{ | ||
|
@@ -253,7 +253,7 @@ public function execute($command, $expected_return = self::EXIT_SUCCESS, $cd = n | |
$return = $this->process->run(); | ||
if ($expected_return !== $return) { | ||
$message = 'Unexpected exit code ' . $return . ' (expected ' . $expected_return . ") for command:\n" . $command; | ||
throw new UnishProcessFailedError($message, $this->process); | ||
throw new UnishProcessFailedException($message . $this->buildProcessMessage($this->process)); | ||
} | ||
// Reset timeouts to default. | ||
$this->timeout = $this->defaultTimeout; | ||
|
@@ -265,10 +265,26 @@ public function execute($command, $expected_return = self::EXIT_SUCCESS, $cd = n | |
} else { | ||
$message = 'Command had no output for ' . $this->idleTimeout . " seconds:\n" . $command; | ||
} | ||
throw new UnishProcessFailedError($message, $this->process); | ||
throw new UnishProcessFailedException($message . $this->buildProcessMessage($this->process)); | ||
} | ||
} | ||
|
||
/** | ||
* @param Process $process | ||
* @return string | ||
*/ | ||
public function buildProcessMessage(Process $process) | ||
{ | ||
$message = ''; | ||
if ($output = $process->getOutput()) { | ||
$message = "\n\nCommand output:\n" . $output; | ||
} | ||
if ($stderr = $process->getErrorOutput()) { | ||
$message = "\n\nCommand stderr:\n" . $stderr; | ||
} | ||
return $message; | ||
} | ||
|
||
/** | ||
* Invoke drush in via execute(). | ||
* | ||
|
@@ -377,49 +393,6 @@ public function drush($command, array $args = [], array $options = [], $site_spe | |
return $return; | ||
} | ||
|
||
/** | ||
* Override the run method, so we can add in our code coverage data after the | ||
* test has run. | ||
* | ||
* We have to collect all coverage data, merge them and append them as one, to | ||
* avoid having phpUnit duplicating the test function as many times as drush | ||
* has been invoked. | ||
* | ||
* Runs the test case and collects the results in a TestResult object. | ||
* If no TestResult object is passed a new one will be created. | ||
* | ||
* @param \PHPUnit_Framework_TestResult $result | ||
* @return \PHPUnit_Framework_TestResult | ||
* @throws \PHPUnit_Framework_Exception | ||
*/ | ||
public function run(\PHPUnit_Framework_TestResult $result = null) | ||
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. This chunk was an OO error on PHPUnit 5. Not sure how to make both 5 and 6 happy with same code. See https://circleci.com/gh/drush-ops/drush/3338 I'm sad to lose this code coverage collecting during $this->drush() calls but we are not using it anyway. If anyone can fix that error we will bring this code back |
||
{ | ||
$result = parent::run($result); | ||
$data = []; | ||
foreach ($this->coverage_data as $merge_data) { | ||
foreach ($merge_data as $file => $lines) { | ||
if (!isset($data[$file])) { | ||
$data[$file] = $lines; | ||
} else { | ||
foreach ($lines as $num => $executed) { | ||
if (!isset($data[$file][$num])) { | ||
$data[$file][$num] = $executed; | ||
} else { | ||
$data[$file][$num] = ($executed == 1 ? $executed : $data[$file][$num]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Reset coverage data. | ||
$this->coverage_data = []; | ||
if (!empty($data)) { | ||
$result->getCodeCoverage()->append($data, $this); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* A slightly less functional copy of drush_backend_parse_output(). | ||
*/ | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Unish; | ||
|
||
class UnishProcessFailedException extends \RuntimeException | ||
{ | ||
} |
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.
This brings in PHPUnit 6 during build_highest