public function testInjectionHttpFlow() { $this->container->set('troyan', 'call me'); $app = new App($this->router, $this->container); $request = (new Request())->withUri(new Uri('/'))->withMethod('GET'); $response = new Response(); $response = $app->run($request, $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('call me', $response->getBody()->__toString()); }
public function testDispatcherErrorCallsListenerIndex() { $dispatcherExceptionListener = $this->prophesize(DispatcherExceptionListener::class); $response = $this->prophesize(Response::class); $request = (new Request())->withUri(new Uri('/pnf'))->withMethod('GET'); $container = App::buildContainer(Loader::load()); $container->set(DispatcherExceptionListener::class, $dispatcherExceptionListener->reveal()); $app = new App(null, $container); $app->run($request, $response->reveal()); $dispatcherExceptionListener->onError(Argument::any())->shouldHaveBeenCalled(); }
public function testCorrectInjectionWithExternalContainer() { $builder = new ContainerBuilder(); $builder->addDefinitions(Loader::load()); $builder->useAnnotations(true); $app = new App($this->router, $builder->build()); $request = (new Request())->withUri(new Uri('/load'))->withMethod('GET'); $response = new Response(); $response = $app->run($request, $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('eureka', $response->getBody()->__toString()); }
<?php use GianArb\Penny\App; use Zend\Diactoros\Response\SapiEmitter; chdir(dirname(__DIR__)); require 'vendor/autoload.php'; $app = new App(); $emitter = new SapiEmitter(); $emitter->emit($app->run());