public function testApplicationWithGetRequest() { $app = new Application(); $app->get('/', function (\Symfony\Component\HttpFoundation\Request $request) { return new \Symfony\Component\HttpFoundation\Response('Hello World'); }); $conn = $this->getMock('React\\Socket\\ConnectionInterface'); $conn->expects($this->atLeastOnce())->method('write')->with($this->isType('string')); $request = new Request('GET', '/'); $response = new Response($conn); $app($request, $response); }
public function testApplicationWithGetRequest() { $app = new Application(); $app->get('/', function () { return 'Hello World'; }); $conn = $this->getMock('React\\Socket\\ConnectionInterface'); $conn->expects($this->at(3))->method('write')->with($this->stringContains('text/html')); $conn->expects($this->at(4))->method('write')->with($this->stringContains('Hello World')); $request = new Request('GET', '/'); $response = new Response($conn); $app($request, $response); }
public function testApplicationWithGetRequest() { $app = new Application(); $app->get('/', function ($request, $response) { $response->writeHead(200, array('Content-Type' => 'text/plain')); $response->end("Hello World\n"); }); $conn = $this->getMock('React\\Socket\\ConnectionInterface'); $conn->expects($this->at(0))->method('write')->with($this->stringContains("text/plain")); $conn->expects($this->at(1))->method('write')->with($this->stringContains("Hello World\n")); $request = new Request('GET', '/'); $response = new Response($conn); $app($request, $response); }
<?php /* * This file is part of the Caffeine Experiment. * * (c) Tigran Azatyan <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace App; require './vendor/autoload.php'; use React\Espresso\Application; use React\Espresso\Stack; use Silex\Provider\TwigServiceProvider; $app = new Application(); $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/views']); $app->get('/', function ($request, $response) use($app) { $response->writeHead(200, ['Content-Type' => 'text/html']); $body = $app['twig']->render('home.html.twig'); $response->end($body); }); $app->error(function ($request, $response) { $response->writeHead(404, ['Content-Type' => 'text/html']); $response->end('Error 404'); }); $stack = new Stack($app); $stack->listen(1337);