Hal\MutaTesting\Test\Collection\Factory\XUnitFactory::factory PHP Method

factory() public method

public factory ( $xmlContent )
    public function factory($xmlContent)
    {
        $collection = new UnitCollection();
        $xml = simplexml_load_string($xmlContent);
        if (!$xml) {
            throw new \UnexpectedValueException('Invalid xml given');
        }
        $nodes = $xml->xpath('//testsuite/testsuite');
        if (!$nodes) {
            $nodes = $xml->xpath('//testsuites/testsuite');
        }
        foreach ($nodes as $n => $info) {
            $unit = new \Hal\MutaTesting\Test\Unit();
            $unit->setName((string) $info['name'])->setNumOfAssertions('?')->setNumOfErrors((int) $info['errors'])->setNumOfFailures((int) $info['failures'])->setTime((string) $info['time']);
            $testcases = $info->children();
            if (sizeof($testcases) > 0) {
                $unit->setFile((string) $testcases[0]['file']);
            }
            $collection->push($unit);
        }
        return $collection;
    }

Usage Example

Beispiel #1
0
 /**
  * Get results of unit test suites by the file where the junit result is logged
  * 
  * @param string $logPath
  * @return UnitCollectionInterface
  */
 public function getSuiteResult($logPath)
 {
     $factory = new XUnitFactory();
     $results = $factory->factory(file_get_contents($logPath));
     return $results;
 }
XUnitFactory