Skip to content

fix: decode Pest v4 php_qn:// evaluable format for describe(FQN::class) dataset tests#408

Merged
recca0120 merged 9 commits into
mainfrom
fix/pest-dataset-class-constant
Mar 13, 2026
Merged

fix: decode Pest v4 php_qn:// evaluable format for describe(FQN::class) dataset tests#408
recca0120 merged 9 commits into
mainfrom
fix/pest-dataset-class-constant

Conversation

@recca0120

Copy link
Copy Markdown
Owner

Summary

  • Root cause: Pest v4 changed locationHint format from pest_qn://testfile.php to php_qn://TestCaseFactory.php(eval'd code)::P\Tests\...\Class::__pest_evaluable__..., pointing to framework internals rather than the actual test file
  • Fix: Route php_qn:// events with P\ class prefix to Pest identifier, derive file path from classFQN, and decode __pest_evaluable__ encoding with FQN heuristic for describe(FQN::class) blocks
  • Encoding: _ = space/backtick/backslash, __ = literal underscore, _→_ separates describe segments; PascalCase heuristic detects FQN vs string describe names

Changes

  • TestIdentifierFactory: detect Pest v4 php_qn:// events via P\ class prefix pattern
  • PestTestIdentifier: handle php_qn:// by extracting classFQN and deriving file path
  • PestV2Fixer: add decodeEvaluableV4() to decode nested describe paths with FQN heuristic
  • Added ClassConstantDatasetTest.php fixture and PeName enum for integration testing

Test plan

  • Unit tests pass: pnpm -C packages/phpunit test -- --run (964/964)
  • describe(PeName::class, ...) with ->with([PeName::Standard, ...]) shows correct test IDs
  • Dataset child tests under FQN describe block update Test Explorer icons correctly
  • Existing pest_qn:// and file:// formats unaffected

…ncated suite names

- PestV2Fixer: extend decodeEvaluable to handle → separator in describe block evaluable names (e.g. __pest_evaluable__something__→_it_should_detect_OK_but_does_not)
- TestResultObserver: add prefix fallback for Pest v3 testSuiteStarted/Finished whose names are truncated due to mb_strrpos+substr byte/char mismatch; restricted to suite events only to avoid false positives
@recca0120 recca0120 force-pushed the fix/pest-dataset-class-constant branch from d2f7581 to 3d7ab62 Compare March 13, 2026 04:10
…V3Fixer + ObserverFactory

- Add PestV3Fixer.truncatedId() to compute v3-truncated ID aliases (2 bytes per → char)
- ObserverFactory registers truncated aliases in testItemById at build time
- TestResultObserver.find() simplified to exact lookup only — no version-specific logic
…ted ID aliases

- TestItemByIdMap<T> extends Map, overrides set() to auto-register truncated aliases
- ObserverFactory uses TestItemByIdMap instead of manual loop + PestV3Fixer call
- TestResultObserver.test.ts uses TestItemByIdMap via buildTestItemById helper
- Rename TestItemByIdMap<T> → AliasMap<T>: name is framework-agnostic,
  shared by both PHPUnit and Pest, focuses on alias registration behavior
- Remove PestV3Fixer from public API (index.ts); only AliasMap is exported
- Remove unreachable ternary in PestV2Fixer.fixId (decodeEvaluable always
  returns a non-empty string)
- Remove PestV3Fixer object: truncatedId() was only used internally by
  AliasMap.set() in the same file; replace with a module-level private function
- Remove PestV3Fixer re-export from PestFixer barrel (no external consumer)
- Simplify decodeDescribePart: replace 17-line while-loop tokenizer with
  placeholder approach (__ → \0, split _, restore \0)
- Merge double ternary on datasetIdx into a single destructure
- Extract decodeWords(): shared decode primitive used by both
  decodeDescribePart and the test-part decoding, removing duplication
- Remove early return for segments.length < 2: the describe-less path
  is now handled by the unified single path (describeParts = [])
- Remove `before` variable: always '' since hasPrefix() guarantees
  methodPart starts with PREFIX (prefixIdx === 0)
- Inline truncatedId() into AliasMap.set(): single-use private function
  with simple logic, inlining removes unnecessary indirection
- Simplify part.replace(/^_/, '').replace(/_$/, '') to part.replace(/^_|_$/g, '')
@recca0120 recca0120 merged commit 8e8a750 into main Mar 13, 2026
12 checks passed
@recca0120 recca0120 deleted the fix/pest-dataset-class-constant branch June 23, 2026 01:04
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.

1 participant