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'); }
public function run(ServerRequestInterface $request = null, ResponseInterface $response = null) { return Runtime::run($this->queue, $request, $response); }