Permalink
Browse files

Some cleanup over the Summer WIP to get development back under way.

  • Loading branch information...
1 parent cbdeaa2 commit 713442ed72df70543e4b785f302ae5091537b196 Pádraic Brady committed Jan 25, 2012
@@ -105,6 +105,7 @@ public function runTests(\Mutagenesis\Runner\Base $runner, $useStdout = false,
public static function execute($jobScript, $timeout = 120)
{
$output = \Mutagenesis\Utility\Process::run($jobScript, $timeout);
+ var_dump($output); exit;
return $output;
}
@@ -147,8 +148,6 @@ public static function main($arguments, $mutation = null, $bootstrap = null)
}
}
- //var_dump($arguments); exit;
-
/**
* Switch working directory to tests and execute the test suite
*/
@@ -187,4 +186,4 @@ public static function processOutput($output)
return true;
}
-}
+}
@@ -32,20 +32,22 @@ class Job
*/
public function generate(array $mutation = array(), array $args = array(), $bootstrap = null)
{
- $serializedArgs = serialize($args);
- $serializedMutation = serialize($mutation);
+ $serializedArgs = addslashes(serialize($args));
+ $serializedMutation = addslashes(serialize($mutation));
if (is_null($bootstrap)) {
$bootstrap = 'null';
+ } else {
+ addslashes($bootstrap);
}
$script = <<<SCRIPT
<?php
require_once 'Mutagenesis/Loader.php';
\$loader = new \Mutagenesis\Loader;
\$loader->register();
\Mutagenesis\Adapter\PHPUnit::main(
- {$serializedArgs},
- {$serializedMutation},
- {$bootstrap}
+ "{$serializedArgs}",
+ "{$serializedMutation}",
+ "{$bootstrap}"
);
SCRIPT;
return $script;
@@ -86,24 +86,17 @@ public static function run($source, $timeout = 120)
if (is_resource($process)) {
fwrite($pipes[0], $source);
fclose($pipes[0]);
- stream_set_timeout($pipes[1], $timeout);
$stdout = stream_get_contents($pipes[1]);
- $info = stream_get_meta_data($pipes[1]);
fclose($pipes[1]);
+ $stderr = stream_get_contents($pipes[2]);
+ fclose($pipes[2]);
proc_close($process);
- if($info['timed_out']) {
- return array(
- 'stdout' => 'Your tests timed out. Mutagenesis may have'
- . ' inadvertently created an infinite loop using'
- . ' the current mutation.'
- );
- } else {
- return array(
- 'stdout' => $stdout
- );
- }
+ return array(
+ 'stdout' => $stdout,
+ 'stderr' => $stderr
+ );
} else {
- throw new \Exception('Unable to open a new process with proc_open()');
+ throw new \Exception('Unable to open a new process');
}
}
@@ -29,7 +29,6 @@ class Mutagenesis_Adapter_PhpunitAdapterTest extends PHPUnit_Framework_TestCase
public function setUp()
{
$this->root = dirname(__FILE__) . '/_files';
- $this->runner = m::mock('\Mutagenesis\Runner\Base');
}
public function tearDown()
@@ -46,7 +45,8 @@ public function tearDown()
public function testAdapterRunsDefaultPhpunitCommand()
{
$adapter = new \Mutagenesis\Adapter\Phpunit;
- $this->runner->shouldReceive('getOptions')->andReturn(
+ $runner = m::mock('\Mutagenesis\Runner\Base');
+ $runner->shouldReceive('getOptions')->andReturn(
array(
'src' => dirname(__FILE__) . '/_files/phpunit',
'tests' => dirname(__FILE__) . '/_files/phpunit',
@@ -56,17 +56,16 @@ public function testAdapterRunsDefaultPhpunitCommand()
'constraint' => 'MM1_MathTest MathTest.php'
)
);
- $this->runner->shouldReceive(array(
+ $runner->shouldReceive(array(
'getBootstrap' => null,
- 'getTimeout' =>120
+ 'getTimeout' => 1200
));
ob_start();
$result = $adapter->runTests(
- $this->runner,
+ $runner,
false,
true
);
- //var_dump($result); exit("\nend:".__FILE__.__LINE__);
$this->assertStringStartsWith(
\PHPUnit_Runner_Version::getVersionString(),
ob_get_clean()
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Mutagenesis
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://github.com/padraic/mutateme/blob/rewrite/LICENSE
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to padraic@php.net so we can send you a copy immediately.
+ *
+ * @category Mutagenesis
+ * @package Mutagenesis
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
+ * @license http://github.com/padraic/mutateme/blob/rewrite/LICENSE New BSD License
+ */
+
+require_once 'Mutagenesis/Utility/Job.php';
+
+class Mutagenesis_ProcTest extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * @group separateprocess
+ */
+ public function testExecutesGivenScriptInSeparateProcess()
+ {
+ $process = new \Mutagenesis\Utility\Process;
+ $return = $process->run(
+ "<?php echo 'It\'s alive!';"
+ );
+ $this->assertEquals('It\'s alive!', $return);
+ }
+
+ /**
+ * @group separateprocess
+ */
+ public function testSeparateProcessTimesOut()
+ {
+ $process = new \Mutagenesis\Utility\Process;
+ $return = $process->run(
+ "<?php sleep(5);",
+ 1
+ );
+ $this->assertEquals('It\'s alive!', $return);
+ }
+
+}

0 comments on commit 713442e

Please sign in to comment.