PhpBrew\Testing\TemporaryFileFixture::withFile PHP Method

withFile() public method

The 1st argument of the callback function is an object which creates this object. The 2nd argument of the callback function is a destination file path.
public withFile ( string $destFileName, callable $callback )
$destFileName string the filename of a copy of the source file.
$callback callable the function called after creating a destination file.
    public function withFile($destFileName, $callback)
    {
        $contents = file_get_contents($this->sourcePath);
        $destPath = $this->temporaryDirectory . DIRECTORY_SEPARATOR . $destFileName;
        $this->caller->assertFileExists($this->sourcePath);
        file_put_contents($destPath, $contents);
        $this->caller->assertFileExists($destPath);
        try {
            $callback($this->caller, $destPath);
        } catch (\Exception $e) {
            @unlink($destPath);
            $this->caller->fail($e->getMessage());
        }
    }

Usage Example

 public function test()
 {
     $build = new Patch64BitSupportTaskTestBuild();
     $fixture = new TemporaryFileFixture($this, getenv('PHPBREW_FIXTURES_PHP_DIR') . '/' . $build->getVersion() . '/Makefile');
     $fixture->setTemporaryDirectory($build->getSourceDirectory());
     $fixture->withFile('Makefile', function ($self, $fixturePath) use($build) {
         $task = new Patch64BitSupportTask($self->logger, new OptionResult());
         $task->patch($build);
         $self->assertFileEquals(getenv('PHPBREW_EXPECTED_PHP_DIR') . '/' . $build->getVersion() . '/Makefile', $fixturePath);
     });
 }
All Usage Examples Of PhpBrew\Testing\TemporaryFileFixture::withFile