-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
... for quite a few report types. The Reports which PHPCS can generate, were until now not covered by tests and therefore had no safeguards/QA whatsoever. This commit sets up an initial end-to-end test suite with tests for common report types. It doesn't have an opinion on whether or not the reports as currently generated are formatted correctly. For now, it just codifies the current functionality. For lack of documentation about this format in the PHPUnit docs, the test docs for PHP Core are the closest available to explain the available sections and how to apply these: https://qa.php.net/phpt_details.php With this initial setup done, it should be fairly straight-forward to expand this end-to-end test suite to cover more report types and to add tests for other command-line options as well. Mind: these type of tests are generally slow, so unit tests/integration tests should be preferred.
- Loading branch information
Showing
22 changed files
with
710 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
/* | ||
* Test fixture file for End to End Report tests. | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures; | ||
|
||
class CleanClass { | ||
const UPPERCASE = true; | ||
|
||
public function myMethod() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/* | ||
* Test fixture file for End to End Report tests. | ||
*/ | ||
|
||
class dirty_class { | ||
const lowerCase = false; | ||
|
||
public function My_Method() {} | ||
} | ||
|
||
class Second_class {} | ||
|
||
$obj = new dirty_class(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
Report: Checkstyle | ||
|
||
--SKIPIF-- | ||
<?php | ||
if (is_file(__DIR__.'/../../../autoload.php') === false) { | ||
print 'skip: Test cannot run from a PEAR install.'; | ||
} | ||
?> | ||
--ARGS-- | ||
./tests/EndToEnd/Fixtures/Reports/ -q --no-colors --report-width=80 --basepath=./tests/EndToEnd/Fixtures/Reports/ --standard=PSR1 --report=Checkstyle | ||
|
||
--FILE-- | ||
<?php | ||
require_once __DIR__ . '/../../../bin/phpcs'; | ||
|
||
--EXPECTF-- | ||
#!/usr/bin/env php | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<checkstyle version="%s"> | ||
<file name="Dirty.php"> | ||
<error line="1" column="1" severity="warning" message="A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 6 and the first side effect is on line 14." source="PSR1.Files.SideEffects.FoundWithSymbols"/> | ||
<error line="6" column="1" severity="error" message="Each class must be in a namespace of at least one level (a top-level vendor name)" source="PSR1.Classes.ClassDeclaration.MissingNamespace"/> | ||
<error line="6" column="1" severity="error" message="Class name "dirty_class" is not in PascalCase format" source="Squiz.Classes.ValidClassName.NotCamelCaps"/> | ||
<error line="7" column="11" severity="error" message="Class constants must be uppercase; expected LOWERCASE but found lowerCase" source="Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase"/> | ||
<error line="9" column="12" severity="error" message="Method name "dirty_class::My_Method" is not in camel caps format" source="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/> | ||
<error line="12" column="1" severity="error" message="Each class must be in a file by itself" source="PSR1.Classes.ClassDeclaration.MultipleClasses"/> | ||
<error line="12" column="1" severity="error" message="Each class must be in a namespace of at least one level (a top-level vendor name)" source="PSR1.Classes.ClassDeclaration.MissingNamespace"/> | ||
<error line="12" column="1" severity="error" message="Class name "Second_class" is not in PascalCase format" source="Squiz.Classes.ValidClassName.NotCamelCaps"/> | ||
</file> | ||
</checkstyle> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--TEST-- | ||
Report: Code, no error codes | ||
|
||
--SKIPIF-- | ||
<?php | ||
if (is_file(__DIR__.'/../../../autoload.php') === false) { | ||
print 'skip: Test cannot run from a PEAR install.'; | ||
} | ||
?> | ||
--ARGS-- | ||
./tests/EndToEnd/Fixtures/Reports/ -q --no-colors --report-width=80 --basepath=./tests/EndToEnd/Fixtures/Reports/ --standard=PSR1 --report=Code | ||
|
||
--FILE-- | ||
<?php | ||
require_once __DIR__ . '/../../../bin/phpcs'; | ||
|
||
--EXPECTF-- | ||
#!/usr/bin/env php | ||
|
||
FILE: Dirty.php | ||
-------------------------------------------------------------------------------- | ||
FOUND 7 ERRORS AND 1 WARNING AFFECTING 5 LINES | ||
-------------------------------------------------------------------------------- | ||
LINE 1: WARNING A file should declare new symbols (classes, functions, | ||
constants, etc.) and cause no other side effects, or it should | ||
execute logic with side effects, but should not do both. The | ||
first symbol is defined on line 6 and the first side effect is | ||
on line 14. | ||
-------------------------------------------------------------------------------- | ||
>> 1: <?php | ||
2: /* | ||
3: * Test fixture file for End to End Report tests. | ||
-------------------------------------------------------------------------------- | ||
LINE 6: ERROR Each class must be in a namespace of at least one level (a | ||
top-level vendor name) | ||
LINE 6: ERROR Class name "dirty_class" is not in PascalCase format | ||
-------------------------------------------------------------------------------- | ||
4: */ | ||
5:%w | ||
>> 6: class dirty_class { | ||
7: const lowerCase = false; | ||
8: | ||
-------------------------------------------------------------------------------- | ||
LINE 7: ERROR Class constants must be uppercase; expected LOWERCASE but found | ||
lowerCase | ||
-------------------------------------------------------------------------------- | ||
5:%w | ||
6: class dirty_class { | ||
>> 7: const lowerCase = false; | ||
8:%w | ||
9: public function My_Method() {} | ||
-------------------------------------------------------------------------------- | ||
LINE 9: ERROR Method name "dirty_class::My_Method" is not in camel caps | ||
format | ||
-------------------------------------------------------------------------------- | ||
7: const lowerCase = false; | ||
8:%w | ||
>> 9: public function My_Method() {} | ||
10: } | ||
11: | ||
-------------------------------------------------------------------------------- | ||
LINE 12: ERROR Each class must be in a file by itself | ||
LINE 12: ERROR Each class must be in a namespace of at least one level (a | ||
top-level vendor name) | ||
LINE 12: ERROR Class name "Second_class" is not in PascalCase format | ||
-------------------------------------------------------------------------------- | ||
10: } | ||
11:%w | ||
>> 12: class Second_class {} | ||
13:%w | ||
14: $obj = new dirty_class(); | ||
-------------------------------------------------------------------------------- | ||
Time: %f secs; Memory: %dMB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--TEST-- | ||
Report: Code, with error codes | ||
|
||
--SKIPIF-- | ||
<?php | ||
if (is_file(__DIR__.'/../../../autoload.php') === false) { | ||
print 'skip: Test cannot run from a PEAR install.'; | ||
} | ||
?> | ||
--ARGS-- | ||
./tests/EndToEnd/Fixtures/Reports/ -qs --no-colors --report-width=80 --basepath=./tests/EndToEnd/Fixtures/Reports/ --standard=PSR1 --report=Code | ||
|
||
--FILE-- | ||
<?php | ||
require_once __DIR__ . '/../../../bin/phpcs'; | ||
|
||
--EXPECTF-- | ||
#!/usr/bin/env php | ||
|
||
FILE: Dirty.php | ||
-------------------------------------------------------------------------------- | ||
FOUND 7 ERRORS AND 1 WARNING AFFECTING 5 LINES | ||
-------------------------------------------------------------------------------- | ||
LINE 1: WARNING A file should declare new symbols (classes, functions, constants, | ||
etc.) and cause no other side effects, or it should execute logic with | ||
side effects, but should not do both. The first symbol is defined on | ||
line 6 and the first side effect is on line 14. | ||
(PSR1.Files.SideEffects.FoundWithSymbols) | ||
-------------------------------------------------------------------------------- | ||
>> 1: <?php | ||
2: /* | ||
3: * Test fixture file for End to End Report tests. | ||
-------------------------------------------------------------------------------- | ||
LINE 6: ERROR Each class must be in a namespace of at least one level (a | ||
top-level vendor name) | ||
(PSR1.Classes.ClassDeclaration.MissingNamespace) | ||
LINE 6: ERROR Class name "dirty_class" is not in PascalCase format | ||
(Squiz.Classes.ValidClassName.NotCamelCaps) | ||
-------------------------------------------------------------------------------- | ||
4: */ | ||
5:%w | ||
>> 6: class dirty_class { | ||
7: const lowerCase = false; | ||
8: | ||
-------------------------------------------------------------------------------- | ||
LINE 7: ERROR Class constants must be uppercase; expected LOWERCASE but found | ||
lowerCase | ||
(Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase) | ||
-------------------------------------------------------------------------------- | ||
5:%w | ||
6: class dirty_class { | ||
>> 7: const lowerCase = false; | ||
8:%w | ||
9: public function My_Method() {} | ||
-------------------------------------------------------------------------------- | ||
LINE 9: ERROR Method name "dirty_class::My_Method" is not in camel caps | ||
format (PSR1.Methods.CamelCapsMethodName.NotCamelCaps) | ||
-------------------------------------------------------------------------------- | ||
7: const lowerCase = false; | ||
8:%w | ||
>> 9: public function My_Method() {} | ||
10: } | ||
11: | ||
-------------------------------------------------------------------------------- | ||
LINE 12: ERROR Each class must be in a file by itself | ||
(PSR1.Classes.ClassDeclaration.MultipleClasses) | ||
LINE 12: ERROR Each class must be in a namespace of at least one level (a | ||
top-level vendor name) | ||
(PSR1.Classes.ClassDeclaration.MissingNamespace) | ||
LINE 12: ERROR Class name "Second_class" is not in PascalCase format | ||
(Squiz.Classes.ValidClassName.NotCamelCaps) | ||
-------------------------------------------------------------------------------- | ||
10: } | ||
11:%w | ||
>> 12: class Second_class {} | ||
13:%w | ||
14: $obj = new dirty_class(); | ||
-------------------------------------------------------------------------------- | ||
Time: %f secs; Memory: %dMB |
Oops, something went wrong.