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:
@@ -379,6 +379,30 @@ abstract class CommonClassTest extends TestCase
|
|||||||
'zapier' => 'Zapier',
|
'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
|
* Assert that a directory does not exist without triggering deprecation
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class ScriptsTest extends CommonClassTest
|
|||||||
$returnvar = 0;
|
$returnvar = 0;
|
||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
$result = exec($script, $output, $returnvar);
|
$result = $this->runPhpScript($script, $output, $returnvar);
|
||||||
|
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
print __METHOD__." output=".join("\n", $output)."\n";
|
print __METHOD__." output=".join("\n", $output)."\n";
|
||||||
@@ -156,21 +156,21 @@ class ScriptsTest extends CommonClassTest
|
|||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
$script = dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test thirdparties';
|
$script = dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test thirdparties';
|
||||||
$result = exec($script, $output, $returnvar);
|
$result = $this->runPhpScript($script, $output, $returnvar);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
print __METHOD__." output=".join("\n", $output)."\n";
|
print __METHOD__." output=".join("\n", $output)."\n";
|
||||||
print __METHOD__." returnvar=".$returnvar."\n";
|
print __METHOD__." returnvar=".$returnvar."\n";
|
||||||
$this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php thirdparties');
|
$this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php thirdparties');
|
||||||
|
|
||||||
$script = dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test contacts -30';
|
$script = dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test contacts -30';
|
||||||
$result = exec($script, $output, $returnvar);
|
$result = $this->runPhpScript($script, $output, $returnvar);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
print __METHOD__." output=".join("\n", $output)."\n";
|
print __METHOD__." output=".join("\n", $output)."\n";
|
||||||
print __METHOD__." returnvar=".$returnvar."\n";
|
print __METHOD__." returnvar=".$returnvar."\n";
|
||||||
$this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php contacts');
|
$this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php contacts');
|
||||||
|
|
||||||
$script = dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_representatives.php test -30';
|
$script = dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_representatives.php test -30';
|
||||||
$result = exec($script, $output, $returnvar);
|
$result = $this->runPhpScript($script, $output, $returnvar);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
print __METHOD__." output=".join("\n", $output)."\n";
|
print __METHOD__." output=".join("\n", $output)."\n";
|
||||||
print __METHOD__." returnvar=".$returnvar."\n";
|
print __METHOD__." returnvar=".$returnvar."\n";
|
||||||
@@ -197,21 +197,21 @@ class ScriptsTest extends CommonClassTest
|
|||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
$script = dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test thirdparties';
|
$script = dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test thirdparties';
|
||||||
$result = exec($script, $output, $returnvar);
|
$result = $this->runPhpScript($script, $output, $returnvar);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
print __METHOD__." output=".join("\n", $output)."\n";
|
print __METHOD__." output=".join("\n", $output)."\n";
|
||||||
print __METHOD__." returnvar=".$returnvar."\n";
|
print __METHOD__." returnvar=".$returnvar."\n";
|
||||||
$this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php thirdparties');
|
$this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php thirdparties');
|
||||||
|
|
||||||
$script = dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test contacts -30';
|
$script = dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test contacts -30';
|
||||||
$result = exec($script, $output, $returnvar);
|
$result = $this->runPhpScript($script, $output, $returnvar);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
print __METHOD__." output=".join("\n", $output)."\n";
|
print __METHOD__." output=".join("\n", $output)."\n";
|
||||||
print __METHOD__." returnvar=".$returnvar."\n";
|
print __METHOD__." returnvar=".$returnvar."\n";
|
||||||
$this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php contacts');
|
$this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php contacts');
|
||||||
|
|
||||||
$script = dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_representatives.php test thirdparties';
|
$script = dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_representatives.php test thirdparties';
|
||||||
$result = exec($script, $output, $returnvar);
|
$result = $this->runPhpScript($script, $output, $returnvar);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
print __METHOD__." output=".join("\n", $output)."\n";
|
print __METHOD__." output=".join("\n", $output)."\n";
|
||||||
print __METHOD__." returnvar=".$returnvar."\n";
|
print __METHOD__." returnvar=".$returnvar."\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user