Arbit - project tracking

PHPMD

Browse source code

File: / test/ PHP/ PMD/ ParserFactoryTest.php

Type
text/plain text/plain
Last Author
mapi
Version
200
Line Rev. Author Source
1 157 mapi <?php
2 mapi /**
3 mapi * This file is part of PHP_PMD.
4 mapi *
5 mapi * PHP Version 5
6 mapi *
7 174 mapi * Copyright (c) 2009, Manuel Pichler <mapi@phpmd.org>.
8 157 mapi * All rights reserved.
9 mapi *
10 mapi * Redistribution and use in source and binary forms, with or without
11 mapi * modification, are permitted provided that the following conditions
12 mapi * are met:
13 mapi *
14 mapi * * Redistributions of source code must retain the above copyright
15 mapi * notice, this list of conditions and the following disclaimer.
16 mapi *
17 mapi * * Redistributions in binary form must reproduce the above copyright
18 mapi * notice, this list of conditions and the following disclaimer in
19 mapi * the documentation and/or other materials provided with the
20 mapi * distribution.
21 mapi *
22 mapi * * Neither the name of Manuel Pichler nor the names of his
23 mapi * contributors may be used to endorse or promote products derived
24 mapi * from this software without specific prior written permission.
25 mapi *
26 mapi * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 mapi * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 mapi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 mapi * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 mapi * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 mapi * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 mapi * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 mapi * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 mapi * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 mapi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 mapi * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 mapi * POSSIBILITY OF SUCH DAMAGE.
38 mapi *
39 mapi * @category PHP
40 mapi * @package PHP_PMD
41 174 mapi * @author Manuel Pichler <mapi@phpmd.org>
42 173 mapi * @copyright 2009 Manuel Pichler. All rights reserved.
43 157 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
44 mapi * @version SVN: $Id$
45 174 mapi * @link http://phpmd.org
46 157 mapi */
47 mapi
48 mapi require_once dirname(__FILE__) . '/AbstractTest.php';
49 mapi
50 mapi require_once 'PHP/PMD.php';
51 mapi require_once 'PHP/PMD/ParserFactory.php';
52 mapi
53 mapi /**
54 mapi * Test case for the parser factory class.
55 mapi *
56 mapi * @category PHP
57 mapi * @package PHP_PMD
58 174 mapi * @author Manuel Pichler <mapi@phpmd.org>
59 173 mapi * @copyright 2009 Manuel Pichler. All rights reserved.
60 157 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 mapi * @version Release: @package_version@
62 174 mapi * @link http://phpmd.org
63 157 mapi */
64 mapi class PHP_PMD_ParserFactoryTest extends PHP_PMD_AbstractTest
65 mapi {
66 mapi /**
67 mapi * testFactoryConfiguresInputDirectory
68 mapi *
69 mapi * @return void
70 mapi * @covers PHP_PMD_ParserFactory
71 mapi * @group phpmd
72 mapi * @group unittest
73 mapi */
74 mapi public function testFactoryConfiguresInputDirectory()
75 mapi {
76 mapi $factory = new PHP_PMD_ParserFactory();
77 mapi
78 mapi $uri = $this->createFileUri('ParserFactory/Directory');
79 mapi
80 mapi $phpmd = $this->getMock('PHP_PMD');
81 mapi $phpmd->expects($this->once())
82 mapi ->method('getInput')
83 mapi ->will($this->returnValue($uri));
84 mapi
85 200 mapi $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class');
86 157 mapi
87 mapi $parser = $factory->create($phpmd);
88 mapi $parser->addRuleSet($ruleSet);
89 mapi $parser->parse($this->getReportMock(0));
90 mapi }
91 mapi
92 mapi /**
93 mapi * testFactoryConfiguresInputFile
94 mapi *
95 mapi * @return void
96 mapi * @covers PHP_PMD_ParserFactory
97 mapi * @group phpmd
98 mapi * @group unittest
99 mapi */
100 mapi public function testFactoryConfiguresInputFile()
101 mapi {
102 mapi $factory = new PHP_PMD_ParserFactory();
103 mapi
104 mapi $uri = $this->createFileUri('ParserFactory/File/Test.php');
105 mapi
106 mapi $phpmd = $this->getMock('PHP_PMD');
107 mapi $phpmd->expects($this->once())
108 mapi ->method('getInput')
109 mapi ->will($this->returnValue($uri));
110 mapi
111 200 mapi $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class');
112 157 mapi
113 mapi $parser = $factory->create($phpmd);
114 mapi $parser->addRuleSet($ruleSet);
115 mapi $parser->parse($this->getReportMock(0));
116 mapi }
117 mapi
118 mapi /**
119 159 mapi * testFactoryConfiguresMultipleInputDirectories
120 mapi *
121 mapi * @return void
122 mapi * @covers PHP_PMD_ParserFactory
123 mapi * @group phpmd
124 mapi * @group unittest
125 mapi */
126 mapi public function testFactoryConfiguresMultipleInputDirectories()
127 mapi {
128 mapi $factory = new PHP_PMD_ParserFactory();
129 mapi
130 mapi $uri1 = $this->createFileUri('ParserFactory/File');
131 mapi $uri2 = $this->createFileUri('ParserFactory/Directory');
132 mapi
133 162 mapi $phpmd = $this->getMock('PHP_PMD', array('getInput'));
134 159 mapi $phpmd->expects($this->once())
135 mapi ->method('getInput')
136 mapi ->will($this->returnValue($uri1 . ',' . $uri2));
137 mapi
138 200 mapi $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class', 2);
139 159 mapi
140 mapi $parser = $factory->create($phpmd);
141 mapi $parser->addRuleSet($ruleSet);
142 mapi $parser->parse($this->getReportMock(0));
143 mapi }
144 mapi
145 mapi /**
146 mapi * testFactoryConfiguresMultipleInputFilesAndDirectories
147 mapi *
148 mapi * @return void
149 mapi * @covers PHP_PMD_ParserFactory
150 mapi * @group phpmd
151 mapi * @group unittest
152 mapi */
153 mapi public function testFactoryConfiguresMultipleInputFilesAndDirectories()
154 mapi {
155 mapi $factory = new PHP_PMD_ParserFactory();
156 mapi
157 mapi $uri1 = $this->createFileUri('ParserFactory/File/Test.php');
158 mapi $uri2 = $this->createFileUri('ParserFactory/Directory');
159 mapi
160 162 mapi $phpmd = $this->getMock('PHP_PMD', array('getInput'));
161 159 mapi $phpmd->expects($this->once())
162 mapi ->method('getInput')
163 mapi ->will($this->returnValue($uri1 . ',' . $uri2));
164 mapi
165 200 mapi $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class', 2);
166 159 mapi
167 mapi $parser = $factory->create($phpmd);
168 mapi $parser->addRuleSet($ruleSet);
169 mapi $parser->parse($this->getReportMock(0));
170 mapi }
171 mapi
172 mapi /**
173 157 mapi * testFactoryConfiguresIgnorePattern
174 mapi *
175 mapi * @return void
176 mapi * @covers PHP_PMD_ParserFactory
177 mapi * @group phpmd
178 mapi * @group unittest
179 mapi */
180 mapi public function testFactoryConfiguresIgnorePattern()
181 mapi {
182 mapi $factory = new PHP_PMD_ParserFactory();
183 mapi
184 mapi $uri = $this->createFileUri('ParserFactory/File/Test.php');
185 mapi
186 mapi $phpmd = $this->getMock('PHP_PMD');
187 mapi $phpmd->expects($this->exactly(2))
188 mapi ->method('getIgnorePattern')
189 mapi ->will($this->returnValue(array('Test')));
190 mapi $phpmd->expects($this->once())
191 mapi ->method('getInput')
192 mapi ->will($this->returnValue($uri));
193 mapi
194 mapi $parser = $factory->create($phpmd);
195 mapi }
196 mapi
197 mapi /**
198 mapi * testFactoryConfiguresFileExtensions
199 mapi *
200 mapi * @return void
201 mapi * @covers PHP_PMD_ParserFactory
202 mapi * @group phpmd
203 mapi * @group unittest
204 mapi */
205 mapi public function testFactoryConfiguresFileExtensions()
206 mapi {
207 mapi $factory = new PHP_PMD_ParserFactory();
208 mapi
209 mapi $uri = $this->createFileUri('ParserFactory/File/Test.php');
210 mapi
211 mapi $phpmd = $this->getMock('PHP_PMD');
212 mapi $phpmd->expects($this->exactly(2))
213 mapi ->method('getFileExtensions')
214 mapi ->will($this->returnValue(array('.php')));
215 mapi $phpmd->expects($this->once())
216 mapi ->method('getInput')
217 mapi ->will($this->returnValue($uri));
218 mapi
219 mapi $parser = $factory->create($phpmd);
220 mapi }
221 164 mapi }