Replies: 1 comment 8 replies
-
What about trying: ((method_declaration
(attribute_list) @attribute (#eq? @attribute "#[Test]")
)) Just had a quick play with the following code: <?php
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
public function test_that_true_is_true()
{
$this->assertTrue(true);
}
#[Test]
public function it_does_something(): void
{
$this->assertTrue(true);
}
} and it feels like it's on the right line. Writing Tree-sitter queries is a real trial and error! If I get some time in the week I'll try and look into it. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With PHP 8.0 attributes were introduced and can be used to annotate tests.
I have a larger code base that mixes the traditional (
/** @test */
) and the modern (#[Test]
) style of annotating test functions.I've dug a bit into the
neotest-phpunit
codebase1 but I'm hitting a wall either with the treesitter query, or the lack of its result being passed around.This is the query that I came up with:
( (method_declaration (attribute_list (attribute_group (attribute) @test_attribute (#match? @test_attribute "Test") ) ) ( (name) @test.name ) ) @test.definition )
This neatly matches the test, however, the problem stems from the attribute (
#[Test]
) being considered part of the function declaration, ultimately leading to an off-by-one when it comes to line-number for the test ids.I'd love to contribute, but I'm just hitting a wall and would need a pointer to get past it.
Footnotes
I'm also implementing Laravel Sail support right now (which would probably also cover docker). Hopefully I can create a PR for this soon 🙂 ↩
Beta Was this translation helpful? Give feedback.
All reactions