holyshared/peridot-temporary-plugin

Temporary file / directory plugin for peridot-php

Maintainers

👁 holyshared

Package info

github.com/holyshared/peridot-temporary-plugin

pkg:composer/holyshared/peridot-temporary-plugin

Statistics

Installs: 1 208

Dependents: 6

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.5 2015-12-31 06:01 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 0d61e7ef8dd0056b9fb4cd118e10295ac0a5456b

  • holyshared <holy.shared.design.woop@gmail.com>

plugintesttemporaryperidottemporary directorytemporary file

This package is auto-updated.

Last update: 2026-06-15 19:35:21 UTC


README

It provides an api to create a temporary directory or file.
Directory of file will be deleted at the end of the test.

👁 Build Status
👁 HHVM Status
👁 Coverage Status
👁 Scrutinizer Code Quality
👁 Dependency Status

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