mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-13 07:29:33 +00:00
fix(php): allow relative prefixes in route groups and correctly fail tests on extractor error
(cherry picked from commit 29ed19f1e4)
This commit is contained in:
1 parent
4c74bd68fe
commit
95dd8cf9a0
2 files changed
+21
-9
No files matched your search
@@ -3504,9 +3504,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")
|
||||
@@ -3518,8 +3518,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")
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user