Skip to content

test: keep CommandsTest out of app/Commands so parallel runs do not race - #10564

Merged
paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:generators-test-commands-dir
Sep 19, 2026
Merged

paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:generators-test-commands-dir

Conversation

@paulbalandan

@paulbalandan paulbalandan commented Sep 15, 2026

Copy link
Copy Markdown
Member

Description

The random-order workflow runs components in parallel, and two of them share app/Commands/. That produces this failure in the Commands component:

GeneratorsTest::testSuffixingHasNoEffect
ErrorException: rmdir(/…/app/Commands): Directory not empty

CommandsTest::testDiscoveredCommandsCanBeOverridden (CLI component) copies a fixture into app/Commands/, while the generator tests (Commands component) create files there and remove the directory afterwards. Whenever the CLI fixture is present at that moment, the rmdir() throws. The reverse can also happen: the directory disappears between CommandsTest's mkdir() and copy().

This removes the sharing. CommandsTest no longer writes to app/. The override rule lives in Commands::discoverCommands() (the first class to claim a name wins), so the test require_onces the _command/ListCommands.php fixture and feeds discovery through a mocked locator that lists it ahead of the system ListCommands. This is the same pattern the neighbouring discovery tests use. The copy/delete helpers are gone.

The generator tests are untouched. Their rmdir() cleanup is safe because the Commands component is now the only user of that directory, and a component runs as a single sequential process. The tree is fully restored after both sequential and parallel runs, with no error suppression and no leftover app/Commands/.

Trade-off: the test no longer proves that the real locator lists App before system. It proves the override rule only. The ordering is FileLocator's own contract.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the testing Pull requests that changes tests only label Sep 15, 2026

@neznaika0 neznaika0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the tests, there’s still other junk left: the sqlite database, test images, empty folders, etc. Should they be deleted to fully revert to the original state?

If so, then the empty folders probably need to be cleaned up.

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the simpler solution be to use @rmdir($dir) here - after all, these are just test cleanups (we can add an inline comment for the reason we use these)?

That way we still clean up the directory when it's empty, but we don't fail if another test happens to be using it at the same time.

@paulbalandan
paulbalandan force-pushed the generators-test-commands-dir branch from 70adeab to c8fa36a Compare September 18, 2026 07:51
@paulbalandan paulbalandan changed the title test: stop removing app/Commands so parallel CLI and Commands runs does not race test: keep CommandsTest out of app/Commands so parallel runs do not race Sep 18, 2026
@paulbalandan

Copy link
Copy Markdown
Member Author

The issue here is that both CLI and Commands use the app/Commands/ so an rmdir in one component might corrupt the other one. The alternative I pushed is have Commands own that directly, and rework CLI tests so that it won;t touch app/Commands.

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thank you - let's see how this works for us.

@paulbalandan
paulbalandan merged commit 744e717 into codeigniter4:develop Sep 19, 2026
57 checks passed
@paulbalandan
paulbalandan deleted the generators-test-commands-dir branch September 19, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Pull requests that changes tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants