test(boundary): 新增 CoreBoundaryTest,並補完 PR-I 的兩個缺漏測試
Anti-EAV Lint + Quality Gate / anti-eav-lint (push) Successful in 9s
Tests / Unit Tests (push) Successful in 9s
Tests / Integration Tests (push) Successful in 31s
Tests / PHP Lint (push) Successful in 8s
Tests / PHPCS (push) Successful in 20s
Tests / PHPStan (push) Successful in 24s

CoreBoundaryTest 靜態掃描核心 126 個生產檔,斷言每一處對 AddOn 類別的
static 呼叫都在同一個函式內有 class_exists() 守衛。上一個 commit 修的
TMDO_Listing_Stats fatal 就是這類缺陷,這個測試讓它不會再回來。

它當場又抓到 3 處同類違規(都是實際會 fatal 的路徑),一併修掉:
- admin render_hpct_import():改印 admin notice 並 return
- wp tmdo import-hpct:改 WP_CLI::error 明示需要 hivepress-addon
- cli-post cleanup-hp-transients 其實早有守衛,是測試的行距啟發式太窄;
  判斷範圍改成「同一個函式內」而非固定 12 行

負向驗證:暫時注入一處無守衛呼叫 → 測試如預期失敗;還原後回綠。

同時補完計畫階段 7 PR-I 列的兩個缺漏測試:
- 核心 tests/unit/StandardPostInterceptorTest.php(10 tests)
- HP AddOn tests/unit/ListingStatsTest.php(9 tests)——AddOn 的 unit
  bootstrap 先前刻意不載入真實 TMDO_Listing_Stats,改以
  TMDO_TEST_SKIP_LISTING_STATS_STUB 常數讓它跳過核心的 stub
- 核心 unit bootstrap 補 add_post_meta() stub(flush 路徑用得到)

核心 unit 451 → 587、HP AddOn 145 → 154。
This commit is contained in:
2026-07-31 10:41:13 +08:00
parent d52d604d7a
commit e33ae4e626
5 changed files with 396 additions and 1 deletions
+12 -1
View File
@@ -253,6 +253,15 @@ if ( ! function_exists( 'update_post_meta' ) ) {
return true;
}
}
if ( ! function_exists( 'add_post_meta' ) ) {
function add_post_meta( int $post_id, string $key, $value, bool $unique = false ): int|bool {
if ( $unique && isset( $GLOBALS['_wp_postmeta'][ $post_id ][ $key ] ) ) {
return false;
}
$GLOBALS['_wp_postmeta'][ $post_id ][ $key ] = $value;
return 1;
}
}
if ( ! function_exists( 'get_user_meta' ) ) {
function get_user_meta( int $uid, string $key = '', bool $single = false ) {
return $GLOBALS['_wp_usermeta'][ $uid ][ $key ] ?? ( $single ? '' : [] );
@@ -661,7 +670,9 @@ add_filter( 'wpdo/fsm_guard/bypass', '__return_true' );
// TMDO_Listing_Stats → 2meet-data-optimizer-hivepress-addon.
// Tests that hit REST endpoints using listing stats receive stub responses.
if ( ! class_exists( 'TMDO_Listing_Stats' ) ) {
// The HivePress AddOn's own suite defines TMDO_TEST_SKIP_LISTING_STATS_STUB so
// it can load the real class instead of this stub.
if ( ! defined( 'TMDO_TEST_SKIP_LISTING_STATS_STUB' ) && ! class_exists( 'TMDO_Listing_Stats' ) ) {
class TMDO_Listing_Stats {
public static function register(): void {}
public static function get_view_count( int $post_id ): int { return 0; }