Skip to content

Commit

Permalink
Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BafS committed Jan 7, 2020
1 parent a1045a8 commit e9b771d
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.vscode
.phpintel
/vendor/
out.csv
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"homepage": "https://github.com/ProtonMail/php-coding-standard",
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test-print": "phpcs --standard=Proton/ruleset.xml --report=summary tests",
"test": "phpcs --standard=Proton/ruleset.xml --report=csv tests | sort -r | cut -f 2,3,4,6 -d ',' > tests/out.csv; diff tests/expected_csv.txt tests/out.csv"
},
"require": {
"php": "^7.1",
"slevomat/coding-standard": "^5.0|^6.0",
Expand Down
44 changes: 44 additions & 0 deletions tests/correct/ClassOk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Proton\Test;

use Proton\Http\Request;

final class ClassOk
{
use MyTrait;

/**
* Foo.
* @var array
*/
protected $foo = [];

public function __construct(array $config)
{
$this->foo = $config + [
'foo' => 'bar',
];
}

public function ping(Request $request)
{
return $request->query->get('test');
}

public function foo(string $a, string $b)
{
$a = $a . 'test';

if (
$a === 'a'
|| $b === 'b'
) {
return $a;
}

return false;
}
}
13 changes: 13 additions & 0 deletions tests/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

PHP CODE SNIFFER REPORT SUMMARY
------------------------------------------------------------------------------------------------
FILE ERRORS WARNINGS
------------------------------------------------------------------------------------------------
/Users/Username/dev/Proton/php-coding-standard/tests/wrong/Class1.php 30 0
/Users/Username/dev/Proton/php-coding-standard/tests/wrong/ClassMetrics.php 4 0
/Users/Username/dev/Proton/php-coding-standard/tests/wrong/file.php 2 0
------------------------------------------------------------------------------------------------
A TOTAL OF 36 ERRORS AND 0 WARNINGS WERE FOUND IN 3 FILES
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX 28 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------
42 changes: 42 additions & 0 deletions tests/expected_csv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Line,Column,Type,Source
4,10,error,PSR2.Files.EndFileNewline.NoneFound
1,1,error,SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
6,12,warning,Generic.Metrics.NestingLevel.TooHigh
5,20,error,PSR2.Classes.ClassDeclaration.OpenBraceNewLine
21,11,error, found 10"
20,9,warning,Generic.CodeAnalysis.UnconditionalIfStatement.Found
20,9,error,SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn.UselessIfCondition
1,1,error,SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
8,1,error, found 1."
6,18,error,PSR12.Files.FileHeader.SpacingInsideBlock
40,1,error,PSR2.Files.EndFileNewline.NoneFound
4,1,error, found 2."
38,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed
37,13,warning,Squiz.PHP.NonExecutableCode.Unreachable
37,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed
36,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed
35,9,error,Generic.PHP.LowerCaseKeyword.Found
35,9,error,Squiz.ControlStructures.LowercaseDeclaration.FoundUppercase
35,9,error,Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword
35,12,error,Squiz.NamingConventions.ValidVariableName.NotCamelCaps
35,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed
33,9,error,Squiz.NamingConventions.ValidVariableName.NotCamelCaps
33,24,warning,Generic.CodeAnalysis.EmptyPHPStatement.SemicolonWithoutCodeDetected
33,24,error,SlevomatCodingStandard.PHP.UselessSemicolon.UselessSemicolon
33,24,error,Generic.Formatting.DisallowMultipleStatements.SameLine
33,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed
31,31,error,Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine
31,13,error,SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod
27,27,error,PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword
24,13,error,SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
20,19,error,Generic.PHP.BacktickOperator.Found
20,14,error,Generic.PHP.BacktickOperator.Found
16,5,error,PSR12.Traits.UseDeclaration.UseAfterBrace
16,16,error,PSR12.Traits.UseDeclaration.MultipleImport
14,5,warning,PSR12.Properties.ConstantVisibility.NotFound
12,13,error,Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
12,13,error,SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty
12,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed
10,27,error,SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces.IncorrectEmptyLinesAfterOpeningBrace
10,27,error,PSR2.Classes.ClassDeclaration.OpenBraceNewLine
1,1,error,SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
40 changes: 40 additions & 0 deletions tests/wrong/Class1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php


namespace Test;

use Something\Foo;

use Something\bar;

abstract final class Test {

private $unused_field;

const TEST = 'NOTOK';

use MyTrait, MyTrait2;

public function __construct()
{
echo `test`;


print_r([
1
]);

$this->test = new class() {
};
}

private function unused() {
$fooBar = 1;
$foo_bar = '1';;

IF($foo_bar == '1') {
return true;
return true;
}
}
}
26 changes: 26 additions & 0 deletions tests/wrong/ClassMetrics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Test;

class ClassMetrics {
public function foo($a, $b, $c, $d, $e, $f)
{
if ($a) {
if ($b) {
if ($c) {
if ($d) {
if ($e) {
return $f;
}
}
}
}
}

if (true) {
return true;
} else {
return false;
}
}
}
4 changes: 4 additions & 0 deletions tests/wrong/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

/* */
return [];

0 comments on commit e9b771d

Please sign in to comment.