Skip to content

Commit 89f335b

Browse files
committed
testing for PSR-2
1 parent 9ca6696 commit 89f335b

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"require-dev": {
99
"phpunit/phpunit": "^5.1"
1010
},
11+
"suggest": {
12+
"fabpot/php-cs-fixer": "PHP CS Fixer (testing for PSR-2 compliance)"
13+
},
1114
"minimum-stability": "stable",
1215
"autoload": {
1316
"psr-0": {

tests/VerbalExpressions/PHPVerbalExpressions/VerbalExpressionsTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,4 +561,54 @@ public function testReplace(){
561561
$this->assertEquals('/foo/mg', $regex->getRegex());
562562
$this->assertEquals('bazbarbaz', $regex->replace('foobarfoo', 'baz'));
563563
}
564+
565+
566+
public function testPsr2(){
567+
$pathToRoot = dirname(dirname(dirname(__DIR__)));
568+
$pathToVendor = $pathToRoot . '/vendor';
569+
$pathToSrc = $pathToRoot . '/src';
570+
$pathToTests = $pathToRoot . '/tests';
571+
572+
if(
573+
!is_dir($pathToVendor)
574+
){
575+
$this->markTestSkipped('Vendor directory not found.');
576+
return;
577+
}else if(
578+
!is_dir($pathToSrc)
579+
){
580+
$this->markTestSkipped('Source directory not found.');
581+
return;
582+
}else if(
583+
!is_dir($pathToTests)
584+
){
585+
$this->markTestSkipped('Tests directory not found.');
586+
return;
587+
}
588+
589+
foreach(array(
590+
$pathToTests,
591+
$pathToSrc,
592+
) as $dirToCheck){
593+
$cmd = escapeshellcmd(
594+
'php-cs-fixer fix --level=psr2 --dry-run ' . $dirToCheck
595+
);
596+
exec($cmd, $output, $return_var);
597+
if($output){
598+
array_pop($output);
599+
$output = array_map('trim', $output);
600+
}
601+
602+
$this->assertEquals(
603+
0,
604+
$return_var,
605+
(
606+
'PSR-2 linter reported errors in ' .
607+
$dirToCheck .
608+
'/: ' .
609+
implode(';', $output)
610+
)
611+
);
612+
}
613+
}
564614
}

0 commit comments

Comments
 (0)