Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
php-versions: ['8.1', '8.2', '8.3', '8.4']
composer-flags: ['', '--prefer-lowest']
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/vendor
/composer.lock
/phpunit.xml
/.phpunit.result.cache
/.phpunit.cache
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BA)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BA)](https://php.net/)
![Run tests](https://github.com/123inkt/php-codesniffer-baseline/workflows/Run%20checks/badge.svg)

# PHP_Codesniffer baseline
Expand Down
18 changes: 11 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@
"lock": false
},
"require": {
"php": ">=7.4",
"composer-plugin-api": "^1.0 || ^2.0",
"php": ">=8.1",
"composer-plugin-api": "^2.0",
"squizlabs/php_codesniffer": "^3.6"
},
"require-dev": {
"composer/composer": "^2.0",
"mikey179/vfsstream": "1.6.12",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/extension-installer": "^1.4",
"phpunit/phpunit": "^10.5 || ^11.5",
"roave/security-advisories": "dev-latest"
},
"scripts": {
"baseline": ["@baseline:phpcs", "@baseline:phpmd", "@baseline:phpstan", "@baseline:phpcqc"],
"baseline:phpcs": "phpcs --report=\\\\DR\\\\CodeSnifferBaseline\\\\Reports\\\\Baseline --report-file=phpcs.baseline.xml --basepath=.",
"baseline:phpmd": "@check:phpmd --generate-baseline",
"baseline:phpstan": "phpstan --generate-baseline",
"run:plugin": "DR\\CodeSnifferBaseline\\Plugin\\Plugin::run",
"check": ["@check:phpstan", "@check:phpmd", "@check:phpcs"],
"check:phpstan": "phpstan analyse",
Expand Down
18 changes: 11 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
forceCoversAnnotation="true"
failOnRisky="true"
failOnWarning="true"
failOnSkipped="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutResourceUsageDuringSmallTests="true"
beStrictAboutTodoAnnotatedTests="true"
executionOrder="defects"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
1 change: 0 additions & 1 deletion src/Baseline/BaselineSetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class BaselineSetFactory
/**
* Read the baseline violations from the given filename path.
* @throws RuntimeException
* @SuppressWarnings(PHPMD.ErrorControlOperator) - handled by the RuntimeException
*/
public static function fromFile(string $fileName): ?BaselineSet
{
Expand Down
5 changes: 1 addition & 4 deletions src/Plugin/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Plugin implements PluginInterface, EventSubscriberInterface
{
private ?IOInterface $stream = null;
private string $codeSnifferFilePath;
private string $codeSnifferFilePath;

public function __construct(?string $codeSnifferFilePath = null)
{
Expand Down Expand Up @@ -48,9 +48,6 @@ public function uninstall(Composer $composer, IOInterface $stream): void
// not necessary
}

/**
* @SuppressWarnings(PHPMD.ErrorControlOperator) - handled by the === false check
*/
public function onPostInstall(): void
{
if ($this->stream === null) {
Expand Down
26 changes: 2 additions & 24 deletions tests/Unit/Baseline/BaselineSetFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
namespace DR\CodeSnifferBaseline\Tests\Unit\Baseline;

use DR\CodeSnifferBaseline\Baseline\BaselineSetFactory;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use RuntimeException;

/**
* @coversDefaultClass \DR\CodeSnifferBaseline\Baseline\BaselineSetFactory
*/
#[CoversClass(BaselineSetFactory::class)]
class BaselineSetFactoryTest extends TestCase
{
/**
* @covers ::fromFile
*/
public function testFromFileShouldSucceed(): void
{
$filename = __DIR__ . '/TestFiles/baseline.xml';
Expand All @@ -23,9 +19,6 @@ public function testFromFileShouldSucceed(): void
static::assertTrue($set->contains('Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen', '/test/src/foo/bar', 'foobar'));
}

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

/**
* @covers ::fromFile
*/
public function testFromFileShouldReturnNullIfAbsent(): void
{
static::assertNull(BaselineSetFactory::fromFile('foobar.xml'));
}

/**
* @covers ::fromFile
*/
public function testFromFileShouldThrowExceptionForOnInvalidXML(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Unable to read xml from');
BaselineSetFactory::fromFile(__DIR__ . '/TestFiles/invalid-baseline.xml');
}

/**
* @covers ::fromFile
*/
public function testFromFileViolationMissingSniffShouldThrowException(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Missing `sniff` attribute in `violation`');
BaselineSetFactory::fromFile(__DIR__ . '/TestFiles/missing-sniff-baseline.xml');
}

/**
* @covers ::fromFile
*/
public function testFromFileViolationMissingSignatureShouldThrowException(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Missing `signature` attribute in `violation` in');
BaselineSetFactory::fromFile(__DIR__ . '/TestFiles/missing-signature-baseline.xml');
}

/**
* @covers ::fromFile
*/
public function testFromFileViolationMissingFileShouldThrowException(): void
{
$this->expectException(RuntimeException::class);
Expand Down
16 changes: 2 additions & 14 deletions tests/Unit/Baseline/BaselineSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@

namespace DR\CodeSnifferBaseline\Tests\Unit\Baseline;

use PHPUnit\Framework\Attributes\CoversClass;
use DR\CodeSnifferBaseline\Baseline\BaselineSet;
use DR\CodeSnifferBaseline\Baseline\ViolationBaseline;
use PHPUnit\Framework\TestCase;

/**
* Test the logic of the baseline set
* @coversDefaultClass \DR\CodeSnifferBaseline\Baseline\BaselineSet
*/
#[CoversClass(BaselineSet::class)]
class BaselineSetTest extends TestCase
{
/**
* @covers ::addEntry
* @covers ::contains
*
*/
public function testSetContainsEntry(): void
{
$set = new BaselineSet();
Expand All @@ -26,10 +22,6 @@ public function testSetContainsEntry(): void
static::assertTrue($set->contains('sniff', 'foobar', 'signature'));
}

/**
* @covers ::addEntry
* @covers ::contains
*/
public function testShouldFindEntryForIdenticalRules(): void
{
$set = new BaselineSet();
Expand All @@ -42,10 +34,6 @@ public function testShouldFindEntryForIdenticalRules(): void
static::assertFalse($set->contains('sniff', 'foo', 'signB'));
}

/**
* @covers ::addEntry
* @covers ::contains
*/
public function testShouldNotFindEntryForNonExistingRule(): void
{
$set = new BaselineSet();
Expand Down
12 changes: 2 additions & 10 deletions tests/Unit/Baseline/ViolationBaselineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@

namespace DR\CodeSnifferBaseline\Tests\Unit\Baseline;

use PHPUnit\Framework\Attributes\CoversClass;
use DR\CodeSnifferBaseline\Baseline\ViolationBaseline;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \DR\CodeSnifferBaseline\Baseline\ViolationBaseline
*/
#[CoversClass(ViolationBaseline::class)]
class ViolationBaselineTest extends TestCase
{
/**
* @covers ::__construct
* @covers ::getSniffName
* @covers ::getSignature
*/
public function testAccessors(): void
{
$violation = new ViolationBaseline('sniff', 'foobar', 'signature');
Expand All @@ -25,8 +19,6 @@ public function testAccessors(): void

/**
* Test the give file matches the baseline correctly
* @covers ::__construct
* @covers ::matches
*/
public function testMatches(): void
{
Expand Down
12 changes: 2 additions & 10 deletions tests/Unit/Plugin/BaselineHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@

namespace DR\CodeSnifferBaseline\Tests\Unit\Plugin;

use PHPUnit\Framework\Attributes\CoversClass;
use DR\CodeSnifferBaseline\Baseline\BaselineSet;
use DR\CodeSnifferBaseline\Plugin\BaselineHandler;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \DR\CodeSnifferBaseline\Plugin\BaselineHandler
* @covers ::__construct
*/
#[CoversClass(BaselineHandler::class)]
class BaselineHandlerTest extends TestCase
{
/**
* @covers ::isSuppressed
*/
public function testIsSuppressedNoBaselineShouldBeFalse(): void
{
$handler = new BaselineHandler(null);
static::assertFalse($handler->isSuppressed([], 1, 'foobar', '/path/'));
}

/**
* @covers ::isSuppressed
*/
public function testIsSuppressedWithBaseline(): void
{
$baseline = $this->createMock(BaselineSet::class);
Expand Down
Loading
Loading