Skip to content

Commit 12c1457

Browse files
committed
Upgrade "phpunit/phpunit"
This commit also replaces PHPUnit annotations with attributes. Signed-off-by: Henrique Moody <[email protected]>
1 parent 9a19b23 commit 12c1457

File tree

167 files changed

+1017
-1360
lines changed

Some content is hidden

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

167 files changed

+1017
-1360
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.couscous/
22
.iso-codes-cache/
33
.phpcs.cache
4-
.phpunit.result.cache
4+
.phpunit.cache/
55
composer.lock
66
Makefile
77
phpcs.xml

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ declare(strict_types=1);
132132

133133
namespace Respect\Validation\Rules;
134134

135+
use PHPUnit\Framework\Attributes\CoversClass;
136+
use PHPUnit\Framework\Attributes\Group;
135137
use Respect\Validation\Test\RuleTestCase;
136138

137-
/**
138-
* @group rule
139-
* @covers \Respect\Validation\Rules\HelloWorld
140-
*/
139+
#[Group('rule')]
140+
#[CoversClass(HelloWorld::class)]
141141
final class HelloWorldTest extends RuleTestCase
142142
{
143143
/**

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"phpstan/phpstan": "^1.9",
3131
"phpstan/phpstan-deprecation-rules": "^1.1",
3232
"phpstan/phpstan-phpunit": "^1.3",
33-
"phpunit/phpunit": "^9.6",
33+
"phpunit/phpunit": "^10.5",
3434
"psr/http-message": "^1.0",
3535
"respect/coding-standard": "^4.0",
3636
"squizlabs/php_codesniffer": "^3.8"

phpunit.xml.dist

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<?xml version="1.0"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
backupGlobals="false"
6-
backupStaticAttributes="false"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
106
processIsolation="false"
117
stopOnFailure="false"
12-
verbose="true">
8+
cacheDirectory=".phpunit.cache"
9+
backupStaticProperties="false">
1310
<testsuites>
1411
<testsuite name="unit">
1512
<directory suffix="Test.php">tests/unit/</directory>
@@ -18,9 +15,9 @@
1815
<directory suffix=".phpt">tests/integration/</directory>
1916
</testsuite>
2017
</testsuites>
21-
<coverage processUncoveredFiles="true" ignoreDeprecatedCodeUnits="true">
18+
<source>
2219
<include>
23-
<directory suffix=".php">library/</directory>
20+
<directory suffix=".php">library/</directory>
2421
</include>
25-
</coverage>
22+
</source>
2623
</phpunit>

tests/library/RuleTestCase.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace Respect\Validation\Test;
1111

12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\Attributes\Test;
1214
use Respect\Validation\Validatable;
1315

1416
use function implode;
@@ -17,9 +19,6 @@
1719
use function Respect\Stringifier\stringify;
1820
use function sprintf;
1921

20-
/**
21-
* @since 1.0.0
22-
*/
2322
abstract class RuleTestCase extends TestCase
2423
{
2524
/**
@@ -29,7 +28,7 @@ abstract class RuleTestCase extends TestCase
2928
* as the first element and an input in which the validation SHOULD pass.
3029
*
3130
* @api
32-
* @return mixed[][]
31+
* @return array<string|int, array{Validatable, mixed}>
3332
*/
3433
abstract public static function providerForValidInput(): array;
3534

@@ -40,23 +39,19 @@ abstract public static function providerForValidInput(): array;
4039
* as the first element and an input in which the validation SHOULD NOT pass.
4140
*
4241
* @api
43-
* @return mixed[][]
42+
* @return array<string|int, array{Validatable, mixed}>
4443
*/
4544
abstract public static function providerForInvalidInput(): array;
4645

47-
/**
48-
* @test
49-
* @dataProvider providerForValidInput
50-
*/
46+
#[Test]
47+
#[DataProvider('providerForValidInput')]
5148
public function shouldValidateValidInput(Validatable $validator, mixed $input): void
5249
{
5350
self::assertValidInput($validator, $input);
5451
}
5552

56-
/**
57-
* @test
58-
* @dataProvider providerForInvalidInput
59-
*/
53+
#[Test]
54+
#[DataProvider('providerForInvalidInput')]
6055
public function shouldValidateInvalidInput(Validatable $validator, mixed $input): void
6156
{
6257
self::assertInvalidInput($validator, $input);

tests/unit/Exceptions/CheckExceptionsTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@
1010
namespace Respect\Validation\Exceptions;
1111

1212
use DirectoryIterator;
13+
use PHPUnit\Framework\Attributes\CoversNothing;
14+
use PHPUnit\Framework\Attributes\DataProvider;
15+
use PHPUnit\Framework\Attributes\Test;
1316
use ReflectionClass;
1417
use Respect\Validation\Test\TestCase;
1518

1619
use function class_exists;
1720
use function mb_substr;
1821
use function sprintf;
1922

20-
/**
21-
* @coversNothing
22-
*/
23+
#[CoversNothing]
2324
final class CheckExceptionsTest extends TestCase
2425
{
25-
/**
26-
* @dataProvider provideListOfRuleNames
27-
* @test
28-
*/
26+
#[Test]
27+
#[DataProvider('provideListOfRuleNames')]
2928
public function ruleHasAnExceptionWhichHasValidApi(string $ruleName): void
3029
{
3130
$exceptionClass = 'Respect\\Validation\\Exceptions\\' . $ruleName . 'Exception';

tests/unit/Exceptions/NestedValidationExceptionTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010
namespace Respect\Validation\Exceptions;
1111

12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\Attributes\Group;
14+
use PHPUnit\Framework\Attributes\Test;
1215
use Respect\Validation\Message\Formatter;
1316
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
1417
use Respect\Validation\Test\TestCase;
1518

16-
/**
17-
* @covers \Respect\Validation\Exceptions\NestedValidationException
18-
*/
19+
#[Group('core')]
20+
#[CoversClass(NestedValidationException::class)]
1921
final class NestedValidationExceptionTest extends TestCase
2022
{
21-
/**
22-
* @test
23-
*/
23+
#[Test]
2424
public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
2525
{
2626
$composite = new AttributeException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
@@ -30,9 +30,7 @@ public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
3030
self::assertContainsOnly(IntValException::class, $composite->getChildren());
3131
}
3232

33-
/**
34-
* @test
35-
*/
33+
#[Test]
3634
public function addingTheSameInstanceShouldAddJustOneSingleReference(): void
3735
{
3836
$composite = new AttributeException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));

tests/unit/Exceptions/ValidationExceptionTest.php

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,28 @@
99

1010
namespace Respect\Validation\Exceptions;
1111

12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\Attributes\Group;
14+
use PHPUnit\Framework\Attributes\Test;
1215
use Respect\Validation\Message\Formatter;
1316
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
1417
use Respect\Validation\Test\TestCase;
1518

1619
use function trim;
1720

18-
/**
19-
* @group core
20-
* @covers \Respect\Validation\Exceptions\ValidationException
21-
*/
21+
#[Group('core')]
22+
#[CoversClass(ValidationException::class)]
2223
final class ValidationExceptionTest extends TestCase
2324
{
24-
/**
25-
* @test
26-
*/
25+
#[Test]
2726
public function itShouldImplementException(): void
2827
{
2928
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
3029

3130
self::assertInstanceOf(Exception::class, $sut);
3231
}
3332

34-
/**
35-
* @test
36-
*/
33+
#[Test]
3734
public function itShouldRetrieveId(): void
3835
{
3936
$id = 'my id';
@@ -42,9 +39,7 @@ public function itShouldRetrieveId(): void
4239
self::assertSame($id, $sut->getId());
4340
}
4441

45-
/**
46-
* @test
47-
*/
42+
#[Test]
4843
public function itShouldRetrieveParams(): void
4944
{
5045
$params = ['foo' => true, 'bar' => 23];
@@ -54,9 +49,7 @@ public function itShouldRetrieveParams(): void
5449
self::assertSame($params, $sut->getParams());
5550
}
5651

57-
/**
58-
* @test
59-
*/
52+
#[Test]
6053
public function itShouldRetrieveOneSingleParameter(): void
6154
{
6255
$name = 'any name';
@@ -67,29 +60,23 @@ public function itShouldRetrieveOneSingleParameter(): void
6760
self::assertSame($value, $sut->getParam($name));
6861
}
6962

70-
/**
71-
* @test
72-
*/
63+
#[Test]
7364
public function itShouldReturnNullWhenParameterCanNotBeFound(): void
7465
{
7566
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
7667

7768
self::assertNull($sut->getParam('foo'));
7869
}
7970

80-
/**
81-
* @test
82-
*/
71+
#[Test]
8372
public function itShouldHaveTemplateByDefault(): void
8473
{
8574
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
8675

8776
self::assertSame('"input" must be valid', $sut->getMessage());
8877
}
8978

90-
/**
91-
* @test
92-
*/
79+
#[Test]
9380
public function itShouldUpdateMode(): void
9481
{
9582
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
@@ -98,9 +85,7 @@ public function itShouldUpdateMode(): void
9885
self::assertSame('"input" must not be valid', $sut->getMessage());
9986
}
10087

101-
/**
102-
* @test
103-
*/
88+
#[Test]
10489
public function itShouldUpdateTemplate(): void
10590
{
10691
$template = 'This is my new template';
@@ -111,9 +96,7 @@ public function itShouldUpdateTemplate(): void
11196
self::assertEquals($template, $sut->getMessage());
11297
}
11398

114-
/**
115-
* @test
116-
*/
99+
#[Test]
117100
public function itShouldTellWhenHasAsCustomUpdateTemplate(): void
118101
{
119102
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
@@ -125,9 +108,7 @@ public function itShouldTellWhenHasAsCustomUpdateTemplate(): void
125108
self::assertTrue($sut->hasCustomTemplate());
126109
}
127110

128-
/**
129-
* @test
130-
*/
111+
#[Test]
131112
public function itShouldUseFormatter(): void
132113
{
133114
$template = ' This is my new template ';
@@ -139,9 +120,7 @@ public function itShouldUseFormatter(): void
139120
self::assertEquals($expected, $sut->getMessage());
140121
}
141122

142-
/**
143-
* @test
144-
*/
123+
#[Test]
145124
public function itShouldReplacePlaceholders(): void
146125
{
147126
$sut = new ValidationException('foo', 'id', ['bar' => 1, 'baz' => 2], $this->createFormatter());
@@ -153,9 +132,7 @@ public function itShouldReplacePlaceholders(): void
153132
);
154133
}
155134

156-
/**
157-
* @test
158-
*/
135+
#[Test]
159136
public function itShouldKeepPlaceholdersThatCanNotReplace(): void
160137
{
161138
$sut = new ValidationException('foo', 'id', ['foo' => 1], $this->createFormatter());
@@ -167,9 +144,7 @@ public function itShouldKeepPlaceholdersThatCanNotReplace(): void
167144
);
168145
}
169146

170-
/**
171-
* @test
172-
*/
147+
#[Test]
173148
public function itShouldUpdateParams(): void
174149
{
175150
$sut = new ValidationException('input', 'id', ['foo' => 1], $this->createFormatter());
@@ -179,9 +154,7 @@ public function itShouldUpdateParams(): void
179154
self::assertEquals('2', $sut->getMessage());
180155
}
181156

182-
/**
183-
* @test
184-
*/
157+
#[Test]
185158
public function itShouldConvertToString(): void
186159
{
187160
$sut = new ValidationException('input', 'id', [], $this->createFormatter());

0 commit comments

Comments
 (0)