Hal\MutaTesting\Runner\Adapter\PHPUnitAdapter::run PHP Method

run() public method

public run ( $path = null, array $options = [], $logFile = null, $prependFile = null, callable $callback = null )
$options array
$callback callable
    public function run($path = null, array $options = array(), $logFile = null, $prependFile = null, callable $callback = null)
    {
        if (!is_null($logFile)) {
            array_push($options, sprintf('--log-junit %s', $logFile));
        }
        if (!is_null($prependFile)) {
            // We cannot use php directive auto_prepend_file :
            // PHPUnit doesn't tun test in a separate process by default
            // see @link https://github.com/sebastianbergmann/phpunit/issues/930
            //
            // all the following lines should be replaced with the commented line if
            // PHPUnit change its behavior
            //
            // $options = array(sprintf('-d auto_prepend_file=%s', $bootstrapName));
            array_push($options, sprintf('--bootstrap %s', $prependFile));
            foreach ($this->getOptions() as $option) {
                $filename = false;
                if (preg_match('!-c\\s*(.*)!', $option, $matches)) {
                    $configFile = $matches[1];
                    $xml = simplexml_load_file($configFile);
                    $filename = (string) $xml['bootstrap'];
                }
                if (preg_match('!--configuration\\s*(.*)!', $option, $matches)) {
                    $configFile = $matches[1];
                    $xml = simplexml_load_file($configFile);
                    $filename = (string) $xml['bootstrap'];
                }
                if (preg_match('!--bootstrap\\s*(.*)!', $option, $matches)) {
                    $filename = $matches[1];
                }
                if ($filename) {
                    $filename = $origine = dirname($configFile) . DIRECTORY_SEPARATOR . $filename;
                    $content = file_get_contents($filename);
                    $filename = tempnam(sys_get_temp_dir(), 'tmp-botstrap');
                    $content = str_replace('__FILE__', "'{$origine}'", $content);
                    $content = str_replace('__DIR__', "'" . dirname($origine) . "'", $content);
                    file_put_contents($filename, $content);
                    file_put_contents($prependFile, sprintf("<?php require_once '%s';?>", $filename), FILE_APPEND);
                }
            }
        }
        return parent::run($path, $options, null, null, $callback);
    }

Usage Example

    public function testICanGetTestSuites()
    {
        $filename = $this->directory . 'ExampleTest.php';
        $content = '<?php
class ExampleTest extends PHPUnit_Framework_TestCase {
    public function testEx1() {
        $this->assertEquals(1,1);
    }
}
';
        file_put_contents($filename, $content);
        $runner = new PHPUnitAdapter($this->binary, $this->directory);
        $logFile = tempnam(sys_get_temp_dir(), 'unit-test');
        $runner->run(null, array(), $logFile);
        $collection = $runner->getSuiteResult($logFile);
        $this->assertInstanceOf('\\Hal\\MutaTesting\\Test\\UnitCollectionInterface', $collection);
        $this->assertEquals(1, sizeof($collection->all()));
    }