Mutagenesis\Renderer\Text::renderReport PHP Method

renderReport() public method

Render the final Mutagenesis report
public renderReport ( integer $total, integer $killed, integer $escaped, array $mutations, array $mutantsCaptured, string $output = '' ) : string
$total integer Total mutations made and tested
$killed integer Number of mutations that did cause a test failure
$escaped integer Number of mutations that did not cause a test failure
$mutations array
$mutantsCaptured array
$output string Result output from test adapter
return string
    public function renderReport($total, $killed, $escaped, array $mutations, array $mutantsCaptured, $output = '')
    {
        $out = PHP_EOL . PHP_EOL . $total . ($total == 1 ? ' Mutant' : ' Mutants') . ' born out of the mutagenic slime!' . PHP_EOL . PHP_EOL;
        if ($escaped > 0) {
            $out .= $escaped . ($escaped == 1 ? ' Mutant' : ' Mutants') . ' escaped; the integrity of your source code may be compromised by the following Mutants:' . PHP_EOL . PHP_EOL;
            $i = 1;
            foreach ($mutations as $mutation) {
                $out .= $i . ')' . PHP_EOL . 'Difference on ' . $mutation['class'] . '::' . $mutation['method'] . '() in ' . $mutation['file'] . PHP_EOL . str_repeat('=', 67) . PHP_EOL . $mutation['mutation']->getDiff() . PHP_EOL;
                if (!empty($output)) {
                    $out .= $this->_indentTestOutput($output) . PHP_EOL . PHP_EOL;
                }
                $i++;
            }
            $out .= 'Happy Hunting! Remember that some Mutants may just be' . ' Ghosts (or if you want to be boring, \'false positives\').' . PHP_EOL . PHP_EOL;
        } else {
            $out .= 'No Mutants survived! Someone in QA will be happy.' . PHP_EOL . PHP_EOL;
        }
        if (count($mutantsCaptured) > 0) {
            $out .= 'The following Mutants were safely captured (see above for escapees):' . PHP_EOL . PHP_EOL;
            $i = 1;
            foreach ($mutantsCaptured as $mutant) {
                $out .= $i . ')' . PHP_EOL . 'Difference on ' . $mutant[0]['class'] . '::' . $mutant[0]['method'] . '() in ' . $mutant[0]['file'] . PHP_EOL . str_repeat('=', 67) . PHP_EOL . $mutant[0]['mutation']->getDiff() . PHP_EOL;
                $out .= 'Reported test output:' . PHP_EOL . PHP_EOL . $this->_indentTestOutput($mutant[1]) . PHP_EOL . PHP_EOL;
                $i++;
            }
            $out .= "Check above for the capture details to see if any mutants" . ' escaped.';
        }
        return $out;
    }

Usage Example

Example #1
0
    public function testRendersFinalReportWithEscapeesFromASingleMutant()
    {
        $expected = <<<EXPECTED


Score: 0%

1 Mutant born out of the mutagenic slime!

1 Mutant escaped; the integrity of your source code may be compromised by the following Mutants:

1)
Difference on Foo::bar() in /path/to/foo.php
===================================================================
diff1
    > test1output

Happy Hunting! Remember that some Mutants may just be Ghosts (or if you want to be boring, 'false positives').


EXPECTED;
        $mutable = $this->getMock('Mutagenesis\\Mutable', array('getMutantsEscaped', 'getMutantsCaptured'));
        $mutant = $this->getMock('Mutagenesis\\Mutant\\Mutant', array('getClassName', 'getMethodName', 'getFileName', 'getDiff'), array(), '', false);
        $mutant->expects($this->once())->method('getClassName')->will($this->returnValue('Foo'));
        $mutant->expects($this->once())->method('getMethodName')->will($this->returnValue('bar'));
        $mutant->expects($this->once())->method('getFileName')->will($this->returnValue('/path/to/foo.php'));
        $mutant->expects($this->once())->method('getDiff')->will($this->returnValue('diff1'));
        $mutable->expects($this->once())->method('getMutantsEscaped')->will($this->returnValue(array($mutant)));
        $mutables = array($mutable);
        $this->assertEquals($expected, $this->_renderer->renderReport(1, 0, 1, $mutables, 'test1output'));
    }