You are here

public function Twig_Tests_TemplateTest::testGetAttributeExceptions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/test/Twig/Tests/TemplateTest.php \Twig_Tests_TemplateTest::testGetAttributeExceptions()

@dataProvider getAttributeExceptions

File

vendor/twig/twig/test/Twig/Tests/TemplateTest.php, line 25

Class

Twig_Tests_TemplateTest

Code

public function testGetAttributeExceptions($template, $message, $useExt) {
  $name = 'index_' . ($useExt ? 1 : 0);
  $templates = array(
    $name => $template . $useExt,
  );
  $env = new Twig_Environment(new Twig_Loader_Array($templates), array(
    'strict_variables' => true,
  ));
  if (!$useExt) {
    $env
      ->addNodeVisitor(new CExtDisablingNodeVisitor());
  }
  $template = $env
    ->loadTemplate($name);
  $context = array(
    'string' => 'foo',
    'null' => null,
    'empty_array' => array(),
    'array' => array(
      'foo' => 'foo',
    ),
    'array_access' => new Twig_TemplateArrayAccessObject(),
    'magic_exception' => new Twig_TemplateMagicPropertyObjectWithException(),
    'object' => new stdClass(),
  );
  try {
    $template
      ->render($context);
    $this
      ->fail('Accessing an invalid attribute should throw an exception.');
  } catch (Twig_Error_Runtime $e) {
    $this
      ->assertSame(sprintf($message, $name), $e
      ->getMessage());
  }
}