Ejemplo n.º 1
0
 /**
  * @param Result $result
  */
 public function output(Result $result)
 {
     if ($result->getAssumptionsCount() > 0) {
         $this->cli->table($result->getAssumptions())->br();
     }
     $this->cli->out(sprintf('%d out of %d boolean expressions are assumptions (%d%%)', $result->getAssumptionsCount(), $result->getBoolExpressionsCount(), $result->getPercentage()));
 }
Ejemplo n.º 2
0
 /**
  * @param Result $result
  */
 public function output(Result $result)
 {
     $assumptions = $result->getAssumptions();
     foreach ($assumptions as $assumption) {
         $fileElements = $this->xpath->query('/phpa/files/file[@name="' . $assumption['file'] . '"]');
         if ($fileElements->length === 0) {
             $files = $this->xpath->query('/phpa/files')->item(0);
             $fileElement = $this->document->createElement('file');
             $fileElement->setAttribute('name', $assumption['file']);
             $files->appendChild($fileElement);
         } else {
             $fileElement = $fileElements->item(0);
         }
         $lineElement = $this->document->createElement('line');
         $lineElement->setAttribute('number', $assumption['line']);
         $lineElement->setAttribute('message', $assumption['message']);
         $fileElement->appendChild($lineElement);
     }
     $this->document->documentElement->setAttribute('assumptions', $result->getAssumptionsCount());
     $this->document->documentElement->setAttribute('bool-expressions', $result->getBoolExpressionsCount());
     $this->document->documentElement->setAttribute('percentage', $result->getPercentage());
     $this->document->preserveWhiteSpace = false;
     $this->document->formatOutput = true;
     $this->document->save($this->file);
     $this->cli->out(sprintf('Written %d assumption(s) to file %s', $result->getAssumptionsCount(), $this->file));
 }
Ejemplo n.º 3
0
    /**
     * @test
     */
    public function itShouldGenerateValidXml()
    {
        $this->result->getAssumptions()->shouldBeCalled()->willReturn([['file' => 'MyClass.php', 'line' => 122, 'message' => 'if ($test) {'], ['file' => 'MyClass.php', 'line' => 132, 'message' => '$test ? "Yes" : "No"'], ['file' => 'MyOtherClass.php', 'line' => 12, 'message' => 'if ($test !== false) {']]);
        $this->result->getAssumptionsCount()->shouldBeCalled()->willReturn(3);
        $this->result->getPercentage()->shouldBeCalled()->willReturn(60);
        $this->result->getBoolExpressionsCount()->shouldBeCalled()->willReturn(5);
        $this->xmlOutput->output($this->result->reveal());
        $version = Cli::VERSION;
        $expected = <<<XML
<?xml version="1.0"?>
<phpa version="{$version}" assumptions="3" bool-expressions="5" percentage="60">
    <files>
        <file name="MyClass.php">
            <line number="122" message="if (\$test) {" />
            <line number="132" message="\$test ? &quot;Yes&quot; : &quot;No&quot;" />
        </file>
        <file name="MyOtherClass.php">
            <line number="12" message="if (\$test !== false) {" />
        </file>
    </files>
</phpa>
XML;
        $this->assertXmlStringEqualsXmlString($expected, file_get_contents($this->file));
    }