Issue Bug Resolved

#110489Unit tests remove the scratch directories of other unit tests

Stefan Bürk 08/15/26, 11:57 updated 08/26/26, 11:35

Description

A couple of unit test cases register a shared scratch directory for recursive
removal instead of the unique directory they create themselves.

Test cases collect paths in “testFilesToDelete”, and the testing framework
removes each of them recursively in tearDown(). Several test cases build a
unique directory below a shared root, but register the shared root instead:

bc. $testRoot = Environment::getVarPath() . DIRECTORY_SEPARATOR . tests;
$this->testFilesToDelete[] = $testRoot;

The unique directory is built below that root with a unique id afterwards, and
it is the one that should have been registered.

Such a test case therefore removes the fixture directories of every other test
case that uses the same root, not only its own. The two shared roots in
question are the tests directory below the var path and the tests directory
below typo3temp in the public path. Test cases of EXT:core,
EXT:extensionmanager and EXT:install all use them.

Why this usually stays invisible

Test cases run one after another in a single process, so a removed directory is
usually recreated by the next test case before anything reads it. The defect
becomes visible as soon as test cases run concurrently, and it shows up as
“tearDown() cleanup: File, link or directory does not exist” when a test case
wants to remove something another test case has removed already.

It also means the tear down of a single test case is far more destructive than
it looks, which is a trap for everybody who adds a test case below one of those
roots.

Solution

Register the unique directory a test case creates, not the shared root. Where
the shared root is kept in a property, that property gets a unique sub
directory instead.

The change covers the registrations of a root that is shared with other test
cases. Registrations of a fixed directory that only a single test case ever
writes to are left alone, since they cannot remove anything of others.

Reviews 3