Skip to content

Strengthen console controller tests#20792

Open
WarLikeLaux wants to merge 10 commits into
yiisoft:masterfrom
WarLikeLaux:strengthen-console-controller-tests
Open

Strengthen console controller tests#20792
WarLikeLaux wants to merge 10 commits into
yiisoft:masterfrom
WarLikeLaux:strengthen-console-controller-tests

Conversation

@WarLikeLaux
Copy link
Copy Markdown
Contributor

@WarLikeLaux WarLikeLaux commented Mar 10, 2026

Q A
Is bugfix?
New feature?
Tests added? ✔️
Breaks BC?
Fixed issues

What does this PR do?

Adds tests for console controllers (CacheController, FixtureController, HelpController, ServeController, MigrateController, BaseMigrateController) to cover previously untested code paths.

Coverage

File Tests Lines MSI
CacheController.php 27 81/106 (76%) → 94/94 (100%) 87% (99/113)
FixtureController.php 51 0/188 (0%) → 169/171 (99%) 60% (155/256)
HelpController.php 9 → 36 225/269 (84%) → 251/252 (100%) 69% (321/460)
ServeController.php 5 → 8 41/45 (91%) → 37/40 (93%) 69% (39/56)
BaseMigrateController.php +47 132/348 (38%) → 312/323 (97%) N/A
MigrateController.php +34 58/249 (23%) → 234/239 (98%) N/A

CacheController and FixtureController had existing tests that required MySQL. New test classes (CacheControllerSqliteTest, FixtureControllerSqliteTest) test the same code without MySQL dependency, making them runnable in all CI environments.

MigrateController/BaseMigrateController MSI unavailable due to pre-existing test failures (template PHPDoc mismatch in testGenerateMigration, MySQL driver in testRefreshMigration#1).

Uncovered lines:

  • FixtureController:159,235 - dead code (defensive checks after getFixturesConfig() which always throws before returning empty)
  • HelpController:496 - dead branch ($type === null after trim((string)$type))
  • ServeController:135-136 - isAddressTaken() true path (needs real open port); 141 - passthru() in runCommand()
  • BaseMigrateController:488,490 - YII_ENV_PROD constant branch; 681,683 - file_put_contents failure; 815-823,975,998 - methods overridden in MigrateController
  • MigrateController:313-314,328 - FK dropping / non-view error (SQLite doesn't support DROP FOREIGN KEY); 491-492 - dead code (ReflectionException never thrown, DI wraps it in InvalidConfigException)

Changelog not required, because no source files changed.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.29%. Comparing base (203323d) to head (df1f374).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20792      +/-   ##
============================================
+ Coverage     80.43%   81.29%   +0.85%     
  Complexity    11541    11541              
============================================
  Files           374      374              
  Lines         30232    30232              
============================================
+ Hits          24317    24576     +259     
+ Misses         5915     5656     -259     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WarLikeLaux WarLikeLaux marked this pull request as ready for review March 10, 2026 19:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Tests
    • Expanded test coverage for console controllers (Cache, Fixture, Help, Migrate, and Serve) with comprehensive unit test suites covering various command scenarios, error handling, and user interaction flows to ensure reliability and stability.

Walkthrough

These changes add comprehensive test coverage for multiple Yii console controllers: a new test suite for CacheController validating cache discovery and flushing behavior, a new test suite for FixtureController covering fixture loading/unloading with global fixtures and error handling, and extended tests for HelpController, MigrateController, and ServeController to validate command discovery, migration operations, exit codes, and option handling.

Changes

Cohort / File(s) Summary
New Console Controller Test Suites
tests/framework/console/controllers/CacheControllerSqliteTest.php, tests/framework/console/controllers/FixtureControllerSqliteTest.php
Comprehensive new test classes with helper subclasses to validate controller action outputs, cache/fixture discovery, error handling for missing components, confirmation prompts, and special case handling (APC cache, global fixtures).
Extended Console Controller Tests
tests/framework/console/controllers/HelpControllerTest.php, tests/framework/console/controllers/MigrateControllerTest.php, tests/framework/console/controllers/ServeControllerTest.php
New test methods validating command/action resolution, help output formatting, exit codes, option metadata, and error handling for unknown commands and invalid arguments.
Migration Test Trait
tests/framework/console/controllers/MigrateControllerTestTrait.php
Added helper methods for generating failing migrations and expanded test coverage for migration history, validation, failure scenarios, and namespace-aware discovery.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With whiskers twitching and tests galore,
These controller suites open every door,
From fixtures loaded to caches flushed,
Through error cases neatly brushed,
Our test-warren's treasure hunt is complete! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.97% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Strengthen console controller tests' accurately summarizes the main change: adding comprehensive test coverage for console controllers.
Description check ✅ Passed The description is directly related to the changeset, providing a detailed breakdown of which console controllers are being tested, coverage metrics, and notes on uncovered lines and limitations.

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

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

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

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: 1

🤖 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/framework/console/controllers/FixtureControllerSqliteTest.php`:
- Around line 170-181: The load action emits a grammatically incorrect error
string ("could not be found according given conditions"); update the message in
the load handler to match the unload message by inserting "to" so it reads
"could not be found according to given conditions". Locate the load action
(method name likely actionLoad or the load branch in FixtureController) and
replace the incorrect string literal with the corrected one to ensure
consistency with the unload message used in the test (which asserts "could not
be found according to given conditions").
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b03259d0-6bae-4da9-baa3-2a572d4bfbb9

📥 Commits

Reviewing files that changed from the base of the PR and between 9265980 and bd4d191.

📒 Files selected for processing (6)
  • tests/framework/console/controllers/CacheControllerSqliteTest.php
  • tests/framework/console/controllers/FixtureControllerSqliteTest.php
  • tests/framework/console/controllers/HelpControllerTest.php
  • tests/framework/console/controllers/MigrateControllerTest.php
  • tests/framework/console/controllers/MigrateControllerTestTrait.php
  • tests/framework/console/controllers/ServeControllerTest.php

Comment thread tests/framework/console/controllers/FixtureControllerSqliteTest.php
@WarLikeLaux
Copy link
Copy Markdown
Contributor Author

image lit-baby

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.

2 participants