Mutagenesis\Utility\Job::generate PHP Method

generate() public method

Generate a new Job script to be executed under a separate PHP process
public generate ( array $mutation = [], array $args = [], $timeout = 60, $bootstrap = null ) : string
$mutation array Mutation data and objects to be used
$args array
return string
    public function generate(array $mutation = array(), array $args = array(), $timeout = 60, $bootstrap = null)
    {
        $serializedArgs = addslashes(serialize($args));
        $serializedMutation = addslashes(serialize($mutation));
        if (is_null($bootstrap)) {
            $bootstrap = 'null';
        } else {
            $bootstrap = '"' . addslashes($bootstrap) . '"';
        }
        $script = <<<SCRIPT
<?php
namespace MutagenesisEnv;
declare(ticks = 1);
require_once 'PHPUnit/Autoload.php';
require_once 'Mutagenesis/Loader.php';
\$loader = new \\Mutagenesis\\Loader;
\$loader->register();
class Job {
    static function main () {
        \\Mutagenesis\\Adapter\\Phpunit::main(
            "{$serializedArgs}",
            "{$serializedMutation}",
            {$bootstrap}
        );
    }
    static function timeout() {
        throw new \\Exception('Timed Out');
    }
}
pcntl_signal(SIGALRM, array('\\MutagenesisEnv\\Job', 'timeout'), TRUE);
pcntl_alarm({$timeout});
try {
    Job::main();
} catch (\\Exception \$e) {
    pcntl_alarm(0);
    throw \$e;
}
pcntl_alarm(0);
SCRIPT;
        return $script;
    }

Usage Example

Beispiel #1
0
 /**
  * Runs the tests suite according to Runner set options and the execution
  * order of test case (if any). It then returns an array of two elements.
  * First element is a boolean result value indicating if tests passed or not.
  * Second element is an array containing the key "stdout" which stores the
  * output from the last test run.
  *
  * @param BaseRunner           $runner
  * @param bool                 $useStdout
  * @param bool                 $firstRun
  * @param MutantInterface|bool $mutant
  * @param array                $testCases
  *
  * @return array
  */
 public function runTests(BaseRunner $runner, $useStdout = true, $firstRun = false, $mutant = false, array $testCases = array())
 {
     $options = $runner->getOptions();
     $job = new Job();
     $outputKey = 'stdout';
     if (!$useStdout) {
         array_unshift($options['clioptions'], '--stderr');
         $outputKey = 'stderr';
     }
     if (!in_array('--stop-on-failure', $options['clioptions'])) {
         array_unshift($options['clioptions'], '--stop-on-failure');
     }
     array_unshift($options['clioptions'], 'phpunit');
     if ($firstRun) {
         $options['clioptions'] = array_merge($options['clioptions'], array('--log-junit', $options['cache'] . '/mutagenesis.xml'), explode(' ', $options['constraint']));
     }
     if (count($testCases) > 0) {
         // tests cases always 0 on first run
         foreach ($testCases as $className => $case) {
             $args = $options;
             $args['clioptions'][] = $className;
             $args['clioptions'][] = $case['file'];
             $output = self::execute($job->generate($mutant, $args, $runner->getTimeout(), $runner->getBootstrap()));
             $res = $this->processOutput($output[$outputKey]);
             if (false === $res) {
                 return array($res, $output);
             }
         }
     } else {
         $output = self::execute($job->generate($mutant, $options, 0, $runner->getBootstrap()));
         $res = $this->processOutput($output[$outputKey]);
         if (!$res) {
             return array(false, $output);
         }
     }
     return array($res, $output);
 }
All Usage Examples Of Mutagenesis\Utility\Job::generate