Skip to content

Bugfix Issue 642 TestAutomationSpec Empty Spec 500

github-actions[bot] edited this page Aug 23, 2026 · 1 revision

Issue 642 — testAutomationSpec.php HTTP 500 + foreach-null E_WARNING on empty spec

Issue: #642 Branch: fix/issue-642 Status: FIXED & VERIFIED (2026-08-23)

Symptom

Direct export / view of Test Automation (lib/results/testAutomationSpec.php?...&format=1&spreadsheet=1) returned HTTP 500 with an empty body whenever the test project's spec contains no test cases (reported variant: plan with no linked test cases). Each request also wrote two events:

id level description
12 32 (L18N) string 'report_test_automation' is not localized for locale 'en_GB'
13 2 (E_WARNING) `foreach() argument must be of type array

after fix — empty spec renders graceful empty report

Root cause chain (verified by reproduction, PHP 8.3.33)

  1. lib/results/testAutomationSpec.php:73 — lang_get('report_test_automation'); key existed in 0 of 19 locale bundles → L18N event on every view.
  2. getTestSpecFromNode() always runs with the controller's mandatory filter $filters = array('exec_type' => TESTCASE_EXECUTION_TYPE_AUTO) ⇒ $applyFilters = true.
  3. With zero testcase nodes in the subtree, the collection loop never writes $itemSet, which stayed null.
  4. foreach($itemKeys …) over null → E_WARNING (specview.php:792).
  5. count($itemSet) → uncaught TypeError on PHP 8 (count(): Argument #1 ($value) must be of type Countable|array, null given, specview.php:810) → HTTP 500. Proven with a CLI harness: TypeError at specview.php:810 ← getTestSpecFromNode() ← genSpecViewFlat() (1559).

Sibling of #428 (guarded the end of the same pipeline); this entry hop was missed because the crash precedes any statistics code.

Fix approach (minimal, semantics-preserving)

In getTestSpecFromNode() (lib/functions/specview.php):

$key2loop = is_null($test_spec) ? array() : array_keys($test_spec);
$itemSet = array();   // was: null

Empty $itemSet = "nothing to filter" → suite-only spec returned unchanged; all three call sites already guard with !empty($test_spec); template renders through its existing {if $gui->has_tc} guard.

Rejected alternatives: early null return (changes contract for 3 call sites); controller-only guard (leaves gen_spec_view() exposed).

i18n fix

$TLS_report_test_automation added to the 15 bundles lacking it (cs_CZ, de_DE, en_GB, es_AR, es_ES, fi_FI, id_ID, it_IT, ja_JP, ko_KR, nl_NL, pl_PL, ro_RO, ru_RU, zh_CN); en_US/fr_FR/pt_BR/pt_PT already had it. Localized values for major locales (ro_RO: „Raport de automatizare a testării"). All bundles validated via PHP include.

Verification matrix (Suite 642 in tmp/TLU_Test_Cases.md)

Case Before After
empty project direct export HTTP 500 + 2 events HTTP 200 graceful, 0 events
project WITH auto TCs rows rendered rows unchanged, 0 events
only-manual project OK since #428 still OK, 0 events
title en_GB / ro_RO L18N warning localized titles, no event

Event Viewer clean across all matrix rows.

after fix — non-empty project lists AUTO test cases

Clone this wiki locally