|
|
@@ -15,10 +15,15 @@
|
|
|
namespace Cake\Test\TestCase;
|
|
|
|
|
|
use Cake\Event\Event;
|
|
|
+use Cake\Event\EventList;
|
|
|
+use Cake\Event\EventManager;
|
|
|
use Cake\Http\CallbackStream;
|
|
|
use Cake\Http\Server;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
+use Psr\Http\Message\ResponseInterface;
|
|
|
+use RuntimeException;
|
|
|
use TestApp\Http\BadResponseApplication;
|
|
|
+use TestApp\Http\EventApplication;
|
|
|
use TestApp\Http\InvalidMiddlewareApplication;
|
|
|
use TestApp\Http\MiddlewareApplication;
|
|
|
use Zend\Diactoros\Response;
|
|
|
@@ -67,8 +72,14 @@ class ServerTest extends TestCase
|
|
|
$app = $this->getMockBuilder('Cake\Http\BaseApplication')
|
|
|
->setConstructorArgs([$this->config])
|
|
|
->getMock();
|
|
|
+
|
|
|
+ $manager = new EventManager();
|
|
|
+ $app->method('getEventManager')
|
|
|
+ ->willReturn($manager);
|
|
|
+
|
|
|
$server = new Server($app);
|
|
|
$this->assertSame($app, $server->getApp($app));
|
|
|
+ $this->assertSame($app->getEventManager(), $server->getEventManager());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -120,10 +131,11 @@ class ServerTest extends TestCase
|
|
|
/**
|
|
|
* Test an application failing to build middleware properly
|
|
|
*
|
|
|
+ * @return void
|
|
|
*/
|
|
|
public function testRunWithApplicationNotMakingMiddleware()
|
|
|
{
|
|
|
- $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectException(RuntimeException::class);
|
|
|
$this->expectExceptionMessage('The application `middleware` method');
|
|
|
$app = new InvalidMiddlewareApplication($this->config);
|
|
|
$server = new Server($app);
|
|
|
@@ -147,10 +159,11 @@ class ServerTest extends TestCase
|
|
|
/**
|
|
|
* Test middleware not creating a response.
|
|
|
*
|
|
|
+ * @return void
|
|
|
*/
|
|
|
public function testRunMiddlewareNoResponse()
|
|
|
{
|
|
|
- $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectException(RuntimeException::class);
|
|
|
$this->expectExceptionMessage('Application did not create a response. Got "Not a response" instead.');
|
|
|
$app = new BadResponseApplication($this->config);
|
|
|
$server = new Server($app);
|
|
|
@@ -158,6 +171,25 @@ class ServerTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test application events.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testRunEvents()
|
|
|
+ {
|
|
|
+ $manager = new EventManager();
|
|
|
+ $manager->setEventList(new EventList());
|
|
|
+ $app = new EventApplication($this->config, $manager);
|
|
|
+
|
|
|
+ $server = new Server($app);
|
|
|
+ $res = $server->run();
|
|
|
+
|
|
|
+ $this->assertCount(1, $manager->listeners('My.event'));
|
|
|
+ $this->assertEventFired('Server.buildMiddleware', $manager);
|
|
|
+ $this->assertInstanceOf(ResponseInterface::class, $res);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Test that emit invokes the appropriate methods on the emitter.
|
|
|
*
|
|
|
* @return void
|