2
0
forked from Wavyzz/dolibarr

Fix: Script tests on Windows where PHP executable is not in path. (#28565)

# Fix: Script tests (on Windows)

- Set `exit(255)` instead of `exit(-1)` in `scripts/bank/export-bank-receipts.php`.
  On *nix, the -1 converts into an exist code of 255 but on windows it
  is -1, making the test fail.
- Add a helper method to execute php scripts using the php binary used
  to run phpunit.

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
MDW
2024-03-04 20:13:34 +01:00
committed by GitHub
parent 04670b92b3
commit 6f8b941c96
2 changed files with 31 additions and 7 deletions

View File

@@ -379,6 +379,30 @@ abstract class CommonClassTest extends TestCase
'zapier' => 'Zapier',
);
/**
* Run php script (file) using the php binary used for running phpunit.
*
* The PHP executable may not be in the path, or refer to an uncontrolled
* version.
* This ensures that the php script is properly run on multiple platforms.
*
* @param string $phpScriptCommand The command and arguments are run by the php binary.
* @param array $output The output returned by the command
* @param int $exitCode The exit code returned for the execution.
* @return false|string False on failure, else last line if the output from the command
*/
protected function runPhpScript($phpScriptCommand, &$output, &$exitCode)
{
$phpExecutable = PHP_BINARY;
// Build the command to execute the PHP script
$command = "$phpExecutable $phpScriptCommand";
// Execute the command
return exec($command, $output, $exitCode);
}
/**
* Assert that a directory does not exist without triggering deprecation
*