getGlobals() public method

As of Twig 2.x, the ability to register a global variable after runtime or the extensions have been initialized will not be possible any longer, but changing the value of an already registered global is possible.
public getGlobals ( )
Example #1
0
 public function testGetGlobalsSafe()
 {
     $app = $this->getApp();
     $request = Request::createFromGlobals();
     $app['request'] = $request;
     $app['request_stack']->push($request);
     $handlers = $this->getTwigHandlers($app);
     $twig = new TwigExtension($app, $handlers, true);
     $result = $twig->getGlobals();
     $this->assertArrayHasKey('config', $result);
     $this->assertNull($result['config']);
     $this->assertNull($result['users']);
 }
Example #2
0
 public function testGetGlobalsExceptionalExceptionIsExceptional()
 {
     $app = $this->getApp();
     $users = $this->getMock('Bolt\\Users', ['getCurrentUser'], [$app]);
     $users->expects($this->atLeastOnce())->method('getCurrentUser')->will($this->throwException(new \Exception()));
     $app['users'] = $users;
     $request = Request::createFromGlobals();
     $app['request'] = $request;
     $app['request_stack']->push($request);
     $handlers = $this->getTwigHandlers($app);
     $twig = new TwigExtension($app, $handlers, false);
     $result = $twig->getGlobals();
     $this->assertArrayHasKey('user', $result);
     $this->assertArrayHasKey('users', $result);
     $this->assertNull($result['user']);
     $this->assertNull($result['users']);
 }