Skip to content

test: make Commands tests random-order safe#10169

Open
memleakd wants to merge 8 commits intocodeigniter4:developfrom
memleakd:refactor/random-tests-commands
Open

test: make Commands tests random-order safe#10169
memleakd wants to merge 8 commits intocodeigniter4:developfrom
memleakd:refactor/random-tests-commands

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

@memleakd memleakd commented May 6, 2026

Description

Related to #9968.

This one took a few rounds: every time the Commands suite looked settled, another bit of shared test state quietly raised its hand. The result is a more random-order-safe Commands component, plus a couple of small fixes in shared code that the random runs exposed along the way.

This enables Commands in the random test config and updates the affected tests so they own their setup/cleanup instead of depending on earlier tests running first.

Main changes:

  • reset scaffold test CLI state and make generated command/scaffold cleanup reliable between tests
  • isolate migration command tests from generated App migrations and leftover tables
  • make database command tests seed and select their own expected state
  • close/reset shared database connections before deleting SQLite test databases
  • restore locale/config state in translation command tests
  • reset mocked cache services after cache command tests
  • make the Unsuffixable support command provide its own template data

This PR also touches a few areas outside tests/system/Commands because the failures were not purely local to one test class:

  • system/Commands/Database/ShowTableInfo.php now keeps db:table --show display IDs sequential even when table arrays have sparse keys
  • system/HotReloader/DirectoryHasher.php now hashes files in a stable order, which avoids filesystem traversal order differences
  • system/Cache/FactoriesCache/FileVarExportHandler.php now guards cache writes against concurrent cleanup/recreation races
  • tests/system/HotReloader/DirectoryHasherTest.php now uses isolated writable fixtures instead of shared app/system directories
  • system/Log/Handlers/FileHandler.php now treats the final chmod after creating a log file as best-effort, so concurrent log cleanup cannot turn logging into a test/app error

Verified locally:

  • repeated random-order Commands runs, including failed CI seeds
  • HotReloader, Cookie random-order runs
  • composer phpstan:check
  • vendor/bin/rector process --dry-run
  • composer cs

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

@memleakd memleakd force-pushed the refactor/random-tests-commands branch 12 times, most recently from 96ce295 to 0fd35c5 Compare May 7, 2026 00:15
memleakd added 2 commits May 7, 2026 02:17
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@memleakd memleakd force-pushed the refactor/random-tests-commands branch from 0fd35c5 to 33e12fc Compare May 7, 2026 00:31
memleakd added 6 commits May 7, 2026 02:40
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
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.

1 participant