public function testJSONResponse()
 {
     $appName = 'App15';
     $projectFolder = ProjectUtil::createNewProject($appName, true);
     list($clazz, $loader) = ProjectUtil::initProjectClassLoader($projectFolder);
     ProjectUtil::appendOrCreateServicesConfig($projectFolder, ['custom-exception-handler' => CustomRequestExceptionHandler::class, 'controller-test-module' => ControllerTestModule::class]);
     $factory = new ApplicationFactory($clazz, $projectFolder);
     $app = $factory->create();
     $output = catch_output(function () use($app) {
         $request = Request::create("/api/hello/world");
         $app->run($request);
     });
     $this->assertEquals('{"hello":"world"}', $output);
     self::$cleanup[] = $projectFolder;
 }
Example #2
0
 public function testRoutingExtension()
 {
     $appName = 'TwigRouting';
     $projectFolder = ProjectUtil::createNewProject($appName, true);
     list($clazz, $loader) = ProjectUtil::initProjectClassLoader($projectFolder);
     ProjectUtil::appendOrCreateServicesConfig($projectFolder, ["runtime" => 'TwigRouting\\TwigRoutingRuntime', "twig-module" => TwigModule::class, 'locale-service' => LocaleService::class, TranslatorInterface::class => TranslatorFactory::class, 'test-translations' => TestTranslationProvider::class, EngineInterface::class => TwigEngineService::class]);
     $factory = new ApplicationFactory($clazz, $projectFolder, true);
     /* @var $app TestableApplication */
     $app = $factory->create();
     $request = Request::create("/urltest/am");
     ProjectUtil::addSession($request);
     $output = catch_output(function () use($app, $request) {
         $app->run($request);
     });
     $this->assertEquals("http://localhost/urltest/am?hello=world", $output);
     self::$cleanup[] = $projectFolder;
 }
Example #3
0
 public function testTranslationFactory()
 {
     $appName = 'TransApp1';
     $projectFolder = ProjectUtil::createNewProject($appName, true);
     list($clazz, $loader) = ProjectUtil::initProjectClassLoader($projectFolder);
     ProjectUtil::appendOrCreateServicesConfig($projectFolder, ['acme-module' => [$projectFolder . '/src/Acme', 'Acme\\Acme'], 'locale-service' => LocaleService::class, TranslatorInterface::class => TranslatorFactory::class, 'test-translations' => Stubs\TestTranslationProvider::class]);
     $factory = new ApplicationFactory(TestableApplication::class, $projectFolder);
     /* @var $app TestableApplication */
     $app = $factory->create();
     $request = Request::create("/am");
     ProjectUtil::addSession($request);
     $output = catch_output(function () use($app, $request) {
         $app->run($request);
     });
     $translator = $app->getContainer()->get(TranslatorInterface::class);
     $this->assertEquals('Bari louys Blend!', $translator->trans('Good morning :name!', [':name' => 'Blend']));
     self::$cleanup[] = $projectFolder;
 }
 /**
  * @large
  */
 public function testCustomExceptionHandler()
 {
     $appName = 'App14';
     $projectFolder = ProjectUtil::createNewProject($appName, true);
     list($clazz, $loader) = ProjectUtil::initProjectClassLoader($projectFolder);
     ProjectUtil::appendOrCreateServicesConfig($projectFolder, ['custom-exception-handler' => CustomRequestExceptionHandler::class]);
     $factory = new ApplicationFactory($clazz, $projectFolder);
     $app = $factory->create();
     $request = Request::create("/notexists");
     $output = catch_output(function () use($app, $request) {
         $app->run($request);
     });
     $this->assertEquals('Page not found /notexists', $output);
     self::$cleanup[] = $projectFolder;
 }