Skip to content

Commit 58c8493

Browse files
committed
Add test coverage
1 parent 98b6689 commit 58c8493

File tree

207 files changed

+609
-6411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+609
-6411
lines changed

PSR2R/Tools/SniffsAndTests.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* MIT License
5+
* For full license information, please view the LICENSE file that was distributed with this source code.
6+
*/
7+
8+
namespace PSR2R\Tools;
9+
10+
use RecursiveDirectoryIterator;
11+
use RecursiveIteratorIterator;
12+
use RecursiveRegexIterator;
13+
use RegexIterator;
14+
15+
class SniffsAndTests
16+
{
17+
/**
18+
* @var array<string>
19+
*/
20+
protected static $orgs = [
21+
'PSR2R',
22+
];
23+
24+
/**
25+
* @param string $path Path
26+
*
27+
* @return array<string, array<string, mixed>>
28+
*/
29+
public function untested(string $path): array
30+
{
31+
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
32+
33+
$sniffs = [];
34+
35+
foreach (static::$orgs as $org) {
36+
$directoryIterator = new RecursiveDirectoryIterator($path . $org);
37+
$recursiveIterator = new RecursiveIteratorIterator($directoryIterator);
38+
$regexIterator = new RegexIterator($recursiveIterator, '#^.+/(\w+)/Sniffs/(\w+)/(\w+)Sniff\.php$#', RecursiveRegexIterator::GET_MATCH);
39+
40+
foreach ($regexIterator as $match) {
41+
$org = $match[1];
42+
$type = $match[2];
43+
$name = $match[3];
44+
$testFile = $path . 'tests' . DIRECTORY_SEPARATOR . $org . 'Sniffs' . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $name . 'SniffTest.php';
45+
$hasTest = file_exists($testFile);
46+
if ($hasTest) {
47+
continue;
48+
}
49+
50+
$key = $org . '.' . $type . '.' . $name;
51+
$sniffs[$key] = [
52+
'hasTest' => $hasTest,
53+
];
54+
}
55+
}
56+
57+
return $sniffs;
58+
}
59+
}

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"squizlabs/php_codesniffer": "^3.7.0"
1919
},
2020
"require-dev": {
21+
"phpunit/phpunit": "^9.5",
2122
"phpstan/phpstan": "^1.0.0"
2223
},
2324
"autoload": {
@@ -27,10 +28,10 @@
2728
},
2829
"autoload-dev": {
2930
"psr-4": {
30-
"PSR2R\\Base\\": "tests/PSR2R/Base/",
31-
"PSR2R\\Tests\\": "tests/PSR2R/Tests/"
31+
"PSR2R\\Test\\": "tests/"
3232
}
3333
},
34+
"prefer-stable": true,
3435
"minimum-stability": "stable",
3536
"bin": [
3637
"bin/tokenize",
@@ -41,10 +42,8 @@
4142
"docs-listing": "phpcs -e --standard=PSR2R/ruleset.xml",
4243
"cs-check": "phpcs",
4344
"cs-fix": "phpcbf",
44-
"test": "php phpunit.phar",
45-
"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit-9.5.10.phar && mv phpunit-9.5.10.phar phpunit.phar || true",
46-
"test-setup-mac": "[ ! -f phpunit.phar ] && curl -OL https://phar.phpunit.de/phpunit-9.5.10.phar && mv phpunit-9.5.10.phar phpunit.phar || true",
47-
"test-coverage": "php phpunit.phar --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml",
45+
"test": "phpunit",
46+
"test-coverage": "phpunit --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml",
4847
"lowest": "validate-prefer-lowest",
4948
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
5049
"stan": "phpstan analyse"

phpunit.xml.dist

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="tests/bootstrap.php">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
34
<php>
45
<ini name="memory_limit" value="-1"/>
56
<ini name="apc.enable_cli" value="1"/>
67
</php>
78

8-
<!-- Add any additional test suites you want to run here -->
99
<testsuites>
1010
<testsuite name="psr2r">
11-
<directory>tests/Sniffs/</directory>
12-
</testsuite>
13-
<testsuite name="Extension of PHP_CodeSniffer Test Suite">
14-
<file>tests/AllTests.php</file>
11+
<directory>tests/PSR2R/</directory>
1512
</testsuite>
16-
<!-- Add plugin test suites here. -->
1713
</testsuites>
1814

19-
<filter>
20-
<whitelist processUncoveredFilesFromWhitelist="true">
15+
<coverage processUncoveredFiles="true">
16+
<include>
2117
<directory>PSR2R/</directory>
22-
</whitelist>
23-
</filter>
24-
18+
</include>
19+
</coverage>
2520
</phpunit>

setup.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@
33

44
# Download composer phar if not available yet
55
[ ! -f composer.phar ] && curl -sS https://getcomposer.org/installer | php
6-
7-
# Download phpunit phar if not available yet
8-
[ ! -f phpunit.phar ] && php composer.phar test-setup

tests/AllTests.php

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* MIT License
5+
* For full license information, please view the LICENSE file that was distributed with this source code.
6+
*/
7+
8+
namespace PSR2R\Sniffs;
9+
10+
use PSR2R\Test\TestCase;
11+
12+
/**
13+
* Test integration of all sniffs together.
14+
*/
15+
class AllSniffTest extends TestCase
16+
{
17+
/**
18+
* @return void
19+
*/
20+
public function testAllSniffs(): void
21+
{
22+
$before = $this->testFilePath() . 'All' . DS . 'before.php';
23+
$after = $this->testFilePath() . 'All' . DS . 'after.php';
24+
25+
// Use --debug to display the errors found
26+
$errors = $this->runFullFixer($before, $after);
27+
$this->assertNotEmpty($errors);
28+
29+
$this->runFullFixer($before, $after, null, null, true);
30+
}
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* MIT License
5+
* For full license information, please view the LICENSE file that was distributed with this source code.
6+
*/
7+
8+
namespace PSR2R\Test\PSR2R\Sniffs\PHP;
9+
10+
use PSR2R\Test\TestCase;
11+
use PSR2R\Sniffs\PHP\DuplicateSemicolonSniff;
12+
13+
class DuplicateSemicolonSniffTest extends TestCase
14+
{
15+
/**
16+
* @return void
17+
*/
18+
public function testDocBlockConstSniffer(): void
19+
{
20+
$this->assertSnifferFindsErrors(new DuplicateSemicolonSniff(), 2);
21+
}
22+
23+
/**
24+
* @return void
25+
*/
26+
public function testDocBlockConstFixer(): void
27+
{
28+
$this->assertSnifferCanFixErrors(new DuplicateSemicolonSniff());
29+
}
30+
}

tests/PSR2R/Tests/Classes/BraceOnSameLineUnitTest.1.inc

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/PSR2R/Tests/Classes/BraceOnSameLineUnitTest.2.inc

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)