Hal\MutaTesting\Runner\Adapter\BaseAdapter::createFileSystemMock PHP Method

createFileSystemMock() public method

create a bootstrapper to mock file system: the file mentionned in the mutation will be virtualized in the application and replaced with own mutated file
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;
    }

Usage Example

 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);
 }