Skip to content

Refactor reflection-based white-box tests into public-contract tests #54

@ahmed-bhs

Description

@ahmed-bhs

Problem

Some unit tests are tightly coupled to private implementation details by invoking private methods through reflection.

Current hotspots

  • tests/Unit/Collector/DoctrineDoctorDataCollectorTest.php
    • invokes private methods: filterQueriesByPaths, isQueryFromExcludedPaths
  • tests/Unit/DependencyInjection/DoctrineDoctorExtensionTest.php
    • invokes private method: classNameToConfigKey

These tests are brittle: harmless internal refactors (renaming/moving private methods) can break tests even when public behavior is unchanged.

Why refactor

  • Preserve refactorability of internals
  • Keep tests focused on observable behavior
  • Reduce maintenance cost and false failures

Proposed approach

  1. Replace private-method reflection tests with public-contract tests wherever possible.
  2. For complex pure logic currently hidden in private methods, extract dedicated collaborators and test them directly (without reflection), for example:
    • query path filtering logic from DoctrineDoctorDataCollector
    • analyzer config key formatting logic from DoctrineDoctorExtension
  3. Keep DoctrineDoctorDataCollector / DoctrineDoctorExtension tests at integration-of-collaborators level (public API only).

Acceptance criteria

  • No test uses reflection to invoke private methods in these areas.
  • Equivalent behavior coverage is preserved or improved.
  • Existing public behavior remains unchanged.
  • Test suite remains green (phpunit, phpstan, ecs).

Notes

This issue is intentionally scoped to tests coupled to private methods. Other test quality improvements can be tracked separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions