public function testPrepending()
 {
     $queue = new Queue();
     $queue->append(function ($req, $res, $next) use($queue) {
         $queue->prepend(function ($req, $res, $next) {
             $res->getBody()->write('Second!');
             return $next($req, $res);
         });
         $res->getBody()->write('First!');
         return $next($req, $res);
     });
     $queue->append(function ($req, $res, $next) use($queue) {
         $queue->append(function ($req, $res, $next) {
             $res->getBody()->write('Sixth!');
             return $next($req, $res);
         });
         $res->getBody()->write('Third!');
         return $next($req, $res);
     });
     $queue->append(function ($req, $res, $next) use($queue) {
         $queue->prepend(function ($req, $res, $next) {
             $res->getBody()->write('Fifth!');
             return $next($req, $res);
         });
         $res->getBody()->write('Fourth!');
         return $next($req, $res);
     });
     $this->assertEquals('First!Second!Third!Fourth!Fifth!Sixth!', (string) Runtime::run($queue)->getBody(), 'first time');
     $this->assertEquals('First!Second!Third!Fourth!Fifth!Sixth!', (string) Runtime::run($queue)->getBody(), 'second time');
     $this->assertEquals('First!Second!Third!Fourth!Fifth!Sixth!', (string) Runtime::run($queue)->getBody(), 'third time');
 }
Exemple #2
0
 /**
  * @param callable $middleware
  *
  * @return $this
  */
 public function append($middleware)
 {
     $this->queue->append($this->prepareMiddleware($middleware));
     return $this;
 }