/**
* Parse tested files of the unit test and injects them in Unit::setTestedFiles()
*
* @param \Hal\MutaTesting\Test\UnitInterface $unit
* @return \Hal\MutaTesting\Test\UnitInterface
*/
public function parseTestedFiles(UnitInterface &$unit)
{
$factory = new MutationFactory();
$mutation = $factory->factoryFromUnit($unit);
$prependFile = $this->createFileSystemMock($mutation);
// add logger
$filename = tempnam(sys_get_temp_dir(), 'tested-files');
$content = '<?php
register_shutdown_function(function() {
file_put_contents(\'' . $filename . '\', serialize( get_included_files() ));
});?>';
file_put_contents($prependFile, $content);
// run mutation
$this->runMutation($mutation, array(), null, $prependFile);
// get files
$includedExport = unserialize(file_get_contents($filename));
$includedFiles = array_filter($includedExport, function ($file) use($prependFile, $filename) {
return !preg_match('!(PHPUnit\\\\)|(Test.php)|(phpunit.phar)|(vendor)|(Interface.php)!', $file) && !in_array($file, array($prependFile, $filename));
});
$unit->setTestedFiles(array_values($includedFiles));
return $unit;
}