-
Notifications
You must be signed in to change notification settings - Fork 34
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
Unit testing applications using SlmLocale #26
Comments
Do you use the latest master? I have, because of several issues, made a refactoring branch which I need to finish with unit tests. There are several changes internally in the new branch, but for you the most important one: the redirect is made via short circuiting the Instead of sending a response in every strategy, the strategy modifies the response and returns it. The response will be returned during I can understand there are many difficulties with testing the current master with SlmLocale. Can you switch to the |
I was using the latest master. Just tried with feature/refactoring and with each of the following, I was getting response of 302 when I tested for 200: /en/account/login When I dump the URI inside UriPathStrategy I'm getting the path: / which then gets transformed to /en/ and redirects to that. |
@intellix to be honest, I haven't made such tests yet and have thus no experience in using SlmLocale with controller tests. The only thing to be certain SlmLocale is causing this: disabling the module fixes the problem? Hopefully I have some time to set these things up and test SlmLocale, but it's unfortunately not happening in the next days. |
If you are attempting to test your code and are NOT testing the Locale capabilities of SlmLocale, you can remove the module SlmLocale from the configuration. I did this by using the following code in as my setUp() function.
With the above in place you can set up your testing the normal ZF2, PHPUnit way. You specify your URI paths without the SlmLocale locale code (e.g. use "/account/login" instead of "/en/account/login") in the path. Of course if you are testing SlmLocale, then the above is not a suitable work around. |
Hi, maintenance of this package has been taken over by me. If you still feel this issue is valid please go ahead and create a PR or contribute in any other manner. It's appreciated. |
Having the same issue. Will issue pull request soon. |
I'm attempting to create unit tests for my application which makes use of SlmLocale UriPathStrategy and am having issues with testing controller dispatches like so:
This returns 302 and when I dump the RequestURI within UriPathStrategy, I'm getting the following twice:
Whereas when I dump the RequestURI from a typical request via my browser:
From what I've been reading in the code, it looks like the only time detection is done (and redirection) is onBootstrap of the Module. So the unit test defaults to / without a locale and every other dispatch uses the same requestUri and it needs to redirect to /en/ with them all.
Are you doing anything in particular when testing your stuff or does there need to be some change so the detection is done onDispatch() instead?
Thanks, Dom
The text was updated successfully, but these errors were encountered: