Hal\MutaTesting\Test\Collection\Factory\JUnitFactory::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'])->setFile((string) $info['file'])->setNumOfAssertions((int) $info['assertions'])->setNumOfErrors((int) $info['errors'])->setNumOfFailures((int) $info['failures'])->setTime((string) $info['time']);
            $collection->push($unit);
        }
        return $collection;
    }

Usage Example

Example #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 JUnitFactory();
     if (!file_exists($logPath)) {
         throw new \Hal\MutaTesting\Test\Exception\TestSuiteNotFoundException(sprintf('results not found. Last command : "%s"', $this->getLastCommand()));
     }
     $content = file_get_contents($logPath);
     if (0 === strlen($content)) {
         throw new \Hal\MutaTesting\Test\Exception\TestSuiteNotFoundException(sprintf('results are empty. Last command : "%s"', $this->getLastCommand()));
     }
     try {
         $results = $factory->factory($content);
     } catch (\UnexpectedValueException $e) {
         throw new \LogicException(sprintf("Cannot get any informations about tests. There is probably no test with your configuration. \n[Executed command : %s]", $this->getLastCommand()));
     }
     return $results;
 }
JUnitFactory