Bugfix Issue 1861 Requirement Mgr Assign To Tcase Unguarded Current - sebiboga/testlink-upgraded GitHub Wiki

Bugfix — Issue #1861: requirement_mgr::assign_to_tcase() — unguarded current(get_last_active_version())

Status: Fixed (PHP 8.3.35) Issue: #1861 — linking a requirement to a test case with no active version fatals TypeError: current(): Argument #1 ($array) must be of type array, null given at lib/functions/requirement_mgr.class.php:1132 (HTTP 500, 0 bytes from POST /api/requirements/assign-reqs).

Root cause

  • get_last_active_version() returns null when no active tcversions row exists for the target test case.
  • assign_to_tcase() did current($tcMgr->get_last_active_version(...)) with no cast/guard; PHP 8 throws TypeError before the if ($tcv == null) refusal executes.
  • Siblings in requirement_spec_mgr.class.php already used current((array)...) (missed here).

Fix

lib/functions/requirement_mgr.class.php (line 1132): cast to array so current() yields false and the existing null guard returns 0 (the documented "latest version inactive ⇒ operation not allowed" contract).

Evidence (measured)

  • CLI no-active → returns 0, no fatal; CLI active → returns 1, link created.
  • BFF POST /api/requirements/assign-reqs tcase with no active version → HTTP 200 {"status":"ok","failed":[...],"assigned_qty":0} (pre-fix 500/0 bytes); active path unchanged.
  • Event Viewer: no new Error/Warning.

Regression suite

Appended Regression — Issue #1861 to tmp/TLU_Test_Cases.md; TLU_REQUIRE_SUITE="Issue #1861" bash ai/verify_test_suites.sh → 7 PASS / 0 FAIL.

Files: lib/functions/requirement_mgr.class.php (1 statement + comment), tmp/TLU_Test_Cases.md, docs mirror + wiki page.