Example #1
0
 protected function getParser()
 {
     $parser = new Apishka_Templater_Parser(new Apishka_Templater_Environment($this->createMock('Apishka_Templater_LoaderInterface')));
     $parser->setParent(Apishka_Templater_Node::apishka());
     $p = new ReflectionProperty($parser, 'stream');
     $p->setAccessible(true);
     $p->setValue($parser, $this->getMockBuilder('Apishka_Templater_TokenStream')->disableOriginalConstructor()->getMock());
     return $parser;
 }
Example #2
0
 /**
  * Get test
  *
  * @param Apishka_Templater_Parser $parser
  * @param mixed                    $line
  *
  * @return mixed
  */
 private function getTest(Apishka_Templater_Parser $parser, $line)
 {
     $stream = $parser->getStream();
     $name = $stream->expect(Apishka_Templater_Token::NAME_TYPE)->getValue();
     $env = $parser->getEnvironment();
     if ($test = $env->getTest($name)) {
         return $test;
     }
     if ($stream->test(Apishka_Templater_Token::NAME_TYPE)) {
         // try 2-words tests
         $name = $name . ' ' . $parser->getCurrentToken()->getValue();
         if ($test = $env->getTest($name)) {
             $parser->getStream()->next();
             return $test;
         }
     }
     $e = new Apishka_Templater_Error_Syntax(sprintf('Unknown "%s" test.', $name), $line, $parser->getFilename());
     $e->addSuggestions($name, array_keys($env->getTests()));
     throw $e;
 }
Example #3
0
 /**
  * Parse test expression
  *
  * @return Apishka_Templater_NodeAbstract
  */
 public function parseTestExpression()
 {
     $node = (new Apishka_Templater_Node_Expression_Binary_TestIs($this->_parser, $this->_node))->parseTestExpression();
     return Apishka_Templater_Node_Expression_Unary_Not::apishka($node, $this->_parser->getCurrentToken()->getLine());
 }
 /**
  * @expectedException        Apishka_Templater_Error_Syntax
  * @expectedExceptionMessage The "block" function takes at least one argument (the variable and the attributes) in "index" at line 1.
  */
 public function testBlockNoArgs()
 {
     $env = new Apishka_Templater_Environment($this->createMock('Apishka_Templater_LoaderInterface'), array('cache' => false, 'autoescape' => false));
     $parser = new Apishka_Templater_Parser($env);
     $parser->parse($env->tokenize('{{ block() }}', 'index'));
 }