public createFileSystemMock ( Hal\MutaTesting\Mutation\MutationInterface $mutation ) : string | ||
$mutation | Hal\MutaTesting\Mutation\MutationInterface | |
return | string |
public function createFileSystemMock(MutationInterface $mutation)
{
// temporary file
$temporaryFile = tempnam(sys_get_temp_dir(), 'mutate-mock');
file_put_contents($temporaryFile, $mutation->getTokens()->asString());
// mocking system
$bootstrapContent = '' . file_get_contents(__DIR__ . '/../../StreamWrapper/FileMutator.php') . "\n \\Hal\\MutaTesting\\StreamWrapper\\FileMutator::initialize();" . sprintf("\n \\Hal\\MutaTesting\\StreamWrapper\\FileMutator::addMutatedFile('%s', '%s'); ?>", $mutation->getSourceFile(), $temporaryFile);
$bootstrapFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'bootstrap-' . md5(uniqid()) . '.php';
file_put_contents($bootstrapFile, $bootstrapContent);
return $bootstrapFile;
}
public function testICanGetFIleToPrependInOrderToMockSources() { $mutation = $this->getMock('\\Hal\\MutaTesting\\Mutation\\MutationInterface'); $tokens = $this->getMock('\\Hal\\Component\\Token\\TokenCollection', array(), array(array())); $mutation->expects($this->any())->method('getTokens')->will($this->returnValue($tokens)); $adapter = new BaseAdapter(null, null); $filename = $adapter->createFileSystemMock($mutation); $this->assertTrue(file_exists($filename)); $this->assertContains('No syntax errors detected', `php -l {$filename}`); // clean up unlink($filename); }