Example #1
0
 public function setUp()
 {
     $config = Loader::load();
     $config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
         $r->addRoute('GET', '/', ['TestApp\\Controller\\IndexController', 'index']);
     });
     $this->app = new App(Container\PHPDiFactory::buildContainer($config));
 }
Example #2
0
 public function setUp()
 {
     $config = Loader::load();
     $config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
         $r->addRoute('GET', '/', [get_class($this), 'index']);
     });
     $config['dispatcher'] = \Di\object('PennyTest\\Utils\\FastSymfonyDispatcher')->constructor(\Di\get('router'), \Di\get('di'));
     $this->app = new App(Container\PHPDiFactory::buildContainer($config));
 }
Example #3
0
 public function setUp()
 {
     chdir(__DIR__ . '/app/');
     $config = Loader::load();
     $config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
         $r->addRoute('GET', '/load', ['TestApp\\Controller\\IndexController', 'loadedParams'], ['name' => 'load']);
     });
     $this->container = Container\PHPDiFactory::buildContainer($config);
 }
Example #4
0
 public function testDispatchGot500Exception()
 {
     $this->setExpectedException('Exception');
     $router = $this->prophesize('FastRoute\\Dispatcher', PHPDiFactory::buildContainer());
     $container = $this->prophesize('Interop\\Container\\ContainerInterface', PHPDiFactory::buildContainer());
     $request = (new ServerRequest())->withUri(new Uri('/'))->withMethod('POST');
     $router->dispatch('POST', '/')->willReturn([0 => 3])->shouldBeCalled();
     $dispatcher = new Dispatcher($router->reveal(), $container->reveal());
     $dispatcher($request);
 }
Example #5
0
 /**
  * Application initialization.
  *
  * @param ContainerInterface $container Dependency Injection container.
  *
  * @throws Exception If no router is defined.
  */
 public function __construct(ContainerInterface $container = null)
 {
     if ($container === null) {
         $container = Container\PHPDiFactory::buildContainer(Loader::load());
     }
     if ($container->has('router') === false) {
         throw new Exception('Define router config');
     }
     $this->container = $container;
 }
Example #6
0
 public function testDispatcherErrorCallsListenerIndex()
 {
     $dispatcherExceptionListener = $this->prophesize(WhoopsListener::class);
     $response = $this->prophesize(Response::class);
     $request = (new Request())->withUri(new Uri('/pnf'))->withMethod('GET');
     $container = Container\PHPDiFactory::buildContainer(Loader::load());
     $container->set(WhoopsListener::class, $dispatcherExceptionListener->reveal());
     $app = new App($container);
     $app->run($request, $response->reveal());
     $dispatcherExceptionListener->onError(Argument::any())->shouldHaveBeenCalled();
 }
Example #7
0
 public function testBootstrapEventTriggered()
 {
     $config = Loader::load();
     $config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
         $r->addRoute('GET', '/', [IndexController::class, 'index']);
     });
     $this->app = new App(Container\PHPDiFactory::buildContainer($config));
     $this->app->getContainer()->get('event_manager')->attach('bootstrap', function () {
         echo 'bootstrap triggered';
     });
     ob_start();
     $this->app->run();
     $content = ob_get_clean();
     $this->assertEquals('bootstrap triggered', $content);
 }
Example #8
0
 /**
  * @expectedException \RuntimeException
  */
 public function testDispatcherShouldBeCallable()
 {
     $request = (new Request())->withUri(new Uri('/'))->withMethod('POST');
     $response = new Response();
     $config = Loader::load();
     $config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
         $r->addRoute('GET', '/', ['TestApp\\Controller\\IndexController', 'index']);
     });
     $config['dispatcher'] = new \StdClass();
     $app = new App(Container\PHPDiFactory::buildContainer($config));
     $app->run($request, $response);
 }