Skip to content

Commit 7b84951

Browse files
committed
Adding unit tests for all PEAR sniffs
git-svn-id: http://svn.php.net/repository/pear/packages/PHP_CodeSniffer/trunk@220488 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent a9bb44a commit 7b84951

32 files changed

+2784
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
// Some code goes here.
4+
5+
// This comment contains # multiple
6+
// hash signs (#).
7+
8+
/*
9+
* Here is a small function comment.
10+
*/
11+
function test()
12+
{
13+
// Some code goes here.
14+
15+
# This comment is banned.
16+
17+
}//end test()
18+
19+
/*
20+
A longer comment goes here.
21+
It spans multiple lines.
22+
*/
23+
24+
# This is a long comment
25+
# that is banned.
26+
27+
?>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* +------------------------------------------------------------------------+
4+
* | BSD Licence |
5+
* +------------------------------------------------------------------------+
6+
* | This software is available to you under the BSD license, |
7+
* | available in the LICENSE file accompanying this software. |
8+
* | You may obtain a copy of the License at |
9+
* | |
10+
* | http://matrix.squiz.net/developer/tools/php_cs/licence |
11+
* | |
12+
* | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
13+
* | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
14+
* | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
15+
* | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
16+
* | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
17+
* | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
18+
* | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
19+
* | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
20+
* | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21+
* | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
22+
* | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23+
* +------------------------------------------------------------------------+
24+
* | Copyright (c), 2006 Squiz Pty Ltd (ABN 77 084 670 600). |
25+
* | All rights reserved. |
26+
* +------------------------------------------------------------------------+
27+
*
28+
* @package PHP_CodeSniffer
29+
* @author Squiz Pty Ltd
30+
*/
31+
32+
/**
33+
* Unit test class for the InlineComment sniff.
34+
*
35+
* A sniff unit test checks a .inc file for expected violations of a single
36+
* coding standard. Expected errors and warnings are stored in this class.
37+
*
38+
* @package PHP_CodeSniffer
39+
* @author Squiz Pty Ltd
40+
*/
41+
class PEAR_Tests_Commenting_InlineCommentUnitTest extends AbstractSniffUnitTest
42+
{
43+
44+
45+
/**
46+
* Returns the lines where errors should occur.
47+
*
48+
* The key of the array should represent the line number and the value
49+
* should represent the number of errors that should occur on that line.
50+
*
51+
* @return array(int => int)
52+
*/
53+
public function getErrorList()
54+
{
55+
return array(
56+
15 => 1,
57+
24 => 1,
58+
25 => 1,
59+
);
60+
61+
}//end getErrorList()
62+
63+
64+
/**
65+
* Returns the lines where warnings should occur.
66+
*
67+
* The key of the array should represent the line number and the value
68+
* should represent the number of warnings that should occur on that line.
69+
*
70+
* @return array(int => int)
71+
*/
72+
public function getWarningList()
73+
{
74+
return array();
75+
76+
}//end getWarningList()
77+
78+
79+
}//end class
80+
81+
?>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
define('VALID_NAME', true);
4+
define('invalidName', true);
5+
define("VALID_NAME", true);
6+
define("invalidName", true);
7+
8+
class TestClass extends MyClass
9+
{
10+
11+
const const1 = 'hello';
12+
const CONST2 = 'hello';
13+
14+
function test()
15+
{
16+
echo constant('VALID_NAME');
17+
echo VALID_NAME;
18+
print VALID_NAME;
19+
echo(VALID_NAME);
20+
print(VALID_NAME);
21+
echo constant('invalidName');
22+
echo invalidName;
23+
print invalidName;
24+
echo(invalidName);
25+
print(invalidName);
26+
27+
echo constant("VALID_NAME");
28+
echo constant("invalidName");
29+
30+
echo 'Hello', VALID_NAME;
31+
echo 'Hello', invalidName;
32+
33+
// These might look like constants to
34+
// poorly written code.
35+
echo 'Hello there';
36+
echo "HELLO";
37+
echo 'HELLO';
38+
print 'Hello there';
39+
print "HELLO";
40+
print 'HELLO';
41+
}
42+
43+
}
44+
45+
interface MyInterface
46+
{
47+
}
48+
49+
if (($object instanceof Some_Class) === false) {
50+
$var = <<<EOF
51+
This is some heredoc text.
52+
This is some heredoc text.
53+
This is some heredoc text.
54+
55+
This is some heredoc text.
56+
This is some heredoc text.
57+
This is some heredoc text.
58+
EOF;
59+
}
60+
61+
$var = <<<EOF
62+
This is some heredoc text.
63+
This is some heredoc text.
64+
This is some heredoc text.
65+
66+
This is some heredoc text.
67+
This is some heredoc text.
68+
This is some heredoc text.
69+
EOF;
70+
71+
throw new InvalidSomethingException;
72+
73+
?>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* +------------------------------------------------------------------------+
4+
* | BSD Licence |
5+
* +------------------------------------------------------------------------+
6+
* | This software is available to you under the BSD license, |
7+
* | available in the LICENSE file accompanying this software. |
8+
* | You may obtain a copy of the License at |
9+
* | |
10+
* | http://matrix.squiz.net/developer/tools/php_cs/licence |
11+
* | |
12+
* | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
13+
* | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
14+
* | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
15+
* | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
16+
* | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
17+
* | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
18+
* | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
19+
* | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
20+
* | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21+
* | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
22+
* | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23+
* +------------------------------------------------------------------------+
24+
* | Copyright (c), 2006 Squiz Pty Ltd (ABN 77 084 670 600). |
25+
* | All rights reserved. |
26+
* +------------------------------------------------------------------------+
27+
*
28+
* @package PHP_CodeSniffer
29+
* @author Squiz Pty Ltd
30+
*/
31+
32+
/**
33+
* Unit test class for the ValidConstantName sniff.
34+
*
35+
* A sniff unit test checks a .inc file for expected violations of a single
36+
* coding standard. Expected errors and warnings are stored in this class.
37+
*
38+
* @package PHP_CodeSniffer
39+
* @author Squiz Pty Ltd
40+
*/
41+
class PEAR_Tests_Constants_ValidConstantNameUnitTest extends AbstractSniffUnitTest
42+
{
43+
44+
45+
/**
46+
* Returns the lines where errors should occur.
47+
*
48+
* The key of the array should represent the line number and the value
49+
* should represent the number of errors that should occur on that line.
50+
*
51+
* @return array(int => int)
52+
*/
53+
public function getErrorList()
54+
{
55+
return array(
56+
4 => 1,
57+
6 => 1,
58+
11 => 1,
59+
21 => 1,
60+
22 => 1,
61+
23 => 1,
62+
24 => 1,
63+
25 => 1,
64+
28 => 1,
65+
31 => 1,
66+
);
67+
68+
}//end getErrorList()
69+
70+
71+
/**
72+
* Returns the lines where warnings should occur.
73+
*
74+
* The key of the array should represent the line number and the value
75+
* should represent the number of warnings that should occur on that line.
76+
*
77+
* @return array(int => int)
78+
*/
79+
public function getWarningList()
80+
{
81+
return array();
82+
83+
}//end getWarningList()
84+
85+
86+
}//end class
87+
88+
?>

0 commit comments

Comments
 (0)