Skip to content

Commit d27e7d9

Browse files
committed
Update phpunit xml
1 parent cf35f90 commit d27e7d9

File tree

9 files changed

+60
-132
lines changed

9 files changed

+60
-132
lines changed

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>

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);

tests/Unit/Plugin/PluginTest.php

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,23 @@
1111
use DR\CodeSnifferBaseline\Plugin\Plugin;
1212
use Exception;
1313
use org\bovigo\vfs\vfsStream;
14+
use PHPUnit\Framework\Attributes\CoversClass;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617
use RuntimeException;
1718

18-
/**
19-
* @coversDefaultClass \DR\CodeSnifferBaseline\Plugin\Plugin
20-
* @covers ::__construct
21-
*/
19+
#[CoversClass(Plugin::class)]
2220
class PluginTest extends TestCase
2321
{
24-
/** @var Composer|MockObject */
25-
private Composer $composer;
26-
/** @var IOInterface|MockObject */
27-
private IOInterface $stream;
22+
private Composer&MockObject $composer;
23+
private IOInterface&MockObject $stream;
2824

2925
protected function setUp(): void
3026
{
3127
$this->composer = $this->createMock(Composer::class);
3228
$this->stream = $this->createMock(IOInterface::class);
3329
}
3430

35-
/**
36-
* @covers ::getSubscribedEvents
37-
*/
3831
public function testGetSubscribedEvents(): void
3932
{
4033
$expected = [
@@ -45,10 +38,6 @@ public function testGetSubscribedEvents(): void
4538
static::assertSame($expected, Plugin::getSubscribedEvents());
4639
}
4740

48-
/**
49-
* @covers ::activate
50-
* @covers ::onPostInstall
51-
*/
5241
public function testOnPostInstallWithoutExistingFile(): void
5342
{
5443
$this->stream->expects(static::once())->method('error')->with(static::stringContains('failed to find'));
@@ -58,15 +47,18 @@ public function testOnPostInstallWithoutExistingFile(): void
5847
$plugin->onPostInstall();
5948
}
6049

61-
/**
62-
* @covers ::activate
63-
* @covers ::onPostInstall
64-
*/
6550
public function testOnPostInstallAlreadyContainsInjection(): void
6651
{
67-
$this->stream->expects(static::exactly(2))
68-
->method('info')
69-
->withConsecutive([static::stringContains('read')], [static::stringContains('is already modified')]);
52+
$matcher = static::exactly(2);
53+
$this->stream->expects($matcher)
54+
->method('info')->willReturnCallback(function (...$parameters) use ($matcher) {
55+
if ($matcher->numberOfInvocations() === 1) {
56+
$this->assertSame(static::stringContains('read'), $parameters[0]);
57+
}
58+
if ($matcher->numberOfInvocations() === 2) {
59+
$this->assertSame(static::stringContains('is already modified'), $parameters[0]);
60+
}
61+
});
7062

7163
$file = vfsStream::setup()->url() . '/File.php';
7264
file_put_contents($file, 'foobar \\' . BaselineHandler::class . 'foobar');
@@ -77,15 +69,16 @@ public function testOnPostInstallAlreadyContainsInjection(): void
7769
$plugin->onPostInstall();
7870
}
7971

80-
/**
81-
* @covers ::activate
82-
* @covers ::onPostInstall
83-
*/
8472
public function testOnPostInstallShouldErrorWhenMessageCountCantBeFound(): void
8573
{
86-
$this->stream->expects(static::once())
74+
$matcher = static::once();
75+
$this->stream->expects($matcher)
8776
->method('error')
88-
->withConsecutive([static::stringContains('unable to find `$messageCount++;`')]);
77+
->willReturnCallback(function (...$parameters) use ($matcher) {
78+
if ($matcher->numberOfInvocations() === 1) {
79+
$this->assertSame(static::stringContains('unable to find `$messageCount++;`'), $parameters[0]);
80+
}
81+
});
8982

9083
$file = vfsStream::setup()->url() . '/File.php';
9184
file_put_contents($file, 'foobar ');
@@ -95,15 +88,18 @@ public function testOnPostInstallShouldErrorWhenMessageCountCantBeFound(): void
9588
$plugin->onPostInstall();
9689
}
9790

98-
/**
99-
* @covers ::activate
100-
* @covers ::onPostInstall
101-
*/
10291
public function testOnPostInstallShouldInjectCode(): void
10392
{
104-
$this->stream->expects(static::exactly(2))
105-
->method('info')
106-
->withConsecutive([static::stringContains('read')], [static::stringContains('saved to:')]);
93+
$matcher = static::exactly(2);
94+
$this->stream->expects($matcher)
95+
->method('info')->willReturnCallback(function (...$parameters) use ($matcher) {
96+
if ($matcher->numberOfInvocations() === 1) {
97+
$this->assertSame(static::stringContains('read'), $parameters[0]);
98+
}
99+
if ($matcher->numberOfInvocations() === 2) {
100+
$this->assertSame(static::stringContains('saved to:'), $parameters[0]);
101+
}
102+
});
107103

108104
$file = vfsStream::setup()->url() . '/File.php';
109105
file_put_contents($file, 'foobar $messageCount++; foobar');
@@ -116,7 +112,6 @@ public function testOnPostInstallShouldInjectCode(): void
116112
}
117113

118114
/**
119-
* @covers ::run
120115
* @throws Exception
121116
*/
122117
public function testRun(): void

tests/Unit/Reports/BaselineTest.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,26 @@
77
use DR\CodeSnifferBaseline\Util\CodeSignature;
88
use PHP_CodeSniffer\Config;
99
use PHP_CodeSniffer\Files\File;
10+
use PHPUnit\Framework\Attributes\CoversClass;
1011
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\TestCase;
1213

13-
/**
14-
* @coversDefaultClass \DR\CodeSnifferBaseline\Reports\Baseline
15-
*/
14+
#[CoversClass(Baseline::class)]
1615
class BaselineTest extends TestCase
1716
{
18-
/** @var File|MockObject */
19-
private File $file;
17+
private File&MockObject $file;
2018

2119
protected function setUp(): void
2220
{
2321
$this->file = $this->createMock(File::class);
2422
}
2523

26-
/**
27-
* @covers ::generateFileReport
28-
*/
2924
public function testGenerateFileReportEmptyShouldReturnFalse(): void
3025
{
3126
$report = new Baseline();
3227
static::assertFalse($report->generateFileReport(['errors' => 0, 'warnings' => 0, 'filename' => 'foo', 'messages' => []], $this->file));
3328
}
3429

35-
/**
36-
* @covers ::generateFileReport
37-
*/
3830
public function testGenerateFileReportShouldPrintReport(): void
3931
{
4032
$reportData = [
@@ -60,9 +52,6 @@ public function testGenerateFileReportShouldPrintReport(): void
6052
static::assertSame('<violation file="/test/foobar.txt" sniff="MySniff" signature="' . $signature . '"/>' . PHP_EOL, $result);
6153
}
6254

63-
/**
64-
* @covers ::generate
65-
*/
6655
public function testGenerate(): void
6756
{
6857
$expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . PHP_EOL;

0 commit comments

Comments
 (0)