holyshared/peridot-temporary-plugin
最新稳定版本:1.0.5
Composer 安装命令:
composer require holyshared/peridot-temporary-plugin
包简介
Temporary file / directory plugin for peridot-php
README 文档
README
It provides an api to create a temporary directory or file.
Directory of file will be deleted at the end of the test.
Basic usage
First will first register the plugin.
Edit the peridot.php, write the code to register.
use holyshared\peridot\temporary\TemporaryPlugin; return function(EventEmitterInterface $emitter) { TemporaryPlugin::create()->registerTo($emitter); };
Create a temporary directory
Create a temporary directory, call the makeDirectory method.
Directory name is generated by UUID, use the id.
Permissions can be specified in the argument.
beforeEach(function() { $this->temp = $this->makeDirectory(); //return holyshared\peridot\temporary\TemporaryDirectory instance }); it('create temporary directory', function() { expect($this->temp->exists())->toBeTrue(); });
or
beforeEach(function() { $this->temp = $this->makeDirectory(0755); }); it('create temporary directory', function() { expect($this->temp->exists())->toBeTrue(); });
Create a temporary file
Create a temporary file, call the makeFile method.
File name is generated by UUID, use the id.
Permissions can be specified in the argument.
beforeEach(function() { $this->temp = $this->makeFile(); //return holyshared\peridot\temporary\TemporaryFile instance }); it('create temporary file', function() { expect($this->temp->exists())->toBeTrue(); });
or
beforeEach(function() { $this->temp = $this->makeFile(0755); }); it('create temporary file', function() { expect($this->temp->exists())->toBeTrue(); });
Write to a temporary file
You can output the data to a temporary file in the write or writeln method of TemporaryFile instance.
beforeEach(function() { $this->tempDirectory = $this->makeDirectory(); $this->tempFile = $this->tempDirectory->createNewFile('report.txt'); $this->tempFile->writeln('Hello world!!'); $this->tempFile->writeln('Hello world!!'); }); afterEach(function() { $this->cleanUpTemporary(); });
or
beforeEach(function() { $tempDirectory = $this->makeDirectory(); $tempFilePath = $tempDirectory->resolvePath('report.txt'); //File not created!! $tempFile = new SplFileObject($tempFilePath, 'w'); $tempFile->fwrite('Hello world!!'); $tempFile->fwrite('Hello world!!'); $tempFile = null; });
Running tests
Run with the following command.
composer test
统计信息
- 总下载量: 1.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-18