Skip to content

[6.x] Only recreate the fake Stache directory when it's gone - #15538

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix/prevents-saving-stache-recreate-guard
Sep 29, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix/prevents-saving-stache-recreate-guard

Conversation

@joshdaugherty

Copy link
Copy Markdown
Contributor

Fixes #15537

deleteFakeStacheDirectory() called mkdir() straight after deleteDirectory(). deleteDirectory() ignores a failed rmdir(), and on Windows a directory stays in place while any process still has a handle open on it. So the directory could still exist, and mkdir() threw ErrorException: mkdir(): File exists in tearDown(), failing a test that had passed.

It now recreates the directory only if it's gone. The directory that survives is already empty, since only the final rmdir() failed, so the next test still starts from a clean fake Stache. This only changes test tooling (PreventsSavingStacheItemsToDisk, used by Tests\TestCase and AddonTestCase).

Tests

Adds tests/Testing/Concerns/PreventsSavingStacheItemsToDiskTest.php:

  • it empties and recreates the fake stache directory, the normal case.
  • it does not fail when the directory outlives its deletion, which binds files to a Filesystem whose deleteDirectory() keeps the directory, like Windows does while a handle is open. On 6.x without the change it throws mkdir(): File exists; with it, it passes.

tests/Stache and tests/Antlers/Parser/ComponentTagsTest.php, which use the trait, still pass (221 tests).

@jasonvarga
jasonvarga merged commit 74824b4 into statamic:6.x Sep 29, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PreventsSavingStacheItemsToDisk teardown throws mkdir(): File exists on Windows when the fake Stache directory outlives its deletion

2 participants