Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
php: Add runnable tests (#11514)
Remco Smitsbfdd9d89a7d8
diff --git a/extensions/php/languages/php/highlights.scm b/extensions/php/languages/php/highlights.scmindex 5f366b53c3b..4f1e35ebf26 100644--- a/extensions/php/languages/php/highlights.scm+++ b/extensions/php/languages/php/highlights.scm@@ -122,3 +122,4 @@"try" @keyword"use" @keyword"while" @keyword+"yield" @keyworddiff --git a/extensions/php/languages/php/outline.scm b/extensions/php/languages/php/outline.scmindex 87986f1032e..aff05692fb1 100644--- a/extensions/php/languages/php/outline.scm+++ b/extensions/php/languages/php/outline.scm@@ -27,3 +27,15 @@"trait" @contextname: (_) @name) @item++; Add support for Pest runnable+(function_call_expression+ function: (_) @context+ (#any-of? @context "it" "test" "describe")+ arguments: (arguments+ .+ (argument+ (encapsed_string (string_value) @name)+ )+ )+) @itemdiff --git a/extensions/php/languages/php/runnables.scm b/extensions/php/languages/php/runnables.scmnew file mode 100644index 00000000000..8e36d901ead--- /dev/null+++ b/extensions/php/languages/php/runnables.scm@@ -0,0 +1,88 @@+; Class that follow the naming convention of PHPUnit test classes+; and that doesn't have the abstract modifier+; and have a method that follow the naming convention of PHPUnit test methods+; and the method is public+(class_declaration+ modifier: (_)? @_modifier+ (#not-eq? @_modifier "abstract")+ name: (_) @_name+ (#match? @_name ".*Test$")+ body: (declaration_list+ (method_declaration+ (visibility_modifier)? @_visibility+ (#eq? @_visibility "public")+ name: (_) @run+ (#match? @run "^test.*")+ )+ )+) @phpunit-test++; Class that follow the naming convention of PHPUnit test classes+; and that doesn't have the abstract modifier+; and have a method that has the @test annotation+; and the method is public+(class_declaration+ modifier: (_)? @_modifier+ (#not-eq? @_modifier "abstract")+ name: (_) @_name+ (#match? @_name ".*Test$")+ body: (declaration_list+ ((comment) @_comment+ (#match? @_comment ".*@test\\b.*")+ .+ (method_declaration+ (visibility_modifier)? @_visibility+ (#eq? @_visibility "public")+ name: (_) @run+ (#not-match? @run "^test.*")+ ))+ )+) @phpunit-test+++; Class that follow the naming convention of PHPUnit test classes+; and that doesn't have the abstract modifier+; and have a method that has the #[Test] attribute+; and the method is public+(class_declaration+ modifier: (_)? @_modifier+ (#not-eq? @_modifier "abstract")+ name: (_) @_name+ (#match? @_name ".*Test$")+ body: (declaration_list+ (method_declaration+ (attribute_list+ (attribute_group+ (attribute (name) @_attribute)+ )+ )+ (#eq? @_attribute "Test")+ (visibility_modifier)? @_visibility+ (#eq? @_visibility "public")+ name: (_) @run+ (#not-match? @run "^test.*")+ )+ )+) @phpunit-test++; Class that follow the naming convention of PHPUnit test classes+; and that doesn't have the abstract modifier+(class_declaration+ modifier: (_)? @_modifier+ (#not-eq? @_modifier "abstract")+ name: (_) @run+ (#match? @run ".*Test$")+) @phpunit-test++; Add support for Pest runnable+; Function expression that has `it`, `test` or `describe` as the function name+(function_call_expression+ function: (_) @_name+ (#any-of? @_name "it" "test" "describe")+ arguments: (arguments+ .+ (argument+ (encapsed_string (string_value) @run)+ )+ )+) @pest-testdiff --git a/extensions/php/languages/php/tasks.json b/extensions/php/languages/php/tasks.jsonnew file mode 100644index 00000000000..65800eebe2e--- /dev/null+++ b/extensions/php/languages/php/tasks.json@@ -0,0 +1,19 @@+[+ {+ "label": "phpunit test $ZED_SYMBOL",+ "command": "./vendor/bin/phpunit",+ "args": ["--filter $ZED_SYMBOL $ZED_FILE"],+ "tags": ["phpunit-test"]+ },+ {+ "label": "pest test $ZED_SYMBOL",+ "command": "./vendor/bin/pest",+ "args": ["--filter \"$ZED_SYMBOL\" $ZED_FILE"],+ "tags": ["pest-test"]+ },+ {+ "label": "execute selection $ZED_SELECTED_TEXT",+ "command": "php",+ "args": ["-r", "$ZED_SELECTED_TEXT"]+ }+]