示例#1
0
 public function testDispatch()
 {
     $getMock = Mockery::mock(ServerRequestInterface::class);
     $getMock->shouldReceive('getMethod')->andReturn('GET');
     $getMock->shouldReceive('getUri->getPath')->andReturn('/');
     $getMock->shouldReceive('setArguments')->with([]);
     $postMock = Mockery::mock(ServerRequestInterface::class);
     $postMock->shouldReceive('getMethod')->andReturn('POST');
     $postMock->shouldReceive('getUri->getPath')->andReturn('/');
     $postMock->shouldReceive('setArguments')->with([]);
     $getCalled = 0;
     $postCalled = 0;
     $this->app->get('/', function (ServerRequestInterface $req, \Closure $next) {
         return $next($req) . ' getMiddleware';
     }, function (ServerRequestInterface $req) use(&$getCalled) {
         $getCalled++;
         return 'get';
     });
     $this->app->post('/', function (ServerRequestInterface $req, \Closure $next) {
         return $next($req) . ' postMiddleware';
     }, function (ServerRequestInterface $req) use(&$postCalled) {
         $postCalled++;
         return 'post';
     });
     $this->assertEquals('get getMiddleware', $this->app->dispatch($getMock));
     $this->assertEquals(1, $getCalled);
     $this->assertEquals(0, $postCalled);
     $this->assertEquals('post postMiddleware', $this->app->dispatch($postMock));
     $this->assertEquals(1, $getCalled);
     $this->assertEquals(1, $postCalled);
 }
 }, ["admin", "middleware"]);
 $app->get('/abc/def', ["admin", "middleware"], ['admin', 'action']);
 $app->get('/abc/ghi', ["admin", "middleware"], ['admin', 'action'], function () {
 });
 $app->get('/def/{id}/2', function () {
 }, function () {
 });
 $app->get('/def/{id}/{name}', ["admin", "middleware"], function () {
 });
 $app->get('/defg/{id}/{what}', function () {
 }, ["admin", "middleware"]);
 $app->get('/def/def/{shit}', ["admin", "action"], ['admin', 'middleware']);
 $app->get('/def/3/{zzz}', ["admin", "middleware"], ['admin', 'action'], function () {
 });
 $app->post('/abc', function () {
 }, function () {
 });
 $app->post('/abc/{id}/{name}', ["admin", "middleware"], function () {
 });
 $app->post('/abd/{id}/{what}', function () {
 }, ["admin", "middleware"]);
 $app->post('/abc/def', ["admin", "middleware"], ['admin', 'action']);
 $app->post('/abc/ghi', ["admin", "middleware"], ['admin', 'action'], function () {
 });
 $app->post('/def/{id}/2', function () {
 }, function () {
 });
 $app->post('/def/{id}/{name}', ["admin", "middleware"], function () {
 });
 $app->post('/defg/{id}/{what}', function () {
 }, ["admin", "middleware"]);