Пример #1
0
    public function testGenerateReturnsPHPScriptRenderedWithCurrentRunnersSettingsAndSerialisedMutationArray()
    {
        $job = new Job();
        $source = '
        $obj = new stdClass;
        $obj->dave = function() {
            return $dave = 123;
        };
        ';
        $script = $job->generate(array('a', '1', $source));
        $autoload = realpath(__DIR__ . "/../../../vendor/autoload.php");
        $expected = <<<EXPECTED
<?php

namespace MutagenesisEnv;

declare(ticks = 1);
require_once 'PHPUnit/Autoload.php';
include "{$autoload}";
class Job {
    static function main () {
        \\Mutagenesis\\Adapter\\Phpunit::main(
            "a:0:{}",
            'a:3:{i:0;s:1:"a";i:1;s:1:"1";i:2;s:115:"
        \$obj = new stdClass;
        \$obj->dave = function() {
            return \$dave = 123;
        };
        ";}',
            null
        );
    }
    static function timeout() {
        throw new \\Exception('Timed Out');
    }
}
pcntl_signal(SIGALRM, array('\\MutagenesisEnv\\Job', 'timeout'), TRUE);
pcntl_alarm(60);
try {
    Job::main();
} catch (\\Exception \$e) {
    pcntl_alarm(0);
    throw \$e;
}
pcntl_alarm(0);
EXPECTED;
        $this->assertEquals($expected, $script);
    }
Пример #2
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);
 }