Skip to content
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

[Routing] Use correct exception message in ChainRouter::match() #110

Merged
merged 4 commits into from Aug 26, 2014

Conversation

timplunkett
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Allow ChainRouter::match() to use the correct exception message when a RequestMatcherInterface router is used.

Currently, even if doMatch() is called via match(), as long as the router cares for a request, it will create one and the exception handling will not use the path-specific message, it will use the request-based message.

$this->router->add($high, 20);

$result = $this->router->match($url);
$this->assertEquals(array('test'), $result);
Copy link
Contributor

Choose a reason for hiding this comment

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

OT: Did symfony-CMF considered to require 5.4 and some point?

Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to still call assertEquals? This line won't be reached

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a copy/paste oversight. Though I tend to leave those in, in case someone removes the @ExpectedException bit after refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lsmith77 @dbu Oppinion on that? I don't care much but I think if you refactory you will have a 100% different test method anyway.

Copy link

Choose a reason for hiding this comment

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

The additional assertion conflicts with the test's expectation, which is to assert an @expectedException. The test's actual expectation is no longer clear (was the intention to expect an exception or the positive assertion?), so it should be removed.

@@ -170,10 +170,13 @@ private function doMatch($url, Request $request = null)
// matching requests is more powerful than matching URLs only, so try that first
if ($router instanceof RequestMatcherInterface) {
if (null === $request) {
$request = Request::create($url);
$request_for_matching = Request::create($url);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we then move this code to before the foreach loop, so that we only need to do it once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it depends. Are we more likely to have 0 routers that implement RequestMatcherInterface, or more likely to have >1 routers that implement RequestMatcherInterface?
Because right now, we optimize for 0. If we move that code outside the foreach and no routers need the created request when called from match(), that'd be an extra Request::create() call.

@@ -170,10 +170,12 @@ private function doMatch($url, Request $request = null)
// matching requests is more powerful than matching URLs only, so try that first
if ($router instanceof RequestMatcherInterface) {
if (null === $request) {
$request = Request::create($url);
Copy link
Member

Choose a reason for hiding this comment

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

how about then:
move $requestForMatching = $request; to before the loop and then inside the loop do

if (empty(requestForMatching)) {
    $requestForMatching = Request::create($url);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, done.

lsmith77 added a commit that referenced this pull request Aug 26, 2014
[Routing] Use correct exception message in ChainRouter::match()
@lsmith77 lsmith77 merged commit 286f7aa into symfony-cmf:master Aug 26, 2014
@lsmith77
Copy link
Member

thx! fix will be in the 1.3.0-RC2 release expected sometime this week

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.

None yet

4 participants