Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions Tests/Routing/DynamicRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DynamicRouterTest extends CmfUnitTestCase
protected $context;
public $request;

protected $url = '/foo/bar';
const URL = '/foo/bar';

public function setUp()
{
Expand All @@ -40,7 +40,7 @@ public function setUp()
$this->enhancer = $this->buildMock('Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface', array('enhance'));

$this->context = $this->buildMock('Symfony\Component\Routing\RequestContext');
$this->request = Request::create($this->url);
$this->request = Request::create(self::URL);

$this->router = new DynamicRouter($this->context, $this->matcher, $this->generator);
$this->router->addRouteEnhancer($this->enhancer);
Expand Down Expand Up @@ -142,18 +142,21 @@ public function testMatchUrl()
$routeDefaults = array('foo' => 'bar');
$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->with(self::URL)
->will($this->returnValue($routeDefaults))
;

$expected = array('this' => 'that');
$test = $this;
$this->enhancer->expects($this->once())
->method('enhance')
->with($this->equalTo($routeDefaults), $this->equalTo($this->request))
->with($this->equalTo($routeDefaults), $this->callback(function (Request $request) use ($test) {
Copy link
Member

Choose a reason for hiding this comment

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

There is some php closure fuckup in v5.3 here. Can't we pass the url directly?

Copy link
Member Author

@wouterj wouterj May 10, 2016

Choose a reason for hiding this comment

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

fixed it

Copy link
Member

Choose a reason for hiding this comment

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

uhh even better :-)

return DynamicRouterTest::URL === $request->server->get('REQUEST_URI');
}))
->will($this->returnValue($expected))
;

$results = $this->router->match($this->url);
$results = $this->router->match(self::URL);

$this->assertEquals($expected, $results);
}
Expand All @@ -164,15 +167,17 @@ public function testMatchRequestWithUrlMatcher()

$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->with(self::URL)
->will($this->returnValue($routeDefaults))
;

$expected = array('this' => 'that');
$test = $this;
$this->enhancer->expects($this->once())
->method('enhance')
// somehow request object gets confused, check on instance only
->with($this->equalTo($routeDefaults), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->with($this->equalTo($routeDefaults), $this->callback(function (Request $request) use ($test) {
return DynamicRouterTest::URL === $request->server->get('REQUEST_URI');
}))
->will($this->returnValue($expected))
;

Expand All @@ -195,9 +200,12 @@ public function testMatchRequest()
;

$expected = array('this' => 'that');
$test = $this;
$this->enhancer->expects($this->once())
->method('enhance')
->with($this->equalTo($routeDefaults), $this->equalTo($this->request))
->with($this->equalTo($routeDefaults), $this->callback(function (Request $request) use ($test) {
return DynamicRouterTest::URL === $request->server->get('REQUEST_URI');
}))
->will($this->returnValue($expected))
;

Expand All @@ -223,7 +231,7 @@ public function testMatchFilter()
->method('enhance')
;

$router->match($this->url);
$router->match(self::URL);
}

/**
Expand Down Expand Up @@ -256,7 +264,7 @@ public function testMatchUrlWithRequestMatcher()
$matcher = $this->buildMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface', array('matchRequest', 'setContext', 'getContext'));
$router = new DynamicRouter($this->context, $matcher, $this->generator);

$router->match($this->url);
$router->match(self::URL);
}

/**
Expand Down Expand Up @@ -301,11 +309,11 @@ public function testEventHandler()
$routeDefaults = array('foo' => 'bar');
$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->with(self::URL)
->will($this->returnValue($routeDefaults))
;

$this->assertEquals($routeDefaults, $router->match($this->url));
$this->assertEquals($routeDefaults, $router->match(self::URL));
}

public function testEventHandlerRequest()
Expand All @@ -327,7 +335,7 @@ public function testEventHandlerRequest()
$routeDefaults = array('foo' => 'bar');
$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->with(self::URL)
->will($this->returnValue($routeDefaults))
;

Expand Down