Skip to content

[#488] Raise console command coverage and silence serve test logs#489

Merged
armanist merged 5 commits into
softberg:masterfrom
armanist:feature/488-console-command-coverage
May 1, 2026
Merged

[#488] Raise console command coverage and silence serve test logs#489
armanist merged 5 commits into
softberg:masterfrom
armanist:feature/488-console-command-coverage

Conversation

@armanist
Copy link
Copy Markdown
Member

@armanist armanist commented May 1, 2026

Closes #488

Summary by CodeRabbit

  • Tests

    • Expanded unit test coverage for console commands, including serve, debug bar, migration, and API operations.
    • Added tests for port validation, server readiness detection, browser opening, and resource file operations.
  • Refactor

    • Internal code reorganization to improve maintainability of server process handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@armanist has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 14 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e9ae1e28-0f01-4cfd-a073-f652bd158a64

📥 Commits

Reviewing files that changed from the base of the PR and between 370801d and dab86e9.

📒 Files selected for processing (3)
  • tests/Unit/Console/Commands/MigrationMigrateCommandTest.php
  • tests/Unit/Console/Commands/OpenApiCommandTest.php
  • tests/Unit/Console/Commands/ServeCommandTest.php
📝 Walkthrough

Walkthrough

This pull request expands unit test coverage for five console command classes to meet a >=70% coverage threshold. A minor refactoring extracts proc_open descriptor construction in ServeCommand into a dedicated method. The changes add behavior-oriented tests for argument parsing, exception handling, private method invocation via reflection, and end-to-end command execution scenarios across DebugBarCommand, MigrationMigrateCommand, OpenApiCommand, ResourceCacheClearCommand, and ServeCommand.

Changes

Cohort / File(s) Summary
ServeCommand refactoring
src/Console/Commands/ServeCommand.php
Extracted proc_open descriptor specification construction into a new protected serverProcessDescriptors() method.
DebugBarCommand tests
tests/Unit/Console/Commands/DebugBarCommandTest.php
Added unit test using reflection to verify private copyResources() method recursively copies root and nested asset files to target directory.
MigrationMigrateCommand tests
tests/Unit/Console/Commands/MigrationMigrateCommandTest.php
Added test validating command output when invoked with invalid direction parameter value.
OpenApiCommand tests
tests/Unit/Console/Commands/OpenApiCommandTest.php
Added three reflection-based tests: verifying openapiRoutes() output includes module name and spec path; confirming copyResources() excludes certain files while copying allowed assets; validating generateOpenapiSpecification() creates non-empty spec JSON.
ResourceCacheClearCommand tests
tests/Unit/Console/Commands/ResourceCacheClearCommandTest.php
Added reflection-based tests for private methods (initType, initModule, clearResourceModuleAndType) and end-to-end test for --all flag clearing entire cache directory.
ServeCommand tests
tests/Unit/Console/Commands/ServeCommandTest.php
Comprehensive test suite covering port range validation, server availability scanning, cleanup on failure, --open option execution, networking helpers with real sockets/processes, functional server startup/shutdown with temp files, and browser opening behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Issue/479 command coverage #485: Adds comprehensive test coverage for ServeCommand including port scanning and server readiness, complementing the refactored startPhpServer() method in this PR.

Suggested labels

testing

Poem

🐰 Five commands tested stem to root,
With coverage climbing toward the truth,
Reflection peeks at secrets deep,
While ports and processes we keep,
Seventy percent—our promise made! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: raising console command coverage and silencing serve test logs, with direct reference to the linked issue #488.
Linked Issues check ✅ Passed The PR adds comprehensive tests for all five target files to increase coverage above 70%, covering success/failure paths with behavior-oriented assertions as required by issue #488.
Out of Scope Changes check ✅ Passed All changes directly address the coverage objectives: test additions for DebugBarCommand, OpenApiCommand, MigrationMigrateCommand, ResourceCacheClearCommand, and refactoring of ServeCommand to improve testability.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 26 minutes and 14 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@armanist armanist added this to the 3.0.0 milestone May 1, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
tests/Unit/Console/Commands/ResourceCacheClearCommandTest.php (1)

83-92: Use a seeded temporary module directory instead of mocking the private $modules property.

The test sets modules to ['blog', 'shop'], but initModule() calls importModules() at line 150 before validation, which overwrites this fixture with actual modules from disk at line 124. This makes the test fragile and dependent on what modules exist on the filesystem. Seed a temporary module directory in the config instead to ensure test isolation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/Console/Commands/ResourceCacheClearCommandTest.php` around lines
83 - 92, Replace the fragile fixture that directly sets the private $modules
property in testInitModuleAcceptsKnownModule with a seeded temporary modules
directory so importModules() returns predictable modules: create a temp
directory containing 'blog' and 'shop' module folders, update the configuration
the command uses (so importModules() reads that temp path), call
initModule('BLOG') via ReflectionMethod as before, then assert the private
'module' property equals 'blog'; ensure cleanup of the temp directory after the
test. Use the test method name testInitModuleAcceptsKnownModule and target
initModule/importModules/modules to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/Unit/Console/Commands/MigrationMigrateCommandTest.php`:
- Around line 52-60: Update the
testExecWithInvalidDirectionShowsMigrationMessage test to assert the specific
migration-direction error text instead of just non-empty output: when invoking
CommandTester->execute(['direction' => 'invalid']) capture
CommandTester->getDisplay() and assert it contains the exact MigrationException
message emitted by the migration command (the migration-direction error string
used in the command's exception/throw path), e.g. assertStringContainsString or
equivalent comparing against that specific error constant/text from the
migration command or MigrationException so the test validates the new
invalid-direction branch.

In `@tests/Unit/Console/Commands/OpenApiCommandTest.php`:
- Around line 83-93: The test testOpenapiRoutesContainsModuleSpecPath assumes
backslashes in the path, which breaks on Linux; update the assertion to use the
platform separator when checking the module spec path returned by openapiRoutes
(located via ReflectionMethod in the test), e.g. build the expected substring
using DIRECTORY_SEPARATOR (or the DS constant used by the production code) like
'resources' . DIRECTORY_SEPARATOR . 'openapi' . DIRECTORY_SEPARATOR .
'spec.json' and assert that against the $routes from
$method->invoke($this->command, 'Blog').
- Around line 123-158: Wrap the temporary module/file setup and the invocation
of generateOpenapiSpecification in a try/finally block inside
testGenerateOpenapiSpecificationCreatesSpecFile so cleanup always runs; move the
ReflectionMethod creation/invoke and assertions into the try, and keep the
filesystem teardown (unlink/rmdir calls) in the finally to ensure modules_dir
artifacts are removed even if generateOpenapiSpecification throws.

In `@tests/Unit/Console/Commands/ServeCommandTest.php`:
- Around line 298-323: The test mutates the repository public/index.php; instead
create an isolated temporary project dir, write public/index.php there, chdir
into that temp dir before calling exposeStartPhpServer('127.0.0.1', $port) and
run exposeWaitUntilServerIsReady/exposeCleanupProcess against the process, then
restore the original cwd and remove the temp files in finally. Concretely:
create a unique temp directory (sys_get_temp_dir()/tempnam or similar), mkdir
$tmp . '/public', write the index file into $tmp/public/index.php, save getcwd()
to $originalCwd, chdir($tmp) before calling
exposeStartPhpServer/exposeWaitUntilServerIsReady/exposeCleanupProcess, and in
the finally block chdir($originalCwd) and delete the temp index and directory;
reference the test helpers exposeStartPhpServer, exposeWaitUntilServerIsReady,
and exposeCleanupProcess when locating changes.
- Around line 165-180: The test's mock returns a stream resource from
startPhpServer() but cleanupProcess() calls parent::cleanupProcess($process)
which ultimately calls proc_close() and triggers a TypeError; fix by either
having startPhpServer() return a real process resource created with proc_open()
(so parent::cleanupProcess can safely call proc_close), or add a type-guard
inside the test's cleanupProcess() to check the resource type (e.g.,
is_resource() && get_resource_type($process) === 'process') and only call
parent::cleanupProcess($process) for actual process resources, otherwise perform
appropriate stream cleanup.

---

Nitpick comments:
In `@tests/Unit/Console/Commands/ResourceCacheClearCommandTest.php`:
- Around line 83-92: Replace the fragile fixture that directly sets the private
$modules property in testInitModuleAcceptsKnownModule with a seeded temporary
modules directory so importModules() returns predictable modules: create a temp
directory containing 'blog' and 'shop' module folders, update the configuration
the command uses (so importModules() reads that temp path), call
initModule('BLOG') via ReflectionMethod as before, then assert the private
'module' property equals 'blog'; ensure cleanup of the temp directory after the
test. Use the test method name testInitModuleAcceptsKnownModule and target
initModule/importModules/modules to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a1741130-37bc-42b5-a262-b9b83a5595c1

📥 Commits

Reviewing files that changed from the base of the PR and between 0bf88cc and 370801d.

📒 Files selected for processing (6)
  • src/Console/Commands/ServeCommand.php
  • tests/Unit/Console/Commands/DebugBarCommandTest.php
  • tests/Unit/Console/Commands/MigrationMigrateCommandTest.php
  • tests/Unit/Console/Commands/OpenApiCommandTest.php
  • tests/Unit/Console/Commands/ResourceCacheClearCommandTest.php
  • tests/Unit/Console/Commands/ServeCommandTest.php

Comment thread tests/Unit/Console/Commands/MigrationMigrateCommandTest.php
Comment thread tests/Unit/Console/Commands/OpenApiCommandTest.php
Comment thread tests/Unit/Console/Commands/OpenApiCommandTest.php
Comment thread tests/Unit/Console/Commands/ServeCommandTest.php
Comment thread tests/Unit/Console/Commands/ServeCommandTest.php Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (0bf88cc) to head (dab86e9).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/Console/Commands/ServeCommand.php 14.28% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #489      +/-   ##
============================================
+ Coverage     89.10%   90.71%   +1.60%     
- Complexity     2904     2905       +1     
============================================
  Files           249      249              
  Lines          7653     7655       +2     
============================================
+ Hits           6819     6944     +125     
+ Misses          834      711     -123     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@armanist armanist merged commit 632f788 into softberg:master May 1, 2026
5 of 7 checks passed
@armanist armanist deleted the feature/488-console-command-coverage branch May 1, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase console command coverage to >=70% for key low-coverage files

1 participant