Skip to content

Commit

Permalink
Implement default INI settings for #1115
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 8, 2014
1 parent 948e2b1 commit 6a79a45
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
31 changes: 29 additions & 2 deletions src/Extensions/PhptTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ class PHPUnit_Extensions_PhptTestCase implements PHPUnit_Framework_Test, PHPUnit
*/
private $filename;

/**
* @var array
*/
private $settings = array(
'allow_url_fopen=1',
'auto_append_file=',
'auto_prepend_file=',
'disable_functions=',
'display_errors=1',
'docref_root=',
'docref_ext=.html',
'error_append_string=',
'error_prepend_string=',
'error_reporting=-1',
'html_errors=0',
'log_errors=0',
'magic_quotes_runtime=0',
'output_handler=',
'open_basedir=',
'output_buffering=Off',
'report_memleaks=0',
'report_zend_debug=0',
'safe_mode=0',
'track_errors=1',
'xdebug.default_enable=0'
);

/**
* Constructs a test case with the given filename.
*
Expand Down Expand Up @@ -117,7 +144,7 @@ public function run(PHPUnit_Framework_TestResult $result = null)
$result->startTest($this);

if (isset($sections['SKIPIF'])) {
$jobResult = $php->runJob($sections['SKIPIF']);
$jobResult = $php->runJob($sections['SKIPIF'], $this->settings);

if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
if (preg_match('/^\s*skip\s*(.+)\s*/i', $jobResult['stdout'], $message)) {
Expand All @@ -134,7 +161,7 @@ public function run(PHPUnit_Framework_TestResult $result = null)

if (!$skip) {
PHP_Timer::start();
$jobResult = $php->runJob($code);
$jobResult = $php->runJob($code, $this->settings);
$time = PHP_Timer::stop();

if (isset($sections['EXPECT'])) {
Expand Down
18 changes: 17 additions & 1 deletion src/Util/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ public function runTestJob($job, PHPUnit_Framework_Test $test, PHPUnit_Framework
* Runs a single job (PHP code) using a separate PHP process.
*
* @param string $job
* @param array $settings
* @return array
* @throws PHPUnit_Framework_Exception
*/
abstract public function runJob($job);
abstract public function runJob($job, array $settings = array());

/**
* @return string
Expand Down Expand Up @@ -162,6 +163,21 @@ protected function getBinary()
return self::$binary;
}

/**
* @param array $settings
* @return string
*/
protected function settingsToParameters(array $settings)
{
$buffer = '';

foreach ($settings as $setting) {
$buffer .= ' -d ' . $setting;
}

return $buffer;
}

/**
* Processes the TestResult object from an isolated process.
*
Expand Down
5 changes: 3 additions & 2 deletions src/Util/PHP/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ class PHPUnit_Util_PHP_Default extends PHPUnit_Util_PHP
* Runs a single job (PHP code) using a separate PHP process.
*
* @param string $job
* @param array $settings
* @return array
* @throws PHPUnit_Framework_Exception
*/
public function runJob($job)
public function runJob($job, array $settings = array())
{
$process = proc_open(
$this->getBinary(),
$this->getBinary() . $this->settingsToParameters($settings),
array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
Expand Down

0 comments on commit 6a79a45

Please sign in to comment.