/** * Run react. * * @param int $port * @param string $host */ public function run($port, $host) { $request_handler = function (Request $request, Response $response) { echo $request->getMethod() . ' ' . $request->getPath() . PHP_EOL; $sf_request = $this->request_bridge->convertRequest($request); $sf_response = $this->app->handle($sf_request); $this->app->terminate($sf_request, $sf_response); $this->response_bridge->send($response, $sf_response); }; $this->http->on('request', $request_handler); $this->socket->listen($port, $host); $this->loop->run(); }
/** * test model service is available */ public function testModelManagerServiceIsAvailable() { $app = new Application(); $app->register(new ModelProvider(), array('model.finder.namespace' => 'Fake\\NameSpace', 'model.finder.path' => '/tmp/fake')); $mockStorage = $this->getMock('Skip\\Model\\ModelStorageHandlerInterface'); $app['model.storage.handlers'] = array('mock.storage' => $mockStorage); $modelManager = $app['model']; $this->assertInstanceOf('Skip\\Model\\Manager', $modelManager); $request = Request::createFromGlobals(); $response = $app->handle($request); $app->terminate($request, $response); }
/** @test */ public function eventHelpersShouldDirectlyAddListenersAfterBoot() { $app = new Application(); $fired = false; $app->get("/", function () use($app, &$fired) { $app->finish(function () use(&$fired) { $fired = true; }); }); $request = Request::create('/'); $response = $app->handle($request); $app->terminate($request, $response); $this->assertTrue($fired, 'Event was not fired'); }
public function testSwiftMailerAvoidsFlushesIfMailerIsUnused() { $app = new Application(); $app->register(new SwiftmailerServiceProvider()); $app->boot(); $app['swiftmailer.spool'] = $app->share(function () { return new SpoolStub(); }); $app->get('/', function () use($app) { }); $request = Request::create('/'); $response = $app->handle($request); $this->assertCount(0, $app['swiftmailer.spool']->getMessages()); $app->terminate($request, $response); $this->assertFalse($app['swiftmailer.spool']->hasFlushed); }
public function testSwiftMailerSendsMailsOnFinish() { $app = new Application(); $app->register(new SwiftmailerServiceProvider(), array('swiftmailer.class_path' => __DIR__ . '/../../../../vendor/swiftmailer/swiftmailer/lib/classes')); $spool = new SpoolStub(); $app['swiftmailer.spooltransport'] = new \Swift_SpoolTransport($spool); $app->get('/', function () use($app) { $app['mailer']->send(\Swift_Message::newInstance()); }); $this->assertCount(0, $spool->getMessages()); $request = Request::create('/'); $response = $app->handle($request); $this->assertCount(1, $spool->getMessages()); $app->terminate($request, $response); $this->assertCount(0, $spool->getMessages()); }
public function testCallbacksAsServices() { $app = new Application(); $app['service'] = $app->share(function () { return new self(); }); $app->before('service:beforeApp'); $app->after('service:afterApp'); $app->finish('service:finishApp'); $app->error('service:error'); $app->on('kernel.request', 'service:onRequest'); $app->match('/', 'service:controller')->convert('foo', 'service:convert')->before('service:before')->after('service:after'); $request = Request::create('/'); $response = $app->handle($request); $app->terminate($request, $response); $this->assertEquals(array('CONVERT', 'BEFORE APP', 'ON REQUEST', 'BEFORE', 'ERROR', 'AFTER', 'AFTER APP', 'FINISH APP'), $app['service']->called); }
public function testSwiftMailerSendsMailsOnFinish() { $app = new Application(); $app->register(new SwiftmailerServiceProvider()); $app->boot(); $app['swiftmailer.spool'] = $app->share(function () { return new SpoolStub(); }); $app->get('/', function () use($app) { $app['mailer']->send(\Swift_Message::newInstance()); }); $this->assertCount(0, $app['swiftmailer.spool']->getMessages()); $request = Request::create('/'); $response = $app->handle($request); $this->assertCount(1, $app['swiftmailer.spool']->getMessages()); $app->terminate($request, $response); $this->assertCount(0, $app['swiftmailer.spool']->getMessages()); }