fix(php): allow relative prefixes in route groups and correctly fail tests on extractor error

This commit is contained in:
nikhil2004 committed 2026-09-23 15:00:01 +05:30
1 parent b8e2033e3c
commit 29ed19f1e4
2 files changed
+21 -9

No files matched your search

+5 -5
View File
@@ -3496,9 +3496,9 @@ def _php_get_route_name(closure_node, src: bytes) -> str | None:
else:
return None # Not a valid route closure
else:
# Outer calls (e.g. group(), prefix()) just contribute their prefix if it starts with '/'
if path_text is not None and path_text.startswith("/"):
prefixes.append(path_text)
# Outer calls (e.g. group(), prefix()) contribute their prefix, normalized to start with '/'
if path_text is not None and path_text:
prefixes.append(path_text if path_text.startswith("/") else "/" + path_text)
# Process any fluent method chain prefixes on the same statement
fluent = call.child_by_field_name("object")
@@ -3510,8 +3510,8 @@ def _php_get_route_name(closure_node, src: bytes) -> str | None:
for cc in c.children:
if cc.type in ("string", "encapsed_string"):
f_path = _read_text(cc, src).strip("'\"")
if f_path.startswith("/"):
prefixes.append(f_path)
if f_path:
prefixes.append(f_path if f_path.startswith("/") else "/" + f_path)
break
fluent = fluent.child_by_field_name("object")
+16 -4
View File
@@ -18,7 +18,10 @@ $app->post('/api/users', function() {
res = extract_php(php_file)
if res.get("error"):
pytest.skip(res["error"])
if "No language parser" in res["error"]:
pytest.skip("PHP grammar not installed")
else:
pytest.fail(res["error"])
labels = {n["label"] for n in res["nodes"]}
@@ -37,7 +40,10 @@ $fn2 = function() { return 'hello'; };
res = extract_php(php_file)
if res.get("error"):
pytest.skip(res["error"])
if "No language parser" in res["error"]:
pytest.skip("PHP grammar not installed")
else:
pytest.fail(res["error"])
labels = {n["label"] for n in res["nodes"]}
@@ -60,7 +66,10 @@ $app->group('/api/v1', function ($group) {
res = extract_php(php_file)
if res.get("error"):
pytest.skip(res["error"])
if "No language parser" in res["error"]:
pytest.skip("PHP grammar not installed")
else:
pytest.fail(res["error"])
labels = {n["label"] for n in res["nodes"]}
assert "GET /api/v1/users/{id}()" in labels, "Expected nested route closure to compose prefix"
@@ -77,7 +86,10 @@ $value = $cache->get('user:42', function () { return 2; });
res = extract_php(php_file)
if res.get("error"):
pytest.skip(res["error"])
if "No language parser" in res["error"]:
pytest.skip("PHP grammar not installed")
else:
pytest.fail(res["error"])
labels = {n["label"] for n in res["nodes"]}
assert "{closure#1}()" in labels, "Expected non-routing get() to fallback to ordinal"