Skip to content

Add tests for PHP runnable queries#129

Open
roxblnfk wants to merge 1 commit into
zed-extensions:mainfrom
roxblnfk:runnable-query-tests
Open

Add tests for PHP runnable queries#129
roxblnfk wants to merge 1 commit into
zed-extensions:mainfrom
roxblnfk:runnable-query-tests

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Jul 2, 2026

Copy link
Copy Markdown

What

Adds a cargo test suite that exercises languages/php/runnables.scm and languages/php/tasks.json, so the runnable/gutter queries have coverage and regressions get caught before release. There are no tests for the runnable queries today, so it's easy to break gutter detection (or the tag ↔ task wiring) without noticing until it ships.

How

Mirrors the approach already used by zed-extensions/java: runs the shipped .scm with the native tree-sitter engine over the pinned grammar, as dev-dependencies. The grammar commit in extension.toml (5b5627f) is the tree-sitter-php 0.24.2 release, so the crate parses identically to the editor.

One deliberate detail: the helper calls cursor.set_match_limit(64) to mirror QueryCursorHandle::new() in crates/language/src/syntax_map.rs, so tests see the same match-limit behaviour Zed applies at runtime.

  • tests/support/mod.rsrun_query helper (parse → query → collect @run captures with their tag and row).
  • tests/runnables.rs — PHPUnit (naming convention, @test, #[Test], abstract) and Pest.
  • tests/tasks.rs — every (#set! tag …) in the query has a matching task in tasks.json, and tags map to the expected runner.

No workflow is added: the org-wide extension_tests workflow already runs cargo nextest on pull requests, so these tests are picked up automatically.

Documented gaps (#[ignore]d)

Two #[ignore]d tests pin behaviour the current query gets wrong — it tags things as PHPUnit that most likely aren't:

  • a *Test class with no extends (PHPUnit test cases always inherit from TestCase; a class with no base class is far more likely a non-PHPUnit test);
  • a bare #[Test] method in such a class (#[Test] is ambiguous between PHPUnit\Framework\Attributes\Test and other frameworks).

They assert the intended behaviour, so they fail today and are skipped in CI. Run them with cargo test -- --ignored to see the gaps.

While writing these I also noticed the (#not-any-eq? @_modifier "abstract") guard on the PHPUnit patterns never fires with the pinned grammar — abstract *Test classes are still tagged. That's pinned as-is by abstract_test_class_is_tagged (the gutter is harmless — PHPUnit just won't run an abstract class), but worth flagging.

Running

cargo test                 # 8 pass, 2 ignored
cargo test -- --ignored    # runs the two documented-gap tests (they fail today)

Exercise languages/php/runnables.scm and tasks.json the same way
zed-extensions/java does: run the shipped queries with the native
tree-sitter engine over the pinned grammar (5b5627f == tree-sitter-php
0.24.2), under Zed's 64-match limit.

The org-wide extension_tests workflow already runs `cargo nextest` on
pull requests, so these are picked up automatically — no extra CI needed.

- tests/support: run_query helper, mirroring the match limit that
  QueryCursorHandle::new() applies in crates/language/src/syntax_map.rs
- tests/runnables.rs: PHPUnit (naming convention, @test, #[Test], abstract)
  and Pest
- tests/tasks.rs: every runnable tag has a task; tags map to the right runner

Two #[ignore]d tests document cases main over-tags as PHPUnit (a *Test class
with no inheritance, and a bare #[Test] in such a class). They assert the
intended behaviour, so they fail today and are skipped in CI; run them with
`cargo test -- --ignored`.
@roxblnfk roxblnfk force-pushed the runnable-query-tests branch from 85f0ad4 to 1b7fca3 Compare July 2, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant