From f1a81ad34acbca3811fa09b82d41ace27883c577 Mon Sep 17 00:00:00 2001 From: dualfroz Date: Fri, 4 Sep 2026 09:42:16 +0200 Subject: [PATCH] fix: only treat the last path segment as a filename in path() isFilePath() checked the entire path for a dot to decide whether path() was given a file or a directory. Because the path includes the location and name, a dot in a parent segment (for example a location like /tmp/my.app) caused a directory argument to be misclassified as a file, so the requested subdirectory was not created. Inspect only the last path segment instead. --- src/TemporaryDirectory.php | 7 ++++++- tests/TemporaryDirectoryTest.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/TemporaryDirectory.php b/src/TemporaryDirectory.php index c65d938..2fb29dd 100644 --- a/src/TemporaryDirectory.php +++ b/src/TemporaryDirectory.php @@ -163,7 +163,12 @@ class TemporaryDirectory protected function isFilePath(string $path): bool { - return str_contains($path, '.'); + // Only the last segment can be a filename; a dot in a parent segment would + // misclassify a directory. + $lastSeparator = strrpos($path, DIRECTORY_SEPARATOR); + $lastSegment = $lastSeparator === false ? $path : substr($path, $lastSeparator + 1); + + return str_contains($lastSegment, '.'); } protected function deleteDirectory(string $path): bool diff --git a/tests/TemporaryDirectoryTest.php b/tests/TemporaryDirectoryTest.php index 88035fb..4ff79fa 100644 --- a/tests/TemporaryDirectoryTest.php +++ b/tests/TemporaryDirectoryTest.php @@ -173,6 +173,25 @@ class TemporaryDirectoryTest extends TestCase $this->assertDirectoryExists("{$this->temporaryDirectoryFullPath}/{$subdirectory}"); } + /** @test */ + public function it_can_create_a_subdirectory_when_the_location_contains_a_dot() + { + $dottedLocation = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'my.dotted.location'; + $this->deleteDirectory($dottedLocation); + + $temporaryDirectory = (new TemporaryDirectory($dottedLocation)) + ->name($this->temporaryDirectory) + ->create(); + + $subdirectory = 'abc'; + $subdirectoryPath = $temporaryDirectory->path($subdirectory); + + $this->assertDirectoryExists($subdirectoryPath); + + $temporaryDirectory->delete(); + $this->deleteDirectory($dottedLocation); + } + /** @test */ public function it_can_create_a_multiple_subdirectories_in_the_temporary_directory() {