-
Notifications
You must be signed in to change notification settings - Fork 35
Chore: Test covering edge case of same-name param and resource #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -648,4 +648,46 @@ public function testCallableStringParametersNotExecuted(): void | |||||||||||||||||
|
|
||||||||||||||||||
| $this->assertEquals('generated: generated-value', $result); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| public function testCanInjectResourceAndParamWithSameName(): void | ||||||||||||||||||
| { | ||||||||||||||||||
| // Register a 'locale' resource returning a Locale instance whose | ||||||||||||||||||
| // `name` statically resolves to "en". | ||||||||||||||||||
| $this->container->set('locale', fn () => new Locale()); | ||||||||||||||||||
|
|
||||||||||||||||||
| $route = new Route('GET', '/path'); | ||||||||||||||||||
|
|
||||||||||||||||||
| $route | ||||||||||||||||||
| ->param('locale', 'en-default', new Text(10), 'locale param', false) | ||||||||||||||||||
| ->inject('locale') | ||||||||||||||||||
| ->action(function (string $localeParam, Locale $localeResource) { | ||||||||||||||||||
| echo \json_encode([ | ||||||||||||||||||
| 'localeParam' => $localeParam, | ||||||||||||||||||
| 'localeResource' => $localeResource->name, | ||||||||||||||||||
| ]); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| \ob_start(); | ||||||||||||||||||
| $request = new UtopiaFPMRequestTest(); | ||||||||||||||||||
| $request::_setParams(['locale' => 'es']); | ||||||||||||||||||
| $this->http->execute($route, $request, new Response()); | ||||||||||||||||||
| $result = \ob_get_contents(); | ||||||||||||||||||
| \ob_end_clean(); | ||||||||||||||||||
|
|
||||||||||||||||||
| $expected = \json_encode([ | ||||||||||||||||||
| 'localeParam' => 'es', | ||||||||||||||||||
| 'localeResource' => 'en', | ||||||||||||||||||
| ]); | ||||||||||||||||||
|
|
||||||||||||||||||
| $this->assertEquals($expected, $result); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Dummy Locale class used by testCanInjectResourceAndParamWithSameName to | ||||||||||||||||||
| * verify resource injection alongside a same-named request parameter. | ||||||||||||||||||
| */ | ||||||||||||||||||
| class Locale | ||||||||||||||||||
| { | ||||||||||||||||||
| public string $name = 'en'; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+690
to
693
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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) { |
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.