|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category QualityAssurance |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Parser |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once 'PHPUnit/Framework.php'; |
|
51 |
+ |
|
52 |
+require_once dirname(__FILE__) . '/FunctionNameParserImplTest.php'; |
|
53 |
+ |
|
54 |
+/** |
|
55 |
+ * Main test suite for the PHP_Depend_Parser package. |
|
56 |
+ * |
|
57 |
+ * @category QualityAssurance |
|
58 |
+ * @package PHP_Depend |
|
59 |
+ * @subpackage Parser |
|
60 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
61 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
62 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
63 |
+ * @version Release: @package_version@ |
|
64 |
+ * @link http://pdepend.org/ |
|
65 |
+ */ |
|
66 |
+class PHP_Depend_Parser_AllTests extends PHPUnit_Framework_TestSuite |
|
67 |
+{ |
|
68 |
+ /** |
|
69 |
+ * Constructs a new test suite instance. |
|
70 |
+ */ |
|
71 |
+ public function __construct() |
|
72 |
+ { |
|
73 |
+ $this->setName('PHP::Depend::Parser::AllTests'); |
|
74 |
+ |
|
75 |
+ $this->addTestSuite('PHP_Depend_Parser_FunctionNameParserImplTest'); |
|
76 |
+ } |
|
77 |
+ |
|
78 |
+ /** |
|
79 |
+ * Returns a configured test suite instance. |
|
80 |
+ * |
|
81 |
+ * @return PHP_Depend_Parser_AllTests |
|
82 |
+ */ |
|
83 |
+ public static function suite() |
|
84 |
+ { |
|
85 |
+ return new PHP_Depend_Parser_AllTests(); |
|
86 |
+ } |
|
87 |
+} |
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category QualityAssurance |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Parser |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once dirname(__FILE__) . '/../AbstractTest.php'; |
|
51 |
+ |
|
52 |
+require_once 'PHP/Depend/Token.php'; |
|
53 |
+require_once 'PHP/Depend/TokenizerI.php'; |
|
54 |
+require_once 'PHP/Depend/Parser/TokenStack.php'; |
|
55 |
+require_once 'PHP/Depend/Parser/FunctionNameParserImpl.php'; |
|
56 |
+ |
|
57 |
+/** |
|
58 |
+ * Test case for the {@link PHP_Depend_Parser_FunctionNameParserImpl} class. |
|
59 |
+ * |
|
60 |
+ * @category QualityAssurance |
|
61 |
+ * @package PHP_Depend |
|
62 |
+ * @subpackage Parser |
|
63 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
64 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
65 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
66 |
+ * @version Release: @package_version@ |
|
67 |
+ * @link http://pdepend.org/ |
|
68 |
+ */ |
|
69 |
+class PHP_Depend_Parser_FunctionNameParserImplTest extends PHP_Depend_AbstractTest |
|
70 |
+{ |
|
71 |
+ /** |
|
72 |
+ * testParserHandlesTNamespaceAsValidFunctionName |
|
73 |
+ * |
|
74 |
+ * @return void |
|
75 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
76 |
+ * @group pdepend |
|
77 |
+ * @group pdepend::parser |
|
78 |
+ * @group unittest |
|
79 |
+ */ |
|
80 |
+ public function testParserHandlesTNamespaceAsValidFunctionName() |
|
81 |
+ { |
|
82 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
83 |
+ |
|
84 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
85 |
+ $tokenizer->expects($this->once()) |
|
86 |
+ ->method('peek') |
|
87 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_NAMESPACE)); |
|
88 |
+ $tokenizer->expects($this->once()) |
|
89 |
+ ->method('next') |
|
90 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
91 |
+ |
|
92 |
+ $stack = $this->getMock('PHP_Depend_Parser_TokenStack'); |
|
93 |
+ |
|
94 |
+ $parser->setTokenizer($tokenizer); |
|
95 |
+ $parser->setTokenStack($stack); |
|
96 |
+ |
|
97 |
+ $parser->parse(); |
|
98 |
+ } |
|
99 |
+ |
|
100 |
+ /** |
|
101 |
+ * testParserHandlesTStringAsValidFunctionName |
|
102 |
+ * |
|
103 |
+ * @return void |
|
104 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
105 |
+ * @group pdepend |
|
106 |
+ * @group pdepend::parser |
|
107 |
+ * @group unittest |
|
108 |
+ */ |
|
109 |
+ public function testParserHandlesTStringAsValidFunctionName() |
|
110 |
+ { |
|
111 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
112 |
+ |
|
113 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
114 |
+ $tokenizer->expects($this->once()) |
|
115 |
+ ->method('peek') |
|
116 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_STRING)); |
|
117 |
+ $tokenizer->expects($this->once()) |
|
118 |
+ ->method('next') |
|
119 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
120 |
+ |
|
121 |
+ $stack = $this->getMock('PHP_Depend_Parser_TokenStack'); |
|
122 |
+ |
|
123 |
+ $parser->setTokenizer($tokenizer); |
|
124 |
+ $parser->setTokenStack($stack); |
|
125 |
+ |
|
126 |
+ $parser->parse(); |
|
127 |
+ } |
|
128 |
+ |
|
129 |
+ /** |
|
130 |
+ * testParserAddsValidTokenToTokenStackInstance |
|
131 |
+ * |
|
132 |
+ * @return void |
|
133 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
134 |
+ * @group pdepend |
|
135 |
+ * @group pdepend::parser |
|
136 |
+ * @group unittest |
|
137 |
+ */ |
|
138 |
+ public function testParserAddsValidTokenToTokenStackInstance() |
|
139 |
+ { |
|
140 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
141 |
+ |
|
142 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
143 |
+ $tokenizer->expects($this->once()) |
|
144 |
+ ->method('peek') |
|
145 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_STRING)); |
|
146 |
+ $tokenizer->expects($this->once()) |
|
147 |
+ ->method('next') |
|
148 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
149 |
+ |
|
150 |
+ $stack = $this->getMock('PHP_Depend_Parser_TokenStack'); |
|
151 |
+ $stack->expects($this->once()) |
|
152 |
+ ->method('add'); |
|
153 |
+ |
|
154 |
+ $parser->setTokenizer($tokenizer); |
|
155 |
+ $parser->setTokenStack($stack); |
|
156 |
+ |
|
157 |
+ $parser->parse(); |
|
158 |
+ } |
|
159 |
+ |
|
160 |
+ /** |
|
161 |
+ * testParserThrowsExceptionForUnexpectedTokenTArray |
|
162 |
+ * |
|
163 |
+ * @return void |
|
164 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
165 |
+ * @group pdepend |
|
166 |
+ * @group pdepend::parser |
|
167 |
+ * @group unittest |
|
168 |
+ * @expectedException PHP_Depend_Parser_UnexpectedTokenException |
|
169 |
+ */ |
|
170 |
+ public function testParserThrowsExceptionForUnexpectedTokenTArray() |
|
171 |
+ { |
|
172 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
173 |
+ |
|
174 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
175 |
+ $tokenizer->expects($this->once()) |
|
176 |
+ ->method('peek') |
|
177 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_ARRAY)); |
|
178 |
+ $tokenizer->expects($this->once()) |
|
179 |
+ ->method('next') |
|
180 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
181 |
+ |
|
182 |
+ $parser->setTokenizer($tokenizer); |
|
183 |
+ |
|
184 |
+ $parser->parse(); |
|
185 |
+ } |
|
186 |
+ |
|
187 |
+ /** |
|
188 |
+ * testParserThrowsExceptionForUnexpectedTokenStreamEnd |
|
189 |
+ * |
|
190 |
+ * @return void |
|
191 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
192 |
+ * @group pdepend |
|
193 |
+ * @group pdepend::parser |
|
194 |
+ * @group unittest |
|
195 |
+ * @expectedException PHP_Depend_Parser_TokenStreamEndException |
|
196 |
+ */ |
|
197 |
+ public function testParserThrowsExceptionForUnexpectedTokenStreamEnd() |
|
198 |
+ { |
|
199 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
200 |
+ |
|
201 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
202 |
+ $tokenizer->expects($this->once()) |
|
203 |
+ ->method('peek') |
|
204 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_EOF)); |
|
205 |
+ |
|
206 |
+ $parser->setTokenizer($tokenizer); |
|
207 |
+ |
|
208 |
+ $parser->parse(); |
|
209 |
+ } |
|
210 |
+} |