|
|
@@ -14,6 +14,7 @@
|
|
|
*/
|
|
|
namespace Cake\Test\TestCase;
|
|
|
|
|
|
+use Cake\Http\CallbackStream;
|
|
|
use Cake\Http\Server;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
use TestApp\Http\BadResponseApplication;
|
|
|
@@ -22,6 +23,9 @@ use TestApp\Http\MiddlewareApplication;
|
|
|
use Zend\Diactoros\Response;
|
|
|
use Zend\Diactoros\ServerRequestFactory;
|
|
|
|
|
|
+require __DIR__ . '/server_mocks.php';
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Server test case
|
|
|
*/
|
|
|
@@ -37,6 +41,7 @@ class ServerTest extends TestCase
|
|
|
parent::setUp();
|
|
|
$this->server = $_SERVER;
|
|
|
$this->config = dirname(dirname(__DIR__));
|
|
|
+ $GLOBALS['mockedHeaders'] = [];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -173,6 +178,26 @@ class ServerTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test that emit invokes the appropriate methods on the emitter.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testEmitCallbackStream()
|
|
|
+ {
|
|
|
+ $response = new Response('php://memory', 200, ['x-testing' => 'source header']);
|
|
|
+ $response = $response->withBody(new CallbackStream(function () {
|
|
|
+ echo 'body content';
|
|
|
+ }));
|
|
|
+
|
|
|
+ $app = new MiddlewareApplication($this->config);
|
|
|
+ $server = new Server($app);
|
|
|
+ ob_start();
|
|
|
+ $server->emit($response);
|
|
|
+ $result = ob_get_clean();
|
|
|
+ $this->assertEquals('body content', $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Ensure that the Server.buildMiddleware event is fired.
|
|
|
*
|
|
|
* @return void
|