holyshared / peridot-temporary-plugin
Temporary file / directory plugin for peridot-php
Installs: 1 171
Dependents: 6
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.0
- peridot-php/peridot: ~1.16
- ramsey/uuid: ~3.1
Requires (Dev)
- cloak/peridot-cloak-plugin: ~2.0
- cloak/robo-coveralls-kit: ~2.1
- codegyre/robo: ~0.6
- expect/peridot-expect-plugin: ~3.0
- holyshared/robo-peridot: ~2.0
- peridot-php/peridot-dot-reporter: ~1.0
- phpspec/prophecy: ~1.5
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