Skip to content

Add unit tests for AssetManager#20789

Open
WarLikeLaux wants to merge 7 commits into
yiisoft:masterfrom
WarLikeLaux:add-AssetManagerTest
Open

Add unit tests for AssetManager#20789
WarLikeLaux wants to merge 7 commits into
yiisoft:masterfrom
WarLikeLaux:add-AssetManagerTest

Conversation

@WarLikeLaux

@WarLikeLaux WarLikeLaux commented Mar 9, 2026

Copy link
Copy Markdown
Contributor
Q A
Is bugfix?
New feature?
Tests added? ✔️
Breaks BC?
Fixed issues

What does this PR do?

Adds AssetManagerTest - unit tests for AssetManager.

Coverage

69 tests. Line coverage: 149/149 (100%). MSI: 94% (265/281).

Changelog not required, because no source files changed.

@codecov

codecov Bot commented Mar 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.65%. Comparing base (d77f4bb) to head (3629f9e).

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20789      +/-   ##
============================================
+ Coverage     80.44%   80.65%   +0.20%     
  Complexity    11540    11540              
============================================
  Files           374      374              
  Lines         30235    30235              
============================================
+ Hits          24323    24385      +62     
+ Misses         5912     5850      -62     

☔ View full report in Codecov by Harness.
📢 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.

@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6fa6af5f-9011-4179-a75f-1d76832a7ea6

📥 Commits

Reviewing files that changed from the base of the PR and between 792e600 and 679fed5.

📒 Files selected for processing (3)
  • tests/data/web/AssetManagerTestSimpleBundle.php
  • tests/data/web/AssetManagerTestSourceBundle.php
  • tests/framework/web/AssetManagerTest.php
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: SQLite tests with coverage / PHP 7.4-ubuntu-22.04
  • GitHub Check: phpstan-7x / PHP 7.4-ubuntu-latest
  • GitHub Check: phpcs / PHP 7.4-ubuntu-latest
  • GitHub Check: phpstan / PHP 8.5-ubuntu-latest
  • GitHub Check: MSSQL tests with coverage / PHP 8.5-mssql-2022-latest
  • GitHub Check: PHP 8.3
  • GitHub Check: NPM 10 on ubuntu-22.04
  • GitHub Check: PHP 8.1
  • GitHub Check: PHP 8.6
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2026-04-11T18:58:31.942Z
Learnt from: terabytesoftw
Repo: yiisoft/yii2 PR: 20817
File: tests/framework/grid/CheckboxColumnTest.php:45-49
Timestamp: 2026-04-11T18:58:31.942Z
Learning: In the yiisoft/yii2 test suite (e.g., under tests/**), PHPMD `UnusedFormalParameter` warnings on test helper methods that are intentionally no-ops (such as trait hook methods like `triggerClientScriptDispatch`) should not be suppressed with annotations. Treat these as acceptable static-analysis nitpicks in test code and only suppress/adjust when the parameter is genuinely not required due to real dead code concerns.

Applied to files:

  • tests/data/web/AssetManagerTestSourceBundle.php
  • tests/data/web/AssetManagerTestSimpleBundle.php
  • tests/framework/web/AssetManagerTest.php
📚 Learning: 2026-04-14T10:43:29.381Z
Learnt from: terabytesoftw
Repo: yiisoft/yii2 PR: 20820
File: tests/framework/console/ControllerTest.php:324-328
Timestamp: 2026-04-14T10:43:29.381Z
Learning: In yiisoft/yii2 PHP tests that assert union-type stringification, remember that `ReflectionUnionType::getTypes()` does not preserve the source declaration order. When building the expected string, follow PHP’s canonical ordering: built-in scalar types are returned in the fixed order `static, callable, array, string, int, float, bool, null`, while class/interface types come first in their declaration order. For example, a parameter declared as `int|string` should stringify to `string|int` (not `int|string`). Ensure test assertions match this canonical ordering.

Applied to files:

  • tests/data/web/AssetManagerTestSourceBundle.php
  • tests/data/web/AssetManagerTestSimpleBundle.php
  • tests/framework/web/AssetManagerTest.php
📚 Learning: 2026-04-21T21:24:32.138Z
Learnt from: terabytesoftw
Repo: yiisoft/yii2 PR: 20829
File: framework/db/mssql/QueryBuilder.php:678-683
Timestamp: 2026-04-21T21:24:32.138Z
Learning: In yiisoft/yii2, follow the existing PHPStan configuration: `empty()` is explicitly prohibited. When reviewing PHP code, do not recommend replacing strict checks like `$var === null || $var === []` (or similar null/empty-array logic) with `empty($var)`, since that would conflict with the codebase’s `empty()` policy.

Applied to files:

  • tests/data/web/AssetManagerTestSourceBundle.php
  • tests/data/web/AssetManagerTestSimpleBundle.php
  • tests/framework/web/AssetManagerTest.php
📚 Learning: 2026-05-01T02:09:33.591Z
Learnt from: terabytesoftw
Repo: yiisoft/yii2 PR: 20842
File: tests/framework/base/ModuleTest.php:481-519
Timestamp: 2026-05-01T02:09:33.591Z
Learning: In the yiisoft/yii2 test suite, remember that `Yii::setAlias()` stores the alias value as an exact string and `Yii::getAlias()` returns that same exact string with no path-separator normalization. As a result, tests that verify alias round-trips through `yii\base\Module::setViewPath()/getViewPath()` and `Module::setLayoutPath()/getLayoutPath()` should assert strict string equality on the stored vs. retrieved values, and do not apply platform-specific directory separator normalization.

Applied to files:

  • tests/data/web/AssetManagerTestSourceBundle.php
  • tests/data/web/AssetManagerTestSimpleBundle.php
  • tests/framework/web/AssetManagerTest.php
🪛 PHPMD (2.15.0)
tests/data/web/AssetManagerTestSourceBundle.php

[warning] 16-18: Avoid variables with short names like $js. Configured minimum length is 3. (undefined)

(ShortVariable)

tests/data/web/AssetManagerTestSimpleBundle.php

[warning] 17-19: Avoid variables with short names like $js. Configured minimum length is 3. (undefined)

(ShortVariable)

tests/framework/web/AssetManagerTest.php

[warning] 28-969: The class AssetManagerTest has 69 public methods and attributes. Consider reducing the number of public items to less than 45. (undefined)

(ExcessivePublicCount)


[warning] 28-969: The class AssetManagerTest has 72 non-getter- and setter-methods. Consider refactoring AssetManagerTest to keep number of methods under 25. (undefined)

(TooManyMethods)


[warning] 28-969: The class AssetManagerTest has 69 public methods. Consider refactoring AssetManagerTest to keep number of public methods under 10. (undefined)

(TooManyPublicMethods)


[warning] 28-969: The class AssetManagerTest has an overall complexity of 84 which is very high. The configured complexity threshold is 50. (undefined)

(ExcessiveClassComplexity)


[error] 37-37: Avoid using static access to class '\Yii' in method 'setUp'. (undefined)

(StaticAccess)


[error] 38-38: Avoid using static access to class '\Yii' in method 'setUp'. (undefined)

(StaticAccess)


[error] 39-39: Avoid using static access to class '\Yii' in method 'setUp'. (undefined)

(StaticAccess)


[error] 40-40: Avoid using static access to class '\Yii' in method 'setUp'. (undefined)

(StaticAccess)


[error] 41-41: Avoid using static access to class '\Yii' in method 'setUp'. (undefined)

(StaticAccess)


[error] 43-43: Avoid using static access to class '\Yii' in method 'setUp'. (undefined)

(StaticAccess)


[error] 65-65: Avoid using static access to class '\yii\helpers\FileHelper' in method 'cleanAssetsDir'. (undefined)

(StaticAccess)


[error] 66-68: The method cleanAssetsDir uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. (undefined)

(ElseExpression)


[error] 67-67: Avoid using static access to class '\yii\helpers\FileHelper' in method 'cleanAssetsDir'. (undefined)

(StaticAccess)


[warning] 82-82: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 84-84: Avoid using static access to class '\Yii' in method 'testInitResolvesBasePathAlias'. (undefined)

(StaticAccess)


[warning] 89-89: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 95-95: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 106-106: Avoid using static access to class '\Yii' in method 'testCheckBasePathPermissionThrowsOnNonWritableDir'. (undefined)

(StaticAccess)


[error] 107-107: Avoid using static access to class '\yii\helpers\FileHelper' in method 'testCheckBasePathPermissionThrowsOnNonWritableDir'. (undefined)

(StaticAccess)


[error] 111-111: Avoid using static access to class '\yii\helpers\FileHelper' in method 'testCheckBasePathPermissionThrowsOnNonWritableDir'. (undefined)

(StaticAccess)


[warning] 115-115: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 124-124: Avoid using static access to class '\yii\helpers\FileHelper' in method 'testCheckBasePathPermissionThrowsOnNonWritableDir'. (undefined)

(StaticAccess)


[warning] 130-130: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 139-139: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 152-152: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 166-166: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 179-179: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 193-193: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 206-206: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 215-215: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 225-225: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 235-235: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 245-245: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 256-256: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 266-266: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 275-275: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 284-284: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 285-285: Avoid using static access to class '\Yii' in method 'testPublishFileByPath'. (undefined)

(StaticAccess)


[warning] 298-298: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 299-299: Avoid using static access to class '\Yii' in method 'testPublishDirectoryByPath'. (undefined)

(StaticAccess)


[warning] 310-310: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 311-311: Avoid using static access to class '\Yii' in method 'testPublishReturnsCachedResult'. (undefined)

(StaticAccess)


[warning] 321-321: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 341-341: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 353-353: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 354-354: Avoid using static access to class '\Yii' in method 'testPublishFileWithLinkAssets'. (undefined)

(StaticAccess)


[warning] 364-364: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 365-365: Avoid using static access to class '\Yii' in method 'testPublishDirectoryWithLinkAssets'. (undefined)

(StaticAccess)


[error] 372-372: Avoid using static access to class '\yii\helpers\FileHelper' in method 'testPublishDirectoryWithLinkAssets'. (undefined)

(StaticAccess)


[error] 375-398: Remove error control operator '@' on line 388. (undefined)

(ErrorControlOperator)


[warning] 380-380: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 381-381: Avoid using static access to class '\Yii' in method 'testPublishFileWithLinkAssetsRethrowsOnSymlinkFailure'. (undefined)

(StaticAccess)


[error] 387-387: Avoid using static access to class '\yii\helpers\FileHelper' in method 'testPublishFileWithLinkAssetsRethrowsOnSymlinkFailure'. (undefined)

(StaticAccess)


[error] 400-421: Remove error control operator '@' on line 411. (undefined)

(ErrorControlOperator)


[warning] 405-405: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 406-406: Avoid using static access to class '\Yii' in method 'testPublishDirectoryWithLinkAssetsRethrowsOnSymlinkFailure'. (undefined)

(StaticAccess)


[warning] 429-429: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 430-430: Avoid using static access to class '\Yii' in method 'testPublishFileWithFileMode'. (undefined)

(StaticAccess)


[warning] 440-440: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 441-441: Avoid using static access to class '\Yii' in method 'testPublishFileWithAppendTimestamp'. (undefined)

(StaticAccess)


[warning] 450-450: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 451-451: Avoid using static access to class '\Yii' in method 'testPublishFileWithoutAppendTimestamp'. (undefined)

(StaticAccess)


[warning] 461-461: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 462-462: Avoid unused parameters such as '$from'. (undefined)

(UnusedFormalParameter)


[warning] 462-462: Avoid unused parameters such as '$to'. (undefined)

(UnusedFormalParameter)


[error] 467-467: Avoid using static access to class '\Yii' in method 'testPublishDirectoryWithAfterCopy'. (undefined)

(StaticAccess)


[warning] 476-476: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 482-482: Avoid using static access to class '\Yii' in method 'testPublishDirectoryOptionsAfterCopyOverridesClassAfterCopy'. (undefined)

(StaticAccess)


[warning] 483-483: Avoid unused parameters such as '$from'. (undefined)

(UnusedFormalParameter)


[warning] 483-483: Avoid unused parameters such as '$to'. (undefined)

(UnusedFormalParameter)


[warning] 495-495: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 496-496: Avoid unused parameters such as '$to'. (undefined)

(UnusedFormalParameter)


[error] 501-501: Avoid using static access to class '\Yii' in method 'testPublishDirectoryWithForceCopyOption'. (undefined)

(StaticAccess)


[warning] 515-515: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 517-517: Avoid unused parameters such as '$to'. (undefined)

(UnusedFormalParameter)


[error] 522-522: Avoid using static access to class '\Yii' in method 'testPublishDirectoryWithForceCopyProperty'. (undefined)

(StaticAccess)


[warning] 536-536: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 538-538: Avoid unused parameters such as '$to'. (undefined)

(UnusedFormalParameter)


[error] 543-543: Avoid using static access to class '\Yii' in method 'testPublishDirectoryForceCopyOptionFalseOverridesProperty'. (undefined)

(StaticAccess)


[warning] 558-558: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 559-559: Avoid using static access to class '\Yii' in method 'testGetPublishedPathForPublishedFile'. (undefined)

(StaticAccess)


[warning] 570-570: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 571-571: Avoid using static access to class '\Yii' in method 'testGetPublishedPathForUnpublishedFile'. (undefined)

(StaticAccess)


[warning] 582-582: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 583-583: Avoid using static access to class '\Yii' in method 'testGetPublishedPathForDirectory'. (undefined)

(StaticAccess)


[warning] 595-595: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 602-602: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 603-603: Avoid using static access to class '\Yii' in method 'testGetPublishedPathUsesCache'. (undefined)

(StaticAccess)


[warning] 610-610: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 611-611: Avoid using static access to class '\Yii' in method 'testGetPublishedUrlForPublishedFile'. (undefined)

(StaticAccess)


[warning] 622-622: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 623-623: Avoid using static access to class '\Yii' in method 'testGetPublishedUrlForUnpublishedFile'. (undefined)

(StaticAccess)


[warning] 635-635: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 636-636: Avoid using static access to class '\Yii' in method 'testGetPublishedUrlForDirectory'. (undefined)

(StaticAccess)


[warning] 648-648: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 655-655: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 656-656: Avoid using static access to class '\Yii' in method 'testGetPublishedUrlUsesCache'. (undefined)

(StaticAccess)


[warning] 663-663: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 664-664: Avoid unused parameters such as '$path'. (undefined)

(UnusedFormalParameter)


[error] 668-668: Avoid using static access to class '\Yii' in method 'testHashWithCustomCallback'. (undefined)

(StaticAccess)


[warning] 677-677: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 679-679: Avoid using static access to class '\Yii' in method 'testGetAssetUrlWithRelativeAsset'. (undefined)

(StaticAccess)


[warning] 689-689: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 700-700: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 711-711: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 713-713: Avoid using static access to class '\Yii' in method 'testGetAssetUrlWithAppendTimestampEnabled'. (undefined)

(StaticAccess)


[warning] 723-723: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 725-725: Avoid using static access to class '\Yii' in method 'testGetAssetUrlWithAppendTimestampDisabled'. (undefined)

(StaticAccess)


[warning] 735-735: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 737-737: Avoid using static access to class '\Yii' in method 'testGetAssetUrlWithPerAssetTimestampOverride'. (undefined)

(StaticAccess)


[warning] 747-747: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 749-749: Avoid using static access to class '\Yii' in method 'testGetAssetUrlWithPerAssetTimestampDisableOverride'. (undefined)

(StaticAccess)


[warning] 759-759: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 774-774: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 780-780: Avoid using static access to class '\Yii' in method 'testGetAssetUrlWithAssetMapSuffixMatch'. (undefined)

(StaticAccess)


[warning] 790-790: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 804-804: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 806-806: Avoid using static access to class '\Yii' in method 'testGetAssetPathForRelativeAsset'. (undefined)

(StaticAccess)


[error] 810-810: Avoid using static access to class '\Yii' in method 'testGetAssetPathForRelativeAsset'. (undefined)

(StaticAccess)


[warning] 815-815: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 817-817: Avoid using static access to class '\Yii' in method 'testGetAssetPathReturnsFalseForAbsoluteUrl'. (undefined)

(StaticAccess)


[warning] 824-824: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 830-830: Avoid using static access to class '\Yii' in method 'testGetAssetPathWithAssetMapReturnsBasePath'. (undefined)

(StaticAccess)


[warning] 839-839: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 850-850: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 864-864: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 879-879: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 892-892: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 907-907: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 922-922: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 933-933: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 947-947: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)


[warning] 961-961: Avoid variables with short names like $am. Configured minimum length is 3. (undefined)

(ShortVariable)

🔇 Additional comments (3)
tests/framework/web/AssetManagerTest.php (1)

1-969: LGTM!

tests/data/web/AssetManagerTestSimpleBundle.php (1)

1-21: LGTM!

tests/data/web/AssetManagerTestSourceBundle.php (1)

1-23: LGTM!


📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for asset management: initialization, bundle retrieval, publishing (files/dirs, symlink/linking), caching, converter/config handling, permissions/errors, copy hooks, timestamping, and URL/path resolution.
    • Added new test fixtures representing simple and source asset bundles to exercise publishing and resolving behaviors.

Walkthrough

Adds a comprehensive PHPUnit test suite for yii\web\AssetManager plus two test AssetBundle fixtures, exercising initialization, bundles/converter, publishing (copy/link), caching, asset mapping, and URL/path resolution.

Changes

Asset Manager Test Suite

Layer / File(s) Summary
Test setup and fixtures
tests/framework/web/AssetManagerTest.php, tests/data/web/AssetManagerTestSimpleBundle.php, tests/data/web/AssetManagerTestSourceBundle.php
Test scaffolding: mocked application, aliases, asset directories, and two test bundle classes for use across suite.
Initialization & basePath checks
tests/framework/web/AssetManagerTest.php
Alias resolution, baseUrl trimming, checkBasePathPermission() error cases and caching of permission checks.
Bundle retrieval & caching
tests/framework/web/AssetManagerTest.php
getBundle() behaviors: disabled bundles, false entries, array-config loading, InvalidConfigException, class-name instantiation, source bundle publishing.
Converter creation & caching
tests/framework/web/AssetManagerTest.php
getConverter() default creation and configuration via array/string/instance, with caching tests.
Publishing (file/dir) and symlink mode
tests/framework/web/AssetManagerTest.php
File and directory publishing, publish-result caching, error cases for missing/unreadable paths, link-asset symlink behavior and symlink-failure rethrow handling.
Publishing options and callbacks
tests/framework/web/AssetManagerTest.php
File mode application, appendTimestamp behavior, afterCopy callback and per-call override, forceCopy and beforeCopy interactions.
Published path/url and hash callback
tests/framework/web/AssetManagerTest.php
getPublishedPath()/getPublishedUrl() for published/unpublished inputs, directory handling, false for missing paths, cache usage, and custom hashCallback test.
getAssetUrl() and timestamping
tests/framework/web/AssetManagerTest.php
Relative/absolute/protocol-relative URL handling and global/per-asset appendTimestamp semantics.
Asset map and path resolution
tests/framework/web/AssetManagerTest.php
Asset map exact/suffix matching, @web alias mapping, getAssetPath() resolution and rejection of absolute mapped URLs.
resolveAsset() and getActualAssetUrl()
tests/framework/web/AssetManagerTest.php
resolveAsset() tests for sourcePath suffix matching and missing map; getActualAssetUrl() alias handling, fallback to bundle baseUrl, and absolute/slash-prefixed preservation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I hop through tests both crisp and spry,
I stamp my paws on asset paths nearby,
Bundles, links, and timestamps in a line,
I copy, hash, and publish — all is fine,
A rabbit's cheer for AssetManager's shine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Title check ✅ Passed The title 'Add unit tests for AssetManager' directly and clearly describes the primary change—adding unit tests for the AssetManager class.
Description check ✅ Passed The description is directly related to the changeset, clearly stating that it adds AssetManagerTest unit tests for AssetManager with coverage metrics and test counts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
tests/framework/web/AssetManagerTest.php (2)

51-69: Close directory handle via finally for safer cleanup paths.

If an exception is thrown during deletion, closedir() may be skipped. Wrapping the loop in try/finally makes cleanup deterministic.

♻️ Proposed refactor
 private function cleanAssetsDir(): void
 {
     $handle = opendir($this->assetsPath);
     if ($handle === false) {
         return;
     }
-    while (($file = readdir($handle)) !== false) {
-        if ($file === '.' || $file === '..' || $file === '.gitignore') {
-            continue;
-        }
-        $path = $this->assetsPath . DIRECTORY_SEPARATOR . $file;
-        if (is_dir($path)) {
-            FileHelper::removeDirectory($path);
-        } else {
-            FileHelper::unlink($path);
-        }
+    try {
+        while (($file = readdir($handle)) !== false) {
+            if ($file === '.' || $file === '..' || $file === '.gitignore') {
+                continue;
+            }
+            $path = $this->assetsPath . DIRECTORY_SEPARATOR . $file;
+            if (is_dir($path)) {
+                FileHelper::removeDirectory($path);
+            } else {
+                FileHelper::unlink($path);
+            }
+        }
+    } finally {
+        closedir($handle);
     }
-    closedir($handle);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/framework/web/AssetManagerTest.php` around lines 51 - 69, The
cleanAssetsDir function currently opens a directory with
opendir($this->assetsPath) and calls closedir($handle) at the end, but an
exception during the readdir/unlink/removeDirectory loop can skip closedir; wrap
the while-loop and deletion logic in a try { ... } finally { closedir($handle);
} block after checking $handle !== false so the handle is always closed, while
preserving the early return when opendir fails and keeping calls to
FileHelper::removeDirectory and FileHelper::unlink unchanged.

673-817: Consider extracting bundle setup helpers to reduce test boilerplate.

AssetManagerTestSimpleBundle creation and basePath/baseUrl assignments are repeated across many tests; a small helper would improve readability and reduce drift.

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

In `@tests/framework/web/AssetManagerTest.php` around lines 673 - 817, Many tests
repeat creating AssetManagerTestSimpleBundle and setting basePath/baseUrl;
extract a small helper (e.g., a private method in the test class like
createBundle or setupBundle) that accepts optional basePath and baseUrl and
returns a configured AssetManagerTestSimpleBundle, then update existing tests
(e.g., testGetAssetUrlWithRelativeAsset, testGetAssetUrlWithAbsoluteUrl,
testGetAssetUrlWithAppendTimestampEnabled, testGetAssetPathForRelativeAsset,
testGetAssetPathReturnsFalseForAbsoluteUrl, etc.) to call createBundle(...)
instead of repeating the instantiation and property assignments; keep
createManager(...) calls as-is and ensure the helper uses Yii::getAlias when
resolving default paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/framework/web/AssetManagerTest.php`:
- Around line 51-69: The cleanAssetsDir function currently opens a directory
with opendir($this->assetsPath) and calls closedir($handle) at the end, but an
exception during the readdir/unlink/removeDirectory loop can skip closedir; wrap
the while-loop and deletion logic in a try { ... } finally { closedir($handle);
} block after checking $handle !== false so the handle is always closed, while
preserving the early return when opendir fails and keeping calls to
FileHelper::removeDirectory and FileHelper::unlink unchanged.
- Around line 673-817: Many tests repeat creating AssetManagerTestSimpleBundle
and setting basePath/baseUrl; extract a small helper (e.g., a private method in
the test class like createBundle or setupBundle) that accepts optional basePath
and baseUrl and returns a configured AssetManagerTestSimpleBundle, then update
existing tests (e.g., testGetAssetUrlWithRelativeAsset,
testGetAssetUrlWithAbsoluteUrl, testGetAssetUrlWithAppendTimestampEnabled,
testGetAssetPathForRelativeAsset, testGetAssetPathReturnsFalseForAbsoluteUrl,
etc.) to call createBundle(...) instead of repeating the instantiation and
property assignments; keep createManager(...) calls as-is and ensure the helper
uses Yii::getAlias when resolving default paths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: be82af6b-7415-4f9c-bfa9-89e5d4dafdb0

📥 Commits

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

📒 Files selected for processing (1)
  • tests/framework/web/AssetManagerTest.php

@terabytesoftw terabytesoftw added the status:code review The pull request needs review. label Apr 9, 2026
Comment thread tests/framework/web/AssetManagerTest.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants