Skip to content

Commit 2943a31

Browse files
authored
Make test compatible with latest PHPUnit (#68)
1 parent 5c4de72 commit 2943a31

25 files changed

+127
-153
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"require-dev": {
2828
"phpunit/phpunit": "^10.0|^11.0|^12.0",
2929
"phpspec/prophecy-phpunit": "^2.0",
30-
"squizlabs/php_codesniffer": "^3.6",
30+
"squizlabs/php_codesniffer": "^4.0",
3131
"slevomat/coding-standard": "^8.0",
3232
"phpstan/phpstan": "^2.0",
3333
"phpstan/extension-installer": "^1.1",

tests/Unit/Option/BooleanTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TH\Maybe\Tests\Unit\Option;
44

55
use PHPUnit\Framework\Assert;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use TH\Maybe\Option;
89
use TH\Maybe\Tests\Provider;
@@ -12,24 +13,24 @@ final class BooleanTest extends TestCase
1213
use Provider\Options;
1314

1415
/**
15-
* @dataProvider andMatrix
1616
* @template T
1717
* @param Option<T> $left
1818
* @param Option<T> $right
1919
* @param Option<T> $expected
20-
*/
20+
*/
21+
#[DataProvider('andMatrix')]
2122
public function testAnd(Option $left, Option $right, Option $expected): void
2223
{
2324
Assert::assertSame($expected, $left->and($right));
2425
}
2526

2627
/**
27-
* @dataProvider andMatrix
2828
* @template T
2929
* @param Option<T> $left
3030
* @param Option<T> $right
3131
* @param Option<T> $expected
32-
*/
32+
*/
33+
#[DataProvider('andMatrix')]
3334
public function testAndThen(Option $left, Option $right, Option $expected): void
3435
{
3536
$calls = [];
@@ -47,12 +48,12 @@ public function testAndThen(Option $left, Option $right, Option $expected): void
4748
}
4849

4950
/**
50-
* @dataProvider orMatrix
5151
* @template T
5252
* @param Option<T> $left
5353
* @param Option<T> $right
5454
* @param Option<T> $expected
55-
*/
55+
*/
56+
#[DataProvider('orMatrix')]
5657
public function testOrElse(Option $left, Option $right, Option $expected): void
5758
{
5859
$calls = 0;
@@ -70,24 +71,24 @@ public function testOrElse(Option $left, Option $right, Option $expected): void
7071
}
7172

7273
/**
73-
* @dataProvider orMatrix
7474
* @template T
7575
* @param Option<T> $left
7676
* @param Option<T> $right
7777
* @param Option<T> $expected
78-
*/
78+
*/
79+
#[DataProvider('orMatrix')]
7980
public function testOr(Option $left, Option $right, Option $expected): void
8081
{
8182
Assert::assertSame($expected, $left->or($right));
8283
}
8384

8485
/**
85-
* @dataProvider xorMatrix
8686
* @template T
8787
* @param Option<T> $left
8888
* @param Option<T> $right
8989
* @param Option<T> $expected
90-
*/
90+
*/
91+
#[DataProvider('xorMatrix')]
9192
public function testXor(Option $left, Option $right, Option $expected): void
9293
{
9394
Assert::assertEquals($expected, $left->xor($right));

tests/Unit/Option/ContainsTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TH\Maybe\Tests\Unit\Option;
44

55
use PHPUnit\Framework\Assert;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use TH\Maybe\Option;
89
use TH\Maybe\Tests\Provider;
@@ -12,9 +13,9 @@ final class ContainsTest extends TestCase
1213
use Provider\Values;
1314

1415
/**
15-
* @dataProvider containsMatrix
1616
* @param Option<mixed> $option
17-
*/
17+
*/
18+
#[DataProvider('containsMatrix')]
1819
public function testContains(Option $option, mixed $value, bool $expect, bool $strict = true): void
1920
{
2021
Assert::assertSame($expect, $option->contains($value, strict: $strict));

tests/Unit/Option/ConvertToResultTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace TH\Maybe\Tests\Unit\Option;
44

5+
use PHPUnit\Framework\Attributes\DataProvider;
56
use PHPUnit\Framework\TestCase;
67
use TH\Maybe\Option;
78
use TH\Maybe\Result;
@@ -13,10 +14,10 @@ final class ConvertToResultTest extends TestCase
1314
use Provider\Transpose;
1415

1516
/**
16-
* @dataProvider okOrMatrix
1717
* @param Option<mixed> $option
1818
* @param Result<mixed, mixed> $expected
19-
*/
19+
*/
20+
#[DataProvider('okOrMatrix')]
2021
public function testOkOr(Option $option, mixed $err, Result $expected): void
2122
{
2223
Assert::assertEquals($expected, $result = $option->okOr($err));
@@ -26,11 +27,11 @@ public function testOkOr(Option $option, mixed $err, Result $expected): void
2627
}
2728

2829
/**
29-
* @dataProvider okOrMatrix
3030
* @param Option<mixed> $option
3131
* @param Result<mixed, mixed> $expected
32-
*/
33-
public function testOkOrElse(Option $option, mixed $err, Result $expected, int $expectedCalls): void
32+
*/
33+
#[DataProvider('okOrMatrix')]
34+
public function testOkOrElse(Option $option, mixed $err, Result $expected): void
3435
{
3536
$calls = 0;
3637

@@ -43,7 +44,7 @@ public function testOkOrElse(Option $option, mixed $err, Result $expected, int $
4344
Assert::assertResultNotUsed($expected);
4445
Assert::assertResultNotUsed($result);
4546

46-
Assert::assertSame($expectedCalls, $calls);
47+
Assert::assertSame($result->isErr() ? 1 : 0, $calls);
4748
}
4849

4950
/**
@@ -55,22 +56,20 @@ public static function okOrMatrix(): iterable
5556
Option\none(),
5657
"Don't panic !",
5758
Result\err("Don't panic !"),
58-
1,
5959
];
6060

6161
yield "some" => [
6262
Option\some(42),
6363
"Don't panic !",
6464
Result\ok(42),
65-
0,
6665
];
6766
}
6867

6968
/**
70-
* @dataProvider transposeMatrix
7169
* @param Option<Result<mixed, mixed>> $option
7270
* @param Result<mixed, mixed> $expected
73-
*/
71+
*/
72+
#[DataProvider('transposeMatrix')]
7473
public function testTranspose(Option $option, Result $expected): void
7574
{
7675
Assert::assertEquals($expected, $result = Option\transpose($option));

tests/Unit/Option/FilterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
namespace TH\Maybe\Tests\Unit\Option;
44

55
use PHPUnit\Framework\Assert;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use TH\Maybe\Option;
89

910
final class FilterTest extends TestCase
1011
{
1112
/**
12-
* @dataProvider filterMatrix
1313
* @template T
1414
* @param Option<T> $option
1515
* @param array<T> $expectedCalls
16-
*/
16+
*/
17+
#[DataProvider('filterMatrix')]
1718
public function testFilter(Option $option, bool $filterResult, bool $expectNone, array $expectedCalls): void
1819
{
1920
$calls = [];

tests/Unit/Option/FlattenTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
namespace TH\Maybe\Tests\Unit\Option;
44

55
use PHPUnit\Framework\Assert;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use TH\Maybe\Option;
89

910
final class FlattenTest extends TestCase
1011
{
1112
/**
12-
* @dataProvider flattenMatrix
1313
* @param Option<mixed> $expected
1414
* @param Option<Option<mixed>> $option
15-
*/
15+
*/
16+
#[DataProvider('flattenMatrix')]
1617
public function testFlatten(Option $expected, Option $option): void
1718
{
1819
Assert::assertEquals($expected, Option\flatten($option));

tests/Unit/Option/FromValueTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TH\Maybe\Tests\Unit\Option;
44

55
use PHPUnit\Framework\Assert;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use TH\Maybe\Option;
89
use TH\Maybe\Tests\Provider;
@@ -12,9 +13,9 @@ final class FromValueTest extends TestCase
1213
use Provider\Options;
1314

1415
/**
15-
* @dataProvider fromValueMatrix
1616
* @param Option<mixed> $expected
17-
*/
17+
*/
18+
#[DataProvider('fromValueMatrix')]
1819
public function testFromValue(Option $expected, mixed $value, mixed $noneValue, bool $strict = true): void
1920
{
2021
Assert::assertEquals($expected, Option\fromValue($value, $noneValue, strict: $strict));

tests/Unit/Option/InspectTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TH\Maybe\Tests\Unit\Option;
44

55
use PHPUnit\Framework\Assert;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use TH\Maybe\Option;
89
use TH\Maybe\Tests\Provider;
@@ -11,9 +12,7 @@ final class InspectTest extends TestCase
1112
{
1213
use Provider\Values;
1314

14-
/**
15-
* @dataProvider values
16-
*/
15+
#[DataProvider('values')]
1716
public function testInspectSome(mixed $value): void
1817
{
1918
$option = Option\some($value);

tests/Unit/Option/IsTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace TH\Maybe\Tests\Unit\Option;
44

5+
use PHPUnit\Framework\Attributes\DataProvider;
56
use PHPUnit\Framework\TestCase;
67
use TH\Maybe\Option;
78
use TH\Maybe\Tests\Assert;
@@ -11,9 +12,7 @@ final class IsTest extends TestCase
1112
{
1213
use Provider\Values;
1314

14-
/**
15-
* @dataProvider values
16-
*/
15+
#[DataProvider('values')]
1716
public function testIsSome(mixed $value): void
1817
{
1918
$option = Option\some($value);
@@ -25,9 +24,7 @@ public function testIsSome(mixed $value): void
2524
Assert::assertFalse($option->isSome());
2625
}
2726

28-
/**
29-
* @dataProvider values
30-
*/
27+
#[DataProvider('values')]
3128
public function testIsNone(mixed $value): void
3229
{
3330
$option = Option\some($value);
@@ -39,9 +36,7 @@ public function testIsNone(mixed $value): void
3936
Assert::assertTrue($option->isNone());
4037
}
4138

42-
/**
43-
* @dataProvider values
44-
*/
39+
#[DataProvider('values')]
4540
public function testIsSomeAnd(mixed $value): void
4641
{
4742
$option = Option\some($value);

tests/Unit/Option/MapTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
namespace TH\Maybe\Tests\Unit\Option;
44

55
use PHPUnit\Framework\Assert;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use TH\Maybe\Option;
89

910
final class MapTest extends TestCase
1011
{
1112
/**
12-
* @dataProvider mapMatrix
1313
* @template T
1414
* @template U
1515
* @param Option<T> $option
1616
* @param U $mapResult
1717
* @param Option<U> $expected
1818
* @param array<T> $expectedCalls
19-
*/
19+
*/
20+
#[DataProvider('mapMatrix')]
2021
public function testMap(Option $option, mixed $mapResult, Option $expected, array $expectedCalls): void
2122
{
2223
$calls = [];
@@ -59,15 +60,15 @@ public static function mapMatrix(): iterable
5960
}
6061

6162
/**
62-
* @dataProvider mapOrMatrix
6363
* @template T
6464
* @template U
6565
* @param Option<T> $option
6666
* @param U $mapResult
6767
* @param U $default
6868
* @param U $expected
6969
* @param array<T> $expectedCalls
70-
*/
70+
*/
71+
#[DataProvider('mapOrMatrix')]
7172
public function testMapOr(
7273
Option $option,
7374
mixed $mapResult,

0 commit comments

Comments
 (0)