ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TokenStreamTest.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase
13{
14 protected static $tokens;
15
16 protected function setUp()
17 {
18 self::$tokens = array(
27 );
28 }
29
34 {
35 $stream = new Twig_TokenStream(array(), 'foo', '{{ foo }}');
36 $this->assertEquals('foo', $stream->getFilename());
37 $this->assertEquals('{{ foo }}', $stream->getSource());
38 $this->assertEquals('foo', $stream->getSourceContext()->getName());
39 $this->assertEquals('{{ foo }}', $stream->getSourceContext()->getCode());
40 }
41
42 public function testNext()
43 {
44 $stream = new Twig_TokenStream(self::$tokens);
45 $repr = array();
46 while (!$stream->isEOF()) {
47 $token = $stream->next();
48
49 $repr[] = $token->getValue();
50 }
51 $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token');
52 }
53
58 public function testEndOfTemplateNext()
59 {
60 $stream = new Twig_TokenStream(array(
62 ));
63 while (!$stream->isEOF()) {
64 $stream->next();
65 }
66 }
67
72 public function testEndOfTemplateLook()
73 {
74 $stream = new Twig_TokenStream(array(
76 ));
77 while (!$stream->isEOF()) {
78 $stream->look();
79 $stream->next();
80 }
81 }
82}
An exception for terminatinating execution or to throw for unit testing.
testLegacyConstructorSignature()
@group legacy
testEndOfTemplateNext()
@expectedException Twig_Error_Syntax @expectedExceptionMessage Unexpected end of template
testEndOfTemplateLook()
@expectedException Twig_Error_Syntax @expectedExceptionMessage Unexpected end of template
Represents a token stream.
Definition: TokenStream.php:21
Represents a Token.
Definition: Token.php:21
const EOF_TYPE
Definition: Token.php:26
const TEXT_TYPE
Definition: Token.php:27
const BLOCK_START_TYPE
Definition: Token.php:28
$stream
PHP stream implementation.