Skip to content

Instantly share code, notes, and snippets.

@ezimuel
Created Aug 10, 2015
Embed
What would you like to do?
Unit test for RouteMiddlewareTest issue #40 zend-expressive
<?php
/**
* Get the router adapters installed
*/
public function getRouterAdapters()
{
$adapters = [];
if (class_exists('Aura\Router\Router')) {
$adapters[] = [ 'Zend\Expressive\Router\Aura' ];
}
if (class_exists('FastRoute\RouteCollector')) {
$adapters[] = [ 'Zend\Expressive\Router\FastRoute' ];
}
if (class_exists('Zend\Mvc\Router\RouteMatch')) {
$adapters[] = [ 'Zend\Expressive\Router\Zf2' ];
}
return $adapters;
}
/**
* @see https://github.com/zendframework/zend-expressive/issues/40
* @dataProvider getRouterAdapters
*/
public function testRoutingWithMultipleMethodsSamePath($adapter)
{
$app = new Application(new $adapter);
$app->get('/foo', function ($req, $res, $next) {
$res->getBody()->write('Middleware1');
return $res;
});
$app->post('/foo', function ($req, $res, $next) {
$res->getBody()->write('Middleware2');
return $res;
});
$next = function ($request, $response) {
return $response;
};
$request = new ServerRequest([], [], '/foo', 'GET');
$response = new Response();
$result = $app->routeMiddleware($request, $response, $next);
$this->assertEquals('Middleware1', (string) $result->getBody());
$request = new ServerRequest([], [], '/foo', 'POST');
$response = new Response();
$result = $app->routeMiddleware($request, $response, $next);
$this->assertEquals('Middleware2', (string) $result->getBody());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment