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)); }
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)); }
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); }
/** * 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; }
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(); }
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); }
/** * @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); }
public function testLoadsByCustomPath() { $config = Loader::load('./config/custom/{{*}}{{,*.local}}.php'); $this->assertTrue($config['nine']); }