From d81d871ad379cdfafae72487803a717ce4756b51 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 19 Mar 2021 13:38:13 +1300 Subject: [PATCH] Code cleanup in bootstrap.php --- composer.json | 3 ++- .../tests/phpunit/bootstrap.php | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index cd21534faa..a42355e235 100644 --- a/composer.json +++ b/composer.json @@ -84,7 +84,8 @@ "ext-intl": "*", "pear/mail_mime": "~1.10", "pear/db": "1.10", - "civicrm/composer-compile-lib": "~0.3 || ~1.0" + "civicrm/composer-compile-lib": "~0.3 || ~1.0", + "ext-json": "*" }, "scripts": { "post-install-cmd": [ diff --git a/ext/sequentialcreditnotes/tests/phpunit/bootstrap.php b/ext/sequentialcreditnotes/tests/phpunit/bootstrap.php index 352e007050..8082b15b0a 100644 --- a/ext/sequentialcreditnotes/tests/phpunit/bootstrap.php +++ b/ext/sequentialcreditnotes/tests/phpunit/bootstrap.php @@ -20,16 +20,16 @@ $loader->register(); * The rest of the command to send. * @param string $decode * Ex: 'json' or 'phpcode'. + * * @return string * Response output (if the command executed normally). - * @throws \RuntimeException - * If the command terminates abnormally. + * @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'); // Execute `cv` in the original folder. This is a work-around for // phpunit/codeception, which seem to manipulate PWD. @@ -49,7 +49,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 (strpos(trim($result), '/*BEGINPHP*/') !== 0 || substr(trim($result), -10) !== '/*ENDPHP*/') { throw new \RuntimeException("Command failed ($cmd):\n$result"); } return $result; -- 2.25.1