Skip to content

Unit tests for SignatureHelpHandler and DefinitionHandler - #657

Closed
Firehed wants to merge 7 commits into
mainfrom
signature-help-handler-unit-test
Closed

Firehed wants to merge 7 commits into
mainfrom
signature-help-handler-unit-test

Conversation

@Firehed

@Firehed Firehed commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Replaces the fixture-driven "unit" test files for two handlers with true unit tests that stub the two interfaces each handler declares. The suites that build a full production KnowledgeStack in setUp are renamed and moved to tests/Integration/, so nothing is lost — they're just called what they are.

Handlers already take interfaces (DocumentSourceInterface, CodeResolverInterface), so this is test-side only: no changes under src/.

What changed

  • SignatureHelpHandlerTest and DefinitionHandlerTest under tests/Handler/ are now true unit tests. They stub their two interface collaborators and assert on the handler's own behavior: method claim, short-circuits on malformed params and unopened documents, and the exact wire shape emitted for a resolved result.
  • The prior test files, whose setUp built the full symbol-knowledge stack over fixtures and asserted on end-to-end resolution, are renamed to SignatureHelpHandlerIntegrationTest / DefinitionHandlerIntegrationTest and moved to tests/Integration/. Their #[CoversClass] lists (ExpressionResolver, ResolvedTypeOnly) already said what they are.
  • New BuildsHandlerRequestsTrait shared by both unit tests; each passes its own method name and URI to method-agnostic request builders.
  • phpunit.xml.dist now defines two disjoint testsuites, unit and integration. phpunit without a --testsuite runs both, so CI and composer test are unchanged.

Why

Every handler already depends on interfaces, so its unit test can be a real unit test with no production change. The existing suites carry the pattern that predates those interfaces and each rebuilds KnowledgeStack::forProject's output in setUp — the duplicate wiring route the design rules call out. Shrinking the surface that reaches for BuildsKnowledgeStackTrait is the prerequisite for later moving Server::forProject / KnowledgeStack::forProject into container factories.

What follows

  • Same treatment for HoverHandlerTest and CompletionHandlerTest.
  • Container factories for the knowledge, resolution, and handler layers so the integration tests can build through the container and both forProject methods can be deleted.

🤖 Generated with Claude Code

Firehed and others added 2 commits September 30, 2026 13:01
The suite wires a full production symbol-knowledge stack through
BuildsKnowledgeStackTrait and asserts on fixtures resolved end-to-end
through SymbolResolver, ExpressionResolver and NativeTypeSource. That
is an integration test wearing a unit-test filename. Rename it to say
what it does; a real unit test for the handler follows in the next
commit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The handler already takes DocumentSourceInterface and CodeResolverInterface,
so a real unit test can be written by stubbing them directly. Covers the
handler's own behavior: method claim, short-circuits on malformed params
and unopened documents, null passthrough when the cursor is outside a
call, and the presenter+parameter shape it emits when a CallContext is
returned. The resolver's ability to identify the call at a given cursor
is exercised by the sibling integration test.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.69%. Comparing base (b5f69e1) to head (66e411c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #657      +/-   ##
============================================
+ Coverage     99.65%   99.69%   +0.04%     
  Complexity     1903     1903              
============================================
  Files           136      136              
  Lines          4882     4882              
============================================
+ Hits           4865     4867       +2     
+ Misses           17       15       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Firehed and others added 5 commits September 30, 2026 14:33
Integration tests already have their own directory. Adjust the namespace
and pull OpensDocumentsTrait in through its full name now that it is no
longer a sibling.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Two disjoint suites: unit (everything outside tests/Integration) and
integration (tests/Integration only). Running phpunit without a
--testsuite still covers both, so composer test is unchanged. A
follow-up composer script can select the unit suite for a fast
inner-loop run.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Every textDocument/position handler unit test needs the same two
request builders. Extract them once so the next handler test does not
re-derive the shape. The trait is method-agnostic; each test passes its
own method name and URI, so a bad params shape or an unopened document
is expressible in one line without a per-file adapter.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The suite builds a full production KnowledgeStack over inline documents
and asserts on definition locations resolved end-to-end. Its CoversClass
list already names ExpressionResolver and ResolvedTypeOnly. Move it to
tests/Integration and rename to match.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Same shape as the SignatureHelpHandler unit test: stub the two
interface collaborators and cover the handler's own behavior. The
resolver's ability to identify what a cursor points at is the sibling
integration tests job.

The two new branches over signature help are the two paths through
getDefinitionLocation(): a resolved symbol without one yields null,
and one with a Location returns its toLspLocation() shape.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Firehed Firehed changed the title Real unit test for SignatureHelpHandler with mocked collaborators Unit tests for SignatureHelpHandler and DefinitionHandler Sep 30, 2026
@Firehed

Firehed commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #660 (phase 1: renames) and its stacked phase 2 (unit tests) — this PR mixed both concerns in one branch.

@Firehed Firehed closed this Sep 30, 2026
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