Skip to content

Commit dd3c84e

Browse files
authored
Merge pull request #20 from 123inkt/Update-phpstan-and-min-php
Update phpstan, phpunit and min php
2 parents 9005d25 + 8b129f3 commit dd3c84e

15 files changed

+78
-145
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
18+
php-versions: ['8.1', '8.2', '8.3', '8.4']
1919
composer-flags: ['', '--prefer-lowest']
2020
steps:
2121
- uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/vendor
33
/composer.lock
44
/phpunit.xml
5-
/.phpunit.result.cache
5+
/.phpunit.cache

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BA)](https://php.net/)
1+
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BA)](https://php.net/)
22
![Run tests](https://github.com/123inkt/php-codesniffer-baseline/workflows/Run%20checks/badge.svg)
33

44
# PHP_Codesniffer baseline

composer.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,26 @@
1313
"lock": false
1414
},
1515
"require": {
16-
"php": ">=7.4",
17-
"composer-plugin-api": "^1.0 || ^2.0",
16+
"php": ">=8.1",
17+
"composer-plugin-api": "^2.0",
1818
"squizlabs/php_codesniffer": "^3.6"
1919
},
2020
"require-dev": {
2121
"composer/composer": "^2.0",
2222
"mikey179/vfsstream": "1.6.12",
2323
"phpmd/phpmd": "^2.15",
24-
"phpstan/phpstan": "^1.4",
25-
"phpstan/phpstan-phpunit": "^1.0",
26-
"phpstan/phpstan-strict-rules": "^1.1",
27-
"phpstan/extension-installer": "^1.1",
28-
"phpunit/phpunit": "^9.5",
24+
"phpstan/phpstan": "^2.0",
25+
"phpstan/phpstan-phpunit": "^2.0",
26+
"phpstan/phpstan-strict-rules": "^2.0",
27+
"phpstan/extension-installer": "^1.4",
28+
"phpunit/phpunit": "^10.5 || ^11.5",
2929
"roave/security-advisories": "dev-latest"
3030
},
3131
"scripts": {
32+
"baseline": ["@baseline:phpcs", "@baseline:phpmd", "@baseline:phpstan", "@baseline:phpcqc"],
33+
"baseline:phpcs": "phpcs --report=\\\\DR\\\\CodeSnifferBaseline\\\\Reports\\\\Baseline --report-file=phpcs.baseline.xml --basepath=.",
34+
"baseline:phpmd": "@check:phpmd --generate-baseline",
35+
"baseline:phpstan": "phpstan --generate-baseline",
3236
"run:plugin": "DR\\CodeSnifferBaseline\\Plugin\\Plugin::run",
3337
"check": ["@check:phpstan", "@check:phpmd", "@check:phpcs"],
3438
"check:phpstan": "phpstan analyse",

phpunit.xml.dist

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
bootstrap="tests/bootstrap.php"
5-
forceCoversAnnotation="true"
65
failOnRisky="true"
76
failOnWarning="true"
7+
failOnSkipped="true"
88
beStrictAboutChangesToGlobalState="true"
99
beStrictAboutOutputDuringTests="true"
10-
beStrictAboutResourceUsageDuringSmallTests="true"
11-
beStrictAboutTodoAnnotatedTests="true"
1210
executionOrder="defects"
11+
cacheDirectory=".phpunit.cache"
12+
requireCoverageMetadata="true"
13+
displayDetailsOnTestsThatTriggerErrors="true"
14+
displayDetailsOnTestsThatTriggerWarnings="true"
15+
displayDetailsOnTestsThatTriggerNotices="true"
16+
displayDetailsOnTestsThatTriggerDeprecations="true"
1317
>
1418
<testsuites>
1519
<testsuite name="unit">
1620
<directory>tests/Unit</directory>
1721
</testsuite>
1822
</testsuites>
19-
<coverage processUncoveredFiles="true">
23+
<source>
2024
<include>
21-
<directory suffix=".php">src</directory>
25+
<directory>src</directory>
2226
</include>
23-
</coverage>
27+
</source>
2428
</phpunit>

src/Baseline/BaselineSetFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class BaselineSetFactory
1010
/**
1111
* Read the baseline violations from the given filename path.
1212
* @throws RuntimeException
13-
* @SuppressWarnings(PHPMD.ErrorControlOperator) - handled by the RuntimeException
1413
*/
1514
public static function fromFile(string $fileName): ?BaselineSet
1615
{

src/Plugin/Plugin.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Plugin implements PluginInterface, EventSubscriberInterface
1616
{
1717
private ?IOInterface $stream = null;
18-
private string $codeSnifferFilePath;
18+
private string $codeSnifferFilePath;
1919

2020
public function __construct(?string $codeSnifferFilePath = null)
2121
{
@@ -48,9 +48,6 @@ public function uninstall(Composer $composer, IOInterface $stream): void
4848
// not necessary
4949
}
5050

51-
/**
52-
* @SuppressWarnings(PHPMD.ErrorControlOperator) - handled by the === false check
53-
*/
5451
public function onPostInstall(): void
5552
{
5653
if ($this->stream === null) {

tests/Unit/Baseline/BaselineSetFactoryTest.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
namespace DR\CodeSnifferBaseline\Tests\Unit\Baseline;
55

66
use DR\CodeSnifferBaseline\Baseline\BaselineSetFactory;
7+
use PHPUnit\Framework\Attributes\CoversClass;
78
use PHPUnit\Framework\TestCase;
89
use RuntimeException;
910

10-
/**
11-
* @coversDefaultClass \DR\CodeSnifferBaseline\Baseline\BaselineSetFactory
12-
*/
11+
#[CoversClass(BaselineSetFactory::class)]
1312
class BaselineSetFactoryTest extends TestCase
1413
{
15-
/**
16-
* @covers ::fromFile
17-
*/
1814
public function testFromFileShouldSucceed(): void
1915
{
2016
$filename = __DIR__ . '/TestFiles/baseline.xml';
@@ -23,9 +19,6 @@ public function testFromFileShouldSucceed(): void
2319
static::assertTrue($set->contains('Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen', '/test/src/foo/bar', 'foobar'));
2420
}
2521

26-
/**
27-
* @covers ::fromFile
28-
*/
2922
public function testFromFileShouldSucceedWithBackAndForwardSlashes(): void
3023
{
3124
$filename = __DIR__ . '/TestFiles/baseline.xml';
@@ -35,47 +28,32 @@ public function testFromFileShouldSucceedWithBackAndForwardSlashes(): void
3528
static::assertTrue($set->contains('Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen', '/test\\src\\foo/bar', 'foobar'));
3629
}
3730

38-
/**
39-
* @covers ::fromFile
40-
*/
4131
public function testFromFileShouldReturnNullIfAbsent(): void
4232
{
4333
static::assertNull(BaselineSetFactory::fromFile('foobar.xml'));
4434
}
4535

46-
/**
47-
* @covers ::fromFile
48-
*/
4936
public function testFromFileShouldThrowExceptionForOnInvalidXML(): void
5037
{
5138
$this->expectException(RuntimeException::class);
5239
$this->expectExceptionMessage('Unable to read xml from');
5340
BaselineSetFactory::fromFile(__DIR__ . '/TestFiles/invalid-baseline.xml');
5441
}
5542

56-
/**
57-
* @covers ::fromFile
58-
*/
5943
public function testFromFileViolationMissingSniffShouldThrowException(): void
6044
{
6145
$this->expectException(RuntimeException::class);
6246
$this->expectExceptionMessage('Missing `sniff` attribute in `violation`');
6347
BaselineSetFactory::fromFile(__DIR__ . '/TestFiles/missing-sniff-baseline.xml');
6448
}
6549

66-
/**
67-
* @covers ::fromFile
68-
*/
6950
public function testFromFileViolationMissingSignatureShouldThrowException(): void
7051
{
7152
$this->expectException(RuntimeException::class);
7253
$this->expectExceptionMessage('Missing `signature` attribute in `violation` in');
7354
BaselineSetFactory::fromFile(__DIR__ . '/TestFiles/missing-signature-baseline.xml');
7455
}
7556

76-
/**
77-
* @covers ::fromFile
78-
*/
7957
public function testFromFileViolationMissingFileShouldThrowException(): void
8058
{
8159
$this->expectException(RuntimeException::class);

tests/Unit/Baseline/BaselineSetTest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33

44
namespace DR\CodeSnifferBaseline\Tests\Unit\Baseline;
55

6+
use PHPUnit\Framework\Attributes\CoversClass;
67
use DR\CodeSnifferBaseline\Baseline\BaselineSet;
78
use DR\CodeSnifferBaseline\Baseline\ViolationBaseline;
89
use PHPUnit\Framework\TestCase;
910

1011
/**
1112
* Test the logic of the baseline set
12-
* @coversDefaultClass \DR\CodeSnifferBaseline\Baseline\BaselineSet
1313
*/
14+
#[CoversClass(BaselineSet::class)]
1415
class BaselineSetTest extends TestCase
1516
{
16-
/**
17-
* @covers ::addEntry
18-
* @covers ::contains
19-
*
20-
*/
2117
public function testSetContainsEntry(): void
2218
{
2319
$set = new BaselineSet();
@@ -26,10 +22,6 @@ public function testSetContainsEntry(): void
2622
static::assertTrue($set->contains('sniff', 'foobar', 'signature'));
2723
}
2824

29-
/**
30-
* @covers ::addEntry
31-
* @covers ::contains
32-
*/
3325
public function testShouldFindEntryForIdenticalRules(): void
3426
{
3527
$set = new BaselineSet();
@@ -42,10 +34,6 @@ public function testShouldFindEntryForIdenticalRules(): void
4234
static::assertFalse($set->contains('sniff', 'foo', 'signB'));
4335
}
4436

45-
/**
46-
* @covers ::addEntry
47-
* @covers ::contains
48-
*/
4937
public function testShouldNotFindEntryForNonExistingRule(): void
5038
{
5139
$set = new BaselineSet();

tests/Unit/Baseline/ViolationBaselineTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@
33

44
namespace DR\CodeSnifferBaseline\Tests\Unit\Baseline;
55

6+
use PHPUnit\Framework\Attributes\CoversClass;
67
use DR\CodeSnifferBaseline\Baseline\ViolationBaseline;
78
use PHPUnit\Framework\TestCase;
89

9-
/**
10-
* @coversDefaultClass \DR\CodeSnifferBaseline\Baseline\ViolationBaseline
11-
*/
10+
#[CoversClass(ViolationBaseline::class)]
1211
class ViolationBaselineTest extends TestCase
1312
{
14-
/**
15-
* @covers ::__construct
16-
* @covers ::getSniffName
17-
* @covers ::getSignature
18-
*/
1913
public function testAccessors(): void
2014
{
2115
$violation = new ViolationBaseline('sniff', 'foobar', 'signature');
@@ -25,8 +19,6 @@ public function testAccessors(): void
2519

2620
/**
2721
* Test the give file matches the baseline correctly
28-
* @covers ::__construct
29-
* @covers ::matches
3022
*/
3123
public function testMatches(): void
3224
{

tests/Unit/Plugin/BaselineHandlerTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,20 @@
33

44
namespace DR\CodeSnifferBaseline\Tests\Unit\Plugin;
55

6+
use PHPUnit\Framework\Attributes\CoversClass;
67
use DR\CodeSnifferBaseline\Baseline\BaselineSet;
78
use DR\CodeSnifferBaseline\Plugin\BaselineHandler;
89
use PHPUnit\Framework\TestCase;
910

10-
/**
11-
* @coversDefaultClass \DR\CodeSnifferBaseline\Plugin\BaselineHandler
12-
* @covers ::__construct
13-
*/
11+
#[CoversClass(BaselineHandler::class)]
1412
class BaselineHandlerTest extends TestCase
1513
{
16-
/**
17-
* @covers ::isSuppressed
18-
*/
1914
public function testIsSuppressedNoBaselineShouldBeFalse(): void
2015
{
2116
$handler = new BaselineHandler(null);
2217
static::assertFalse($handler->isSuppressed([], 1, 'foobar', '/path/'));
2318
}
2419

25-
/**
26-
* @covers ::isSuppressed
27-
*/
2820
public function testIsSuppressedWithBaseline(): void
2921
{
3022
$baseline = $this->createMock(BaselineSet::class);

0 commit comments

Comments
 (0)