Exemplo n.º 1
0
 public function testHandle()
 {
     $request = Request::create('http://localhost/test', 'GET', array(), array(), array(), array('PATH_INFO' => '/test'));
     $fileCache = new FileCacheModuleProvider($this->application);
     $fileCache->setCachePath(vfsStream::url('cacheDir'));
     $this->application[\Phruts\Util\Globals::MODULE_CONFIG_PROVIDER] = $fileCache;
     $response = $this->actionKernel->handle($request, HttpKernelInterface::MASTER_REQUEST, false);
     $this->assertEquals(200, $response->getStatusCode(), $response->getContent());
     //        $request = Request::create('http://localhost/admin/test', 'GET', array(), array(), array(), array('PATH_INFO' => '/admin/test'));
     //        RequestUtils::selectModule($request, $this->application);
     //        $response = $this->actionKernel->handle($request, HttpKernelInterface::MASTER_REQUEST, false);
     //        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());
 }
Exemplo n.º 2
0
 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param \Silex\Application $app An Application instance
  */
 public function register(\Silex\Application $app)
 {
     // Register our action server
     $app[\Phruts\Util\Globals::ACTION_KERNEL] = $app->share(function () use($app) {
         return new \Phruts\Action\ActionKernel($app);
     });
     // Register our digester for when we need it
     $app[\Phruts\Util\Globals::DIGESTER] = $app->share(function () use($app) {
         $digester = new Digester();
         $digester->addRuleSet(new ConfigRuleSet('phruts-config'));
         return $digester;
     });
     $app[\Phruts\Util\Globals::MODULE_CONFIG_PROVIDER] = $app->share(function () use($app) {
         $provider = new FileCacheModuleProvider($app);
         // Set the cache
         $cache = $app[\Phruts\Util\Globals::CACHE_DIR];
         if (empty($cache)) {
             $cache = getcwd() . '/../app/cache/';
         }
         $provider->setCachePath($cache);
         return $provider;
     });
 }
Exemplo n.º 3
0
 public function createApplication()
 {
     // Create a silex application
     $app = new Silex\Application();
     // Configure test environments
     $app['debug'] = true;
     $app['exception_handler']->disable();
     $app['session.test'] = true;
     // Add in phruts to organise your controllers
     $app->register(new Phruts\Provider\PhrutsServiceProvider(), array(Phruts\Util\Globals::ACTION_KERNEL_CONFIG => array('config' => __DIR__ . '/Resources/module1-config.xml', 'config/moduleA' => __DIR__ . '/Resources/module2-config.xml', 'config/moduleB' => __DIR__ . '/Resources/module2-config.xml,' . __DIR__ . '/Resources/module1-config.xml')));
     // Setup the mock file system for caching
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory('cacheDir'));
     $app[Phruts\Util\Globals::MODULE_CONFIG_PROVIDER] = $app->share(function () use($app) {
         $provider = new FileCacheModuleProvider($app);
         $provider->setCachePath(vfsStream::url('cacheDir'));
         return $provider;
     });
     // Add a relevant html
     $app->get('{path}', function ($path) use($app) {
         return new \Symfony\Component\HttpFoundation\Response(file_get_contents(__DIR__ . '/Resources/' . $path));
     })->assert('path', '.+\\.html');
     // Add routes to be matched by Phruts
     $app->get('/my/{path}.do', function (Request $request) use($app) {
         return $app[Phruts\Util\Globals::ACTION_KERNEL]->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     })->assert('path', '.*')->before(function (Request $request) {
         // Match a ".do" as context path
         $path = $request->attributes->get('path');
         if (!empty($path)) {
             $request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $path);
         }
     });
     // Add routes to be matched by Phruts
     $app->get('{path}', function (Request $request) use($app) {
         return $app[Phruts\Util\Globals::ACTION_KERNEL]->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     })->assert('path', '.*')->value('path', '/')->before(function (Request $request) {
         $do = $request->get('do');
         if (!empty($do)) {
             $rewritePath = $request->attributes->get('_rewrite_path');
             // tmp var as attributes
             if (empty($rewritePath)) {
                 $request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $do);
                 $request->attributes->set('_rewrite_path', 1);
             } else {
                 $request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, null);
             }
         }
     });
     return $app;
 }