1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Knp\RadBundle\Twig; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
|
8
|
|
|
class FlashesTokenParserSpec extends ObjectBehavior |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param Twig_Parser $parser |
12
|
|
|
* @param Twig_ExpressionParser $exprParser |
13
|
|
|
* @param Twig_TokenStream $stream |
14
|
|
|
* @param Twig_Token $token |
15
|
|
|
* @param Twig_NodeInterface $body |
|
|
|
|
16
|
|
|
* @param Knp\RadBundle\Twig\FlashesNodeFactory $nodeFactory |
17
|
|
|
* @param Knp\RadBundle\Twig\FlashesNode $node |
|
|
|
|
18
|
|
|
*/ |
19
|
|
|
function let($parser, $exprParser, $stream, $nodeFactory, $token) |
20
|
|
|
{ |
21
|
|
|
$this->beConstructedWith($nodeFactory); |
22
|
|
|
|
23
|
|
|
$parser->getStream()->willReturn($stream); |
24
|
|
|
$parser->getExpressionParser()->willReturn($exprParser); |
25
|
|
|
|
26
|
|
|
$token->getLine()->willReturn(123); |
27
|
|
|
|
28
|
|
|
$this->setParser($parser); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function it_should_be_a_twig_token_parser() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$this->shouldBeAnInstanceOf('Twig_TokenParserInterface'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_should_handle_flashes_tags() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$this->getTag()->shouldReturn('flashes'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {% flashes {expr:types} using catalog {expr:catalog} %} |
43
|
|
|
* <div class="flash {{ type }}">{{ message }}</div> |
44
|
|
|
* {% endflashes %} |
45
|
|
|
* |
46
|
|
|
* @param Twig_Node_Expression $types |
47
|
|
|
* @param Twig_Node_Expression $catalog |
48
|
|
|
*/ |
49
|
|
|
function it_should_parse_complete_flashes_tag( |
|
|
|
|
50
|
|
|
$parser, $exprParser, $stream, $body, $nodeFactory, $node, $token, $types, $catalog |
|
|
|
|
51
|
|
|
) |
52
|
|
|
{ |
|
|
|
|
53
|
|
|
$stream->test(\Twig_Token::BLOCK_END_TYPE)->willReturn(false); |
54
|
|
|
$stream->test(\Twig_Token::NAME_TYPE, 'using')->willReturn(false, true); |
55
|
|
|
|
56
|
|
|
$stream->expect(Argument::any())->will(function() {}); |
|
|
|
|
57
|
|
|
$stream->expect(Argument::cetera())->will(function() {}); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$exprParser->parseExpression()->willReturn($types, $catalog); |
60
|
|
|
|
61
|
|
|
$parser->subparse(array($this, 'isEndTag'), true)->willReturn($body); |
62
|
|
|
|
63
|
|
|
$nodeFactory->createFlashesNode($types, $catalog, $body, 123)->willReturn($node); |
64
|
|
|
|
65
|
|
|
$this->parse($token)->shouldReturn($node); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {% flashes {expr:types} %} |
70
|
|
|
* <div class="flash {{ type }}">{{ message }}</div> |
71
|
|
|
* {% endflashes %} |
72
|
|
|
* |
73
|
|
|
* @param Twig_Node_Expression $types |
74
|
|
|
*/ |
75
|
|
|
function it_should_parse_flashes_tag_with_no_specified_catalog( |
|
|
|
|
76
|
|
|
$parser, $exprParser, $stream, $body, $nodeFactory, $node, $token, $types |
|
|
|
|
77
|
|
|
) |
78
|
|
|
{ |
|
|
|
|
79
|
|
|
$stream->test(\Twig_Token::NAME_TYPE, 'using')->willReturn(false, false); |
80
|
|
|
$stream->test(\Twig_Token::BLOCK_END_TYPE)->willReturn(false); |
81
|
|
|
|
82
|
|
|
$exprParser->parseExpression()->willReturn($types); |
83
|
|
|
|
84
|
|
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE)->will(function() {}); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$parser->subparse(array($this, 'isEndTag'), true)->willReturn($body); |
87
|
|
|
|
88
|
|
|
$nodeFactory->createFlashesNode($types, null, $body, 123)->willReturn($node); |
89
|
|
|
|
90
|
|
|
$this->parse($token)->shouldReturn($node); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {% flashes using catalog {expr:catalog} %} |
95
|
|
|
* <div class="flash {{ type }}">{{ message }}</div> |
96
|
|
|
* {% endflashes %} |
97
|
|
|
* |
98
|
|
|
* @param Twig_Node_Expression $catalog |
99
|
|
|
*/ |
100
|
|
|
function it_should_parse_flashes_tag_with_no_specified_types( |
|
|
|
|
101
|
|
|
$parser, $exprParser, $stream, $body, $nodeFactory, $node, $token, $catalog |
|
|
|
|
102
|
|
|
) |
103
|
|
|
{ |
|
|
|
|
104
|
|
|
$stream->test(\Twig_Token::NAME_TYPE, 'using')->willReturn(true, true); |
105
|
|
|
$stream->expect(\Twig_Token::NAME_TYPE, 'using')->will(function() {}); |
|
|
|
|
106
|
|
|
$stream->expect(\Twig_Token::NAME_TYPE, 'catalog')->will(function() {}); |
|
|
|
|
107
|
|
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE)->will(function() {}); |
|
|
|
|
108
|
|
|
|
109
|
|
|
$exprParser->parseExpression()->willReturn($catalog); |
110
|
|
|
|
111
|
|
|
$parser->subparse(array($this, 'isEndTag'), true)->willReturn($body); |
112
|
|
|
|
113
|
|
|
$nodeFactory->createFlashesNode(null, $catalog, $body, 123)->willReturn($node); |
114
|
|
|
|
115
|
|
|
$this->parse($token)->shouldReturn($node); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {% flashes using catalog {expr:catalog} %} |
120
|
|
|
* <div class="flash {{ type }}">{{ message }}</div> |
121
|
|
|
* {% endflashes %} |
122
|
|
|
*/ |
123
|
|
|
function it_should_parse_flashes_tag_with_no_specified_types_nor_catalog( |
|
|
|
|
124
|
|
|
$parser, $exprParser, $stream, $body, $nodeFactory, $node, $token |
|
|
|
|
125
|
|
|
) |
126
|
|
|
{ |
|
|
|
|
127
|
|
|
$stream->test(\Twig_Token::NAME_TYPE, 'using')->willReturn(false, false); |
128
|
|
|
$stream->test(\Twig_Token::BLOCK_END_TYPE)->willReturn(true); |
129
|
|
|
|
130
|
|
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE)->will(function() {}); |
|
|
|
|
131
|
|
|
|
132
|
|
|
$parser->subparse(array($this, 'isEndTag'), true)->willReturn($body); |
133
|
|
|
|
134
|
|
|
$nodeFactory->createFlashesNode(null, null, $body, 123)->willReturn($node); |
135
|
|
|
|
136
|
|
|
$this->parse($token)->shouldReturn($node); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
function its_isEndTag_should_return_true_recognize_end_tag_token($token) |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$token->test('endflashes')->willReturn(true); |
142
|
|
|
|
143
|
|
|
$this->isEndTag($token)->shouldReturn(true); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
function its_isEndTag_should_return_false_otherwise($token) |
|
|
|
|
147
|
|
|
{ |
148
|
|
|
$token->test('endflashes')->willReturn(false); |
149
|
|
|
|
150
|
|
|
$this->isEndTag($token)->shouldReturn(false); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.