Skip to content

Commit

Permalink
nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Feb 1, 2017
1 parent d1ef2ca commit c67ed00
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $temporaryDirectory = (new TemporaryDirectory())->create();
// Get a path inside the temporary directory
$temporaryDirectory->path('temporaryfile.txt');

// To delete the temporary directory and all the files inside it
// Delete the temporary directory and all the files inside it
$temporaryDirectory->delete();
```

Expand All @@ -47,21 +47,28 @@ To create a temporary directory simply call the `create` method of the `Temporar
If you want to use a custom name for your temporary directory instead of the timestamp call the `name` method before the `create` method.

```php
(new TemporaryDirectory())->name(string $name)->create();
(new TemporaryDirectory())
->name(string $name)
->create();
```

By default an exception will be thrown when if a directory already exists with the given `$name`. You can override this behaviour by calling the `force` method in combination with the `name` method.

```php
(new TemporaryDirectory())->name(string $name)->force()->create();
(new TemporaryDirectory())
->name(string $name)
->force()
->create();
```

### Setting a custom location for a temporary directory

You can set a custom location in which your temporary directory will be created by calling the `location` method and providing the `$path` argument.

```php
(new TemporaryDirectory())->location(string $path)->create();
(new TemporaryDirectory())
->location(string $path)
->create();
```

### Determining paths within the temporary directory
Expand Down
52 changes: 40 additions & 12 deletions tests/TemporaryDirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public function it_can_create_a_temporary_directory()
/** @test */
public function it_can_create_a_temporary_directory_with_a_name()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$this->assertDirectoryExists($temporaryDirectory->path());
$this->assertDirectoryExists($this->temporaryDirectoryFullPath);
Expand All @@ -46,7 +48,10 @@ public function it_can_create_a_temporary_directory_with_a_name()
/** @test */
public function it_can_create_a_temporary_directory_in_a_custom_location()
{
$temporaryDirectory = (new TemporaryDirectory())->location($this->testingDirectory)->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->location($this->testingDirectory)
->name($this->temporaryDirectory)
->create();

$this->assertDirectoryExists($temporaryDirectory->path());
$this->assertDirectoryExists($this->testingDirectory.DIRECTORY_SEPARATOR.$this->temporaryDirectory);
Expand All @@ -55,7 +60,10 @@ public function it_can_create_a_temporary_directory_in_a_custom_location()
/** @test */
public function it_strips_trailing_slashes()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$testingPath = $temporaryDirectory->path('testing'.DIRECTORY_SEPARATOR);
$this->assertStringEndsNotWith(DIRECTORY_SEPARATOR, $testingPath);
}
Expand All @@ -67,23 +75,31 @@ public function by_default_it_will_not_overwrite_an_existing_directory()

$this->expectException(InvalidArgumentException::class);

(new TemporaryDirectory())->name($this->temporaryDirectory)->create();
(new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();
}

/** @test */
public function it_will_overwrite_an_existing_directory_when_using_force_create()
{
mkdir($this->temporaryDirectoryFullPath);

(new TemporaryDirectory())->force()->name($this->temporaryDirectory)->create();
(new TemporaryDirectory())
->force()
->name($this->temporaryDirectory)
->create();

$this->assertDirectoryExists($this->temporaryDirectoryFullPath);
}

/** @test */
public function it_provides_chainable_create_methods()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$this->assertInstanceOf(TemporaryDirectory::class, $temporaryDirectory);

$temporaryDirectory = (new TemporaryDirectory())->force()->name($this->temporaryDirectory)->create();
Expand All @@ -93,7 +109,9 @@ public function it_provides_chainable_create_methods()
/** @test */
public function it_can_create_a_subdirectory_in_the_temporary_directory()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$subdirectory = 'abc';
$subdirectoryPath = $temporaryDirectory->path($subdirectory);
Expand All @@ -105,7 +123,9 @@ public function it_can_create_a_subdirectory_in_the_temporary_directory()
/** @test */
public function it_can_create_a_multiple_subdirectories_in_the_temporary_directory()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$subdirectories = 'abc/123/xyz';
$subdirectoryPath = $temporaryDirectory->path($subdirectories);
Expand All @@ -117,7 +137,9 @@ public function it_can_create_a_multiple_subdirectories_in_the_temporary_directo
/** @test */
public function it_can_create_a_path_to_a_file_in_the_temporary_directory()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$subdirectoriesWithFile = 'abc/123/xyz/test.txt';
$subdirectoryFilePath = $temporaryDirectory->path($subdirectoriesWithFile);
Expand All @@ -130,7 +152,9 @@ public function it_can_create_a_path_to_a_file_in_the_temporary_directory()
/** @test */
public function it_can_delete_a_temporary_directory_containing_files()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$subdirectoriesWithFile = 'abc/123/xyz/test.txt';
$subdirectoryPath = $temporaryDirectory->path($subdirectoriesWithFile);
Expand All @@ -143,7 +167,9 @@ public function it_can_delete_a_temporary_directory_containing_files()
/** @test */
public function it_can_delete_a_temporary_directory_containing_no_content()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$temporaryDirectory->delete();

Expand All @@ -153,7 +179,9 @@ public function it_can_delete_a_temporary_directory_containing_no_content()
/** @test */
public function it_can_empty_a_temporary_directory()
{
$temporaryDirectory = (new TemporaryDirectory())->name($this->temporaryDirectory)->create();
$temporaryDirectory = (new TemporaryDirectory())
->name($this->temporaryDirectory)
->create();

$subdirectoriesWithFile = 'abc/123/xyz/test.txt';
$subdirectoryPath = $temporaryDirectory->path($subdirectoriesWithFile);
Expand Down

0 comments on commit c67ed00

Please sign in to comment.