public function testICanGetTestedFilesFromUnitTest() { $filename = $this->directory . 'ExampleTest.php'; $testContent = '<?php require_once "src.php"; class ExampleTest extends PHPUnit_Framework_TestCase { public function testEx1() { $a = new A; $this->assertEquals(true, $a->foo() ); } } '; $srcContent = '<?php class A { public function foo() { return true; } } '; file_put_contents($filename, $testContent); file_put_contents($this->directory . 'src.php', $srcContent); $runner = new PHPUnitAdapter($this->binary, $this->directory); // @todo mock $unit = new \Hal\MutaTesting\Test\Unit(); $unit->setFile($filename); $runner->parseTestedFiles($unit); $testedFiles = $unit->getTestedFiles(); $expected = array($this->directory . 'src.php'); $this->assertEquals($expected, $testedFiles); }
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; }
public function testICanGetTestedFilesFromUnitTest() { $filename = $this->directory . 'ExampleTest.php'; $content = '<?php namespace vendor\\project\\tests\\units; require_once "ExampleSrc.php"; use \\mageekguy\\atoum; use \\vendor\\project; class helloWorld extends atoum\\test { public function testSay() { $helloWorld = new project\\helloWorld(); $this->string($helloWorld->say())->isEqualTo("Hello World!") ; } } '; file_put_contents($filename, $content); $filename = $this->directory . 'ExampleSrc.php'; $content = '<?php namespace vendor\\project; class helloWorld { public function say() { return "Hello World!"; } } '; file_put_contents($filename, $content); $runner = new AtoumAdapter($this->binary, $this->directory); // @todo mock $unit = new \Hal\MutaTesting\Test\Unit(); $unit->setFile($this->directory . 'ExampleTest.php'); $runner->parseTestedFiles($unit); $testedFiles = $unit->getTestedFiles(); $expected = array($this->directory . 'ExampleSrc.php'); $this->assertEquals($expected, $testedFiles); }