Skip to content

Commit

Permalink
Merge pull request #246 from seamuslee001/phpunit8
Browse files Browse the repository at this point in the history
[NFC] Update Unit tests to be compatible with PHPUnit8
  • Loading branch information
eileenmcnaughton authored Mar 20, 2021
2 parents e40392c + 1126881 commit f45758b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/CiviWP/HookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class HookTest extends \PHPUnit\Framework\TestCase implements EndToEndInterface {

public function testFoo() {
public function testFoo(): void {
add_action('civicrm_fakeAlterableHook', 'onFakeAlterableHook', 10, 2);

$arg1 = 'hello';
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CiviWP/PhpVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PhpVersionTest extends \PHPUnit\Framework\TestCase implements EndToEndInte
*
* The literal value should be duplicated in the define() to prevent dependency issues.
*/
public function testConstantMatch() {
public function testConstantMatch(): void {
$constantFile = $this->getModulePath() . '/civicrm.php';
$this->assertFileExists($constantFile);
$content = file_get_contents($constantFile);
Expand Down
9 changes: 4 additions & 5 deletions tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
define('CIVICRM_CONTAINER_CACHE', 'never');

ini_set('memory_limit', '2G');
ini_set('safe_mode', 0);
// phpcs:disable
eval(cv('php:boot', 'phpcode'));
// phpcs:enable
Expand All @@ -22,11 +21,11 @@
* @throws \RuntimeException
* If the command terminates abnormally.
*/
function cv($cmd, $decode = 'json') {
function cv(string $cmd, $decode = 'json'): string {
$cmd = 'cv ' . $cmd;
$descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR);
$descriptorSpec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => STDERR];
$oldOutput = getenv('CV_OUTPUT');
putenv("CV_OUTPUT=json");
putenv('CV_OUTPUT=json');
$process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__);
putenv("CV_OUTPUT=$oldOutput");
fclose($pipes[0]);
Expand All @@ -41,7 +40,7 @@ function cv($cmd, $decode = 'json') {

case 'phpcode':
// If the last output is /*PHPCODE*/, then we managed to complete execution.
if (substr(trim($result), 0, 12) !== "/*BEGINPHP*/" || substr(trim($result), -10) !== "/*ENDPHP*/") {
if (substr(trim($result), 0, 12) !== '/*BEGINPHP*/' || substr(trim($result), -10) !== '/*ENDPHP*/') {
throw new \RuntimeException("Command failed ($cmd):\n$result");
}
return $result;
Expand Down

0 comments on commit f45758b

Please sign in to comment.