Skip to content

Chore: Test covering edge case of same-name param and resource#237

Merged
Meldiron merged 1 commit into0.34.xfrom
chore-test-param-resource-same-name
Apr 17, 2026
Merged

Chore: Test covering edge case of same-name param and resource#237
Meldiron merged 1 commit into0.34.xfrom
chore-test-param-resource-same-name

Conversation

@Meldiron
Copy link
Copy Markdown
Contributor

No description provided.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 17, 2026

Greptile Summary

This PR adds a new test testCanInjectResourceAndParamWithSameName to verify that the framework correctly handles the edge case where a route has both a param and an inject registered under the same name (locale). A dummy Locale helper class is appended to the test file to support the test. No production code is changed.

Confidence Score: 5/5

Safe to merge — only test code added, no production changes.

All findings are P2 style suggestions (class naming and static state cleanup). The new test is logically correct: params and injects are stored in separate arrays and resolved into a positionally-indexed arguments array, so the same-name collision is properly avoided. No production code was changed.

No files require special attention.

Important Files Changed

Filename Overview
tests/HttpTest.php Adds testCanInjectResourceAndParamWithSameName and a helper Locale class; test logic is correct, arguments resolved positionally so same-name param/inject collision is properly avoided.

Reviews (1): Last reviewed commit: "Add test covering edge case of same-name..." | Re-trigger Greptile

Comment thread tests/HttpTest.php
Comment on lines +690 to 693
class Locale
{
public string $name = 'en';
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Generic helper class name may collide

Locale is a very common class name. Defining it in the Utopia\Http namespace at file scope means any future addition of a real Locale class to this namespace (or a test file included alongside this one) would cause a fatal "Cannot redeclare class" error. Naming it something test-specific (e.g. TestLocale or LocaleStub) eliminates the risk at no cost.

Suggested change
class Locale
{
public string $name = 'en';
}
class TestLocale
{
public string $name = 'en';
}

You would also need to update the container registration and the action's type hint accordingly:

$this->container->set('locale', fn () => new TestLocale());
// ...
->action(function (string $localeParam, TestLocale $localeResource) {

Comment thread tests/HttpTest.php
@Meldiron Meldiron merged commit 8754f5f into 0.34.x Apr 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants