diff --git a/composer.json b/composer.json index 0d98fa2..56c6594 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "require-dev": { "phpunit/phpunit": "^10.0|^11.0|^12.0", "phpspec/prophecy-phpunit": "^2.0", - "squizlabs/php_codesniffer": "^3.6", + "squizlabs/php_codesniffer": "^4.0", "slevomat/coding-standard": "^8.0", "phpstan/phpstan": "^2.0", "phpstan/extension-installer": "^1.1", diff --git a/tests/Unit/Option/BooleanTest.php b/tests/Unit/Option/BooleanTest.php index 4c460eb..2545288 100644 --- a/tests/Unit/Option/BooleanTest.php +++ b/tests/Unit/Option/BooleanTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Provider; @@ -12,24 +13,24 @@ final class BooleanTest extends TestCase use Provider\Options; /** - * @dataProvider andMatrix * @template T * @param Option $left * @param Option $right * @param Option $expected - */ + */ + #[DataProvider('andMatrix')] public function testAnd(Option $left, Option $right, Option $expected): void { Assert::assertSame($expected, $left->and($right)); } /** - * @dataProvider andMatrix * @template T * @param Option $left * @param Option $right * @param Option $expected - */ + */ + #[DataProvider('andMatrix')] public function testAndThen(Option $left, Option $right, Option $expected): void { $calls = []; @@ -47,12 +48,12 @@ public function testAndThen(Option $left, Option $right, Option $expected): void } /** - * @dataProvider orMatrix * @template T * @param Option $left * @param Option $right * @param Option $expected - */ + */ + #[DataProvider('orMatrix')] public function testOrElse(Option $left, Option $right, Option $expected): void { $calls = 0; @@ -70,24 +71,24 @@ public function testOrElse(Option $left, Option $right, Option $expected): void } /** - * @dataProvider orMatrix * @template T * @param Option $left * @param Option $right * @param Option $expected - */ + */ + #[DataProvider('orMatrix')] public function testOr(Option $left, Option $right, Option $expected): void { Assert::assertSame($expected, $left->or($right)); } /** - * @dataProvider xorMatrix * @template T * @param Option $left * @param Option $right * @param Option $expected - */ + */ + #[DataProvider('xorMatrix')] public function testXor(Option $left, Option $right, Option $expected): void { Assert::assertEquals($expected, $left->xor($right)); diff --git a/tests/Unit/Option/ContainsTest.php b/tests/Unit/Option/ContainsTest.php index 1f32d83..4507f79 100644 --- a/tests/Unit/Option/ContainsTest.php +++ b/tests/Unit/Option/ContainsTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Provider; @@ -12,9 +13,9 @@ final class ContainsTest extends TestCase use Provider\Values; /** - * @dataProvider containsMatrix * @param Option $option - */ + */ + #[DataProvider('containsMatrix')] public function testContains(Option $option, mixed $value, bool $expect, bool $strict = true): void { Assert::assertSame($expect, $option->contains($value, strict: $strict)); diff --git a/tests/Unit/Option/ConvertToResultTest.php b/tests/Unit/Option/ConvertToResultTest.php index f637db2..6976250 100644 --- a/tests/Unit/Option/ConvertToResultTest.php +++ b/tests/Unit/Option/ConvertToResultTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Option; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Result; @@ -13,10 +14,10 @@ final class ConvertToResultTest extends TestCase use Provider\Transpose; /** - * @dataProvider okOrMatrix * @param Option $option * @param Result $expected - */ + */ + #[DataProvider('okOrMatrix')] public function testOkOr(Option $option, mixed $err, Result $expected): void { Assert::assertEquals($expected, $result = $option->okOr($err)); @@ -26,11 +27,11 @@ public function testOkOr(Option $option, mixed $err, Result $expected): void } /** - * @dataProvider okOrMatrix * @param Option $option * @param Result $expected - */ - public function testOkOrElse(Option $option, mixed $err, Result $expected, int $expectedCalls): void + */ + #[DataProvider('okOrMatrix')] + public function testOkOrElse(Option $option, mixed $err, Result $expected): void { $calls = 0; @@ -43,7 +44,7 @@ public function testOkOrElse(Option $option, mixed $err, Result $expected, int $ Assert::assertResultNotUsed($expected); Assert::assertResultNotUsed($result); - Assert::assertSame($expectedCalls, $calls); + Assert::assertSame($result->isErr() ? 1 : 0, $calls); } /** @@ -55,22 +56,20 @@ public static function okOrMatrix(): iterable Option\none(), "Don't panic !", Result\err("Don't panic !"), - 1, ]; yield "some" => [ Option\some(42), "Don't panic !", Result\ok(42), - 0, ]; } /** - * @dataProvider transposeMatrix * @param Option> $option * @param Result $expected - */ + */ + #[DataProvider('transposeMatrix')] public function testTranspose(Option $option, Result $expected): void { Assert::assertEquals($expected, $result = Option\transpose($option)); diff --git a/tests/Unit/Option/FilterTest.php b/tests/Unit/Option/FilterTest.php index 853a1a4..9cf96a8 100644 --- a/tests/Unit/Option/FilterTest.php +++ b/tests/Unit/Option/FilterTest.php @@ -3,17 +3,18 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; final class FilterTest extends TestCase { /** - * @dataProvider filterMatrix * @template T * @param Option $option * @param array $expectedCalls - */ + */ + #[DataProvider('filterMatrix')] public function testFilter(Option $option, bool $filterResult, bool $expectNone, array $expectedCalls): void { $calls = []; diff --git a/tests/Unit/Option/FlattenTest.php b/tests/Unit/Option/FlattenTest.php index e6989c0..2098129 100644 --- a/tests/Unit/Option/FlattenTest.php +++ b/tests/Unit/Option/FlattenTest.php @@ -3,16 +3,17 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; final class FlattenTest extends TestCase { /** - * @dataProvider flattenMatrix * @param Option $expected * @param Option> $option - */ + */ + #[DataProvider('flattenMatrix')] public function testFlatten(Option $expected, Option $option): void { Assert::assertEquals($expected, Option\flatten($option)); diff --git a/tests/Unit/Option/FromValueTest.php b/tests/Unit/Option/FromValueTest.php index 83d35c8..9f9863e 100644 --- a/tests/Unit/Option/FromValueTest.php +++ b/tests/Unit/Option/FromValueTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Provider; @@ -12,9 +13,9 @@ final class FromValueTest extends TestCase use Provider\Options; /** - * @dataProvider fromValueMatrix * @param Option $expected - */ + */ + #[DataProvider('fromValueMatrix')] public function testFromValue(Option $expected, mixed $value, mixed $noneValue, bool $strict = true): void { Assert::assertEquals($expected, Option\fromValue($value, $noneValue, strict: $strict)); diff --git a/tests/Unit/Option/InspectTest.php b/tests/Unit/Option/InspectTest.php index 5d45aba..97b89b0 100644 --- a/tests/Unit/Option/InspectTest.php +++ b/tests/Unit/Option/InspectTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Provider; @@ -11,9 +12,7 @@ final class InspectTest extends TestCase { use Provider\Values; - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testInspectSome(mixed $value): void { $option = Option\some($value); diff --git a/tests/Unit/Option/IsTest.php b/tests/Unit/Option/IsTest.php index d0666b4..c5e9945 100644 --- a/tests/Unit/Option/IsTest.php +++ b/tests/Unit/Option/IsTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Option; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Assert; @@ -11,9 +12,7 @@ final class IsTest extends TestCase { use Provider\Values; - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testIsSome(mixed $value): void { $option = Option\some($value); @@ -25,9 +24,7 @@ public function testIsSome(mixed $value): void Assert::assertFalse($option->isSome()); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testIsNone(mixed $value): void { $option = Option\some($value); @@ -39,9 +36,7 @@ public function testIsNone(mixed $value): void Assert::assertTrue($option->isNone()); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testIsSomeAnd(mixed $value): void { $option = Option\some($value); diff --git a/tests/Unit/Option/MapTest.php b/tests/Unit/Option/MapTest.php index a83e03b..b9c3361 100644 --- a/tests/Unit/Option/MapTest.php +++ b/tests/Unit/Option/MapTest.php @@ -3,20 +3,21 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; final class MapTest extends TestCase { /** - * @dataProvider mapMatrix * @template T * @template U * @param Option $option * @param U $mapResult * @param Option $expected * @param array $expectedCalls - */ + */ + #[DataProvider('mapMatrix')] public function testMap(Option $option, mixed $mapResult, Option $expected, array $expectedCalls): void { $calls = []; @@ -59,7 +60,6 @@ public static function mapMatrix(): iterable } /** - * @dataProvider mapOrMatrix * @template T * @template U * @param Option $option @@ -67,7 +67,8 @@ public static function mapMatrix(): iterable * @param U $default * @param U $expected * @param array $expectedCalls - */ + */ + #[DataProvider('mapOrMatrix')] public function testMapOr( Option $option, mixed $mapResult, diff --git a/tests/Unit/Option/OfTest.php b/tests/Unit/Option/OfTest.php index e055ed2..6e0cc72 100644 --- a/tests/Unit/Option/OfTest.php +++ b/tests/Unit/Option/OfTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Provider; @@ -12,18 +13,18 @@ final class OfTest extends TestCase use Provider\Options; /** - * @dataProvider fromValueMatrix * @param Option $expected - */ + */ + #[DataProvider('fromValueMatrix')] public function testOf(Option $expected, mixed $value, mixed $noneValue, bool $strict = true): void { Assert::assertEquals($expected, Option\of(static fn () => $value, $noneValue, strict: $strict)); } /** - * @dataProvider fromValueMatrix * @param Option $expected - */ + */ + #[DataProvider('fromValueMatrix')] public function testTryOf(Option $expected, mixed $value, mixed $noneValue, bool $strict = true): void { Assert::assertEquals($expected, Option\tryOf(static fn () => $value, $noneValue, strict: $strict)); diff --git a/tests/Unit/Option/SerializationTest.php b/tests/Unit/Option/SerializationTest.php index 9b96717..38af24f 100644 --- a/tests/Unit/Option/SerializationTest.php +++ b/tests/Unit/Option/SerializationTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Provider; @@ -19,9 +20,7 @@ public function testWithNone(): void $this->testSerializableOption($none); } - /** - * @dataProvider serializableValues - */ + #[DataProvider('serializableValues')] public function testWithSomeValidValues(mixed $value): void { $this->testSerializableOption(Option\some($value)); diff --git a/tests/Unit/Option/UnwrapTest.php b/tests/Unit/Option/UnwrapTest.php index ce0de3b..5c2c14a 100644 --- a/tests/Unit/Option/UnwrapTest.php +++ b/tests/Unit/Option/UnwrapTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Tests\Provider; @@ -18,9 +19,7 @@ public function testExpectNone(): void Option\none()->expect("This should fail"); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testExpectSome(mixed $value): void { Assert::assertSame($value, Option\some($value)->expect("This should succeed")); @@ -33,41 +32,31 @@ public function testUnwrapNone(): void Option\none()->unwrap(); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapSome(mixed $value): void { Assert::assertSame($value, Option\some($value)->unwrap()); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrNone(mixed $value): void { Assert::assertSame($value, Option\none()->unwrapOr($value)); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrSome(mixed $value): void { Assert::assertSame($value, Option\some($value)->unwrapOr(false)); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrElseNone(mixed $value): void { Assert::assertSame($value, Option\none()->unwrapOrElse(static fn () => $value)); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrElseSome(mixed $value): void { Assert::assertSame($value, Option\some($value)->unwrapOrElse(static fn () => false)); diff --git a/tests/Unit/Option/ZipTest.php b/tests/Unit/Option/ZipTest.php index 714391b..ba69340 100644 --- a/tests/Unit/Option/ZipTest.php +++ b/tests/Unit/Option/ZipTest.php @@ -3,19 +3,20 @@ namespace TH\Maybe\Tests\Unit\Option; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; final class ZipTest extends TestCase { /** - * @dataProvider zipMatrix * @template L * @template R * @param Option $left * @param Option $right * @param Option $expected - */ + */ + #[DataProvider('zipMatrix')] public function testZip(Option $left, Option $right, Option $expected): void { Assert::assertEquals($expected, $left->zip($right)); @@ -56,13 +57,13 @@ public static function zipMatrix(): iterable } /** - * @dataProvider unzipMatrix * @template L * @template R * @param Option $zipped * @param Option $left * @param Option $right - */ + */ + #[DataProvider('unzipMatrix')] public function testUnzip(Option $zipped, Option $left, Option $right): void { Assert::assertEquals([$left, $right], Option\unzip($zipped)); diff --git a/tests/Unit/Result/BooleanTest.php b/tests/Unit/Result/BooleanTest.php index 22470f1..16cb0cd 100644 --- a/tests/Unit/Result/BooleanTest.php +++ b/tests/Unit/Result/BooleanTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -12,12 +13,12 @@ final class BooleanTest extends TestCase use Provider\Results; /** - * @dataProvider andMatrix * @template T * @param Result $left * @param Result $right * @param Result $expected - */ + */ + #[DataProvider('andMatrix')] public function testAnd(Result $left, Result $right, Result $expected): void { Assert::assertEquals($expected, $result = $left->and($right)); @@ -29,12 +30,12 @@ public function testAnd(Result $left, Result $right, Result $expected): void } /** - * @dataProvider andMatrix * @template T * @param Result $left * @param Result $right * @param Result $expected - */ + */ + #[DataProvider('andMatrix')] public function testAndThen(Result $left, Result $right, Result $expected): void { $calls = []; @@ -64,12 +65,12 @@ static function (mixed $value) use ($right, &$calls): mixed { } /** - * @dataProvider orMatrix * @template T * @param Result $left * @param Result $right * @param Result $expected - */ + */ + #[DataProvider('orMatrix')] public function testOrElse(Result $left, Result $right, Result $expected): void { $calls = 0; @@ -97,12 +98,12 @@ public function testOrElse(Result $left, Result $right, Result $expected): void } /** - * @dataProvider orMatrix * @template T * @param Result $left * @param Result $right * @param Result $expected - */ + */ + #[DataProvider('orMatrix')] public function testOr(Result $left, Result $right, Result $expected): void { Assert::assertEquals($expected, $result = $left->or($right)); diff --git a/tests/Unit/Result/ContainsTest.php b/tests/Unit/Result/ContainsTest.php index 49aa27d..a142b0e 100644 --- a/tests/Unit/Result/ContainsTest.php +++ b/tests/Unit/Result/ContainsTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -12,9 +13,9 @@ final class ContainsTest extends TestCase use Provider\Values; /** - * @dataProvider containsMatrix * @param Result $result - */ + */ + #[dataProvider('containsMatrix')] public function testContains(Result $result, mixed $value, bool $expect, bool $strict = true): void { Assert::assertSame($expect, $result->contains($value, strict: $strict)); @@ -55,9 +56,9 @@ public function testContainsDefaultsToStrict(): void } /** - * @dataProvider containsErrMatrix * @param Result $result - */ + */ + #[dataProvider('containsErrMatrix')] public function testContainsErr(Result $result, mixed $value, bool $expect, bool $strict = true): void { Assert::assertSame($expect, $result->containsErr($value, strict: $strict)); diff --git a/tests/Unit/Result/ConvertToOptionTest.php b/tests/Unit/Result/ConvertToOptionTest.php index e063089..420e395 100644 --- a/tests/Unit/Result/ConvertToOptionTest.php +++ b/tests/Unit/Result/ConvertToOptionTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Option; use TH\Maybe\Result; @@ -13,10 +14,10 @@ final class ConvertToOptionTest extends TestCase use Provider\Transpose; /** - * @dataProvider okMatrix * @param Result $result * @param Option $expected - */ + */ + #[DataProvider('okMatrix')] public function testOk(Result $result, Option $expected): void { Assert::assertEquals($expected, $result->ok()); @@ -39,10 +40,10 @@ public static function okMatrix(): iterable } /** - * @dataProvider errMatrix * @param Result $result * @param Option $expected - */ + */ + #[DataProvider('errMatrix')] public function testErr(Result $result, Option $expected): void { Assert::assertEquals($expected, $result->err()); @@ -67,10 +68,10 @@ public static function errMatrix(): iterable /** * @template T * @template E - * @dataProvider transposeMatrix * @param Result, E> $expected * @param Option> $option - */ + */ + #[DataProvider('transposeMatrix')] public function testTranspose(Option $option, Result $expected): void { Assert::assertEquals($option, $option2 = Result\transpose($expected)); diff --git a/tests/Unit/Result/ExtendsTest.php b/tests/Unit/Result/ExtendsTest.php index 350dfca..2c92671 100644 --- a/tests/Unit/Result/ExtendsTest.php +++ b/tests/Unit/Result/ExtendsTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -29,10 +30,10 @@ public function testErrIsExtendable(): void /** * Allowing overriding constructors would make the "Must be used" feature unsafe * - * @dataProvider resultClasses * @param class-string> $resultClass * @throws \ReflectionException - */ + */ + #[DataProvider('resultClasses')] public function testConstructorsCannotBeOverriden(string $resultClass): void { $rc = new \ReflectionClass($resultClass); @@ -42,9 +43,9 @@ public function testConstructorsCannotBeOverriden(string $resultClass): void } /** - * @dataProvider resultMethods * @throws \ReflectionException - */ + */ + #[DataProvider('resultMethods')] public function testOkResultMethodsCannotBeOverriden(string $method): void { $rc = new \ReflectionClass(Result\Ok::class); @@ -55,9 +56,9 @@ public function testOkResultMethodsCannotBeOverriden(string $method): void } /** - * @dataProvider resultMethods * @throws \ReflectionException - */ + */ + #[DataProvider('resultMethods')] public function testErrResultMethodsCannotBeOverriden(string $method): void { $rc = new \ReflectionClass(Result\Err::class); diff --git a/tests/Unit/Result/FlattenTest.php b/tests/Unit/Result/FlattenTest.php index 2d09dd4..dab6d9f 100644 --- a/tests/Unit/Result/FlattenTest.php +++ b/tests/Unit/Result/FlattenTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -9,10 +10,10 @@ final class FlattenTest extends TestCase { /** - * @dataProvider flattenMatrix * @param Result $expected * @param Result, null> $result - */ + */ + #[DataProvider('flattenMatrix')] public function testFlatten(Result $expected, Result $result): void { Assert::assertResultNotUsed($result); diff --git a/tests/Unit/Result/InspectTest.php b/tests/Unit/Result/InspectTest.php index 7095896..4a9aec8 100644 --- a/tests/Unit/Result/InspectTest.php +++ b/tests/Unit/Result/InspectTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -11,9 +12,7 @@ final class InspectTest extends TestCase { use Provider\Values; - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testInspectOk(mixed $value): void { $result = Result\ok($value); @@ -50,9 +49,7 @@ public function testInspectErrOk(): void Assert::assertResultNotUsed($result); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testInspectErrNone(mixed $value): void { $result = Result\err($value); diff --git a/tests/Unit/Result/IsTest.php b/tests/Unit/Result/IsTest.php index b63e45f..1d9ed7a 100644 --- a/tests/Unit/Result/IsTest.php +++ b/tests/Unit/Result/IsTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -11,9 +12,7 @@ final class IsTest extends TestCase { use Provider\Values; - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testIsOk(mixed $value): void { $result = Result\ok($value); @@ -27,9 +26,7 @@ public function testIsOk(mixed $value): void Assert::assertResultUsed($result); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testIsErr(mixed $value): void { $result = Result\ok($value); @@ -43,9 +40,7 @@ public function testIsErr(mixed $value): void Assert::assertResultUsed($result); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testIsOkAnd(mixed $value): void { $result = Result\ok($value); @@ -61,9 +56,7 @@ public function testIsOkAnd(mixed $value): void Assert::assertResultUsed($result); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testIsErrAnd(mixed $value): void { $result = Result\ok($value); diff --git a/tests/Unit/Result/MapTest.php b/tests/Unit/Result/MapTest.php index 5af4eec..a6dc871 100644 --- a/tests/Unit/Result/MapTest.php +++ b/tests/Unit/Result/MapTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -9,14 +10,14 @@ final class MapTest extends TestCase { /** - * @dataProvider mapMatrix * @template T * @template U * @param Result $result * @param U $mapResult * @param Result $expected * @param array $expectedCalls - */ + */ + #[DataProvider('mapMatrix')] public function testMap(Result $result, mixed $mapResult, Result $expected, array $expectedCalls): void { $calls = []; @@ -63,14 +64,14 @@ public static function mapMatrix(): iterable } /** - * @dataProvider mapErrMatrix * @template T * @template U * @param Result $result * @param U $mapResult * @param Result $expected * @param array $expectedCalls - */ + */ + #[DataProvider('mapErrMatrix')] public function testMapErr(Result $result, mixed $mapResult, Result $expected, array $expectedCalls): void { $calls = []; @@ -117,7 +118,6 @@ public static function mapErrMatrix(): iterable } /** - * @dataProvider mapOrMatrix * @template T * @template U * @param Result $result @@ -125,7 +125,8 @@ public static function mapErrMatrix(): iterable * @param U $default * @param U $expected * @param array $expectedCalls - */ + */ + #[DataProvider('mapOrMatrix')] public function testMapOr( Result $result, mixed $mapResult, diff --git a/tests/Unit/Result/MustBeUsedTest.php b/tests/Unit/Result/MustBeUsedTest.php index d5741d4..d4988d4 100644 --- a/tests/Unit/Result/MustBeUsedTest.php +++ b/tests/Unit/Result/MustBeUsedTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Result; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Result\UnusedResultException; @@ -10,9 +11,9 @@ final class MustBeUsedTest extends TestCase { /** - * @dataProvider resultsFactory * @param callable(): Result $factory - */ + */ + #[DataProvider('resultsFactory')] public function testNotUsingAResultThrowAnExceptionWhenFreed(callable $factory): void { $this->expectException(UnusedResultException::class); @@ -25,9 +26,9 @@ public function testNotUsingAResultThrowAnExceptionWhenFreed(callable $factory): } /** - * @dataProvider resultsFactory * @param callable(): Result $factory - */ + */ + #[DataProvider('resultsFactory')] public function testUsingAResultAvoidTheExceptionWhenFreed(callable $factory): void { (static function (callable $factory): void { @@ -37,9 +38,9 @@ public function testUsingAResultAvoidTheExceptionWhenFreed(callable $factory): v } /** - * @dataProvider resultsFactory * @param callable(): Result $factory - */ + */ + #[DataProvider('resultsFactory')] public function testAClonedResultMustBeUsed(callable $factory): void { $this->expectException(UnusedResultException::class); @@ -56,9 +57,9 @@ public function testAClonedResultMustBeUsed(callable $factory): void } /** - * @dataProvider resultsFactory * @param callable(): Result $factory - */ + */ + #[DataProvider('resultsFactory')] public function testAnUnserializedResultDontHaveToBeUsed(callable $factory): void { (static function (callable $factory): void { diff --git a/tests/Unit/Result/TrapTest.php b/tests/Unit/Result/TrapTest.php index b6bfbc1..19ad9d9 100644 --- a/tests/Unit/Result/TrapTest.php +++ b/tests/Unit/Result/TrapTest.php @@ -2,6 +2,7 @@ namespace TH\Maybe\Tests\Unit\Result; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Assert; @@ -11,9 +12,7 @@ final class TrapTest extends TestCase { use Provider\Values; - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testTrapOk(mixed $value): void { $callback = static fn () => $value; diff --git a/tests/Unit/Result/UnwrapTest.php b/tests/Unit/Result/UnwrapTest.php index a87ba07..7cf044d 100644 --- a/tests/Unit/Result/UnwrapTest.php +++ b/tests/Unit/Result/UnwrapTest.php @@ -3,6 +3,7 @@ namespace TH\Maybe\Tests\Unit\Result; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TH\Maybe\Result; use TH\Maybe\Tests\Provider; @@ -18,9 +19,7 @@ public function testExpectErr(): void Result\err(null)->expect("This should fail"); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testExpectOk(mixed $value): void { Assert::assertSame($value, Result\ok($value)->expect("This should succeed")); @@ -42,41 +41,31 @@ public function testUnwrapErrException(): void Result\err($ex)->unwrap(); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOk(mixed $value): void { Assert::assertSame($value, Result\ok($value)->unwrap()); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrErr(mixed $value): void { Assert::assertSame($value, Result\err(null)->unwrapOr($value)); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrOk(mixed $value): void { Assert::assertSame($value, Result\ok($value)->unwrapOr(false)); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrElseErr(mixed $value): void { Assert::assertSame($value, Result\err(null)->unwrapOrElse(static fn () => $value)); } - /** - * @dataProvider values - */ + #[DataProvider('values')] public function testUnwrapOrElseOk(mixed $value): void { Assert::assertSame($value, Result\ok($value)->unwrapOrElse(static fn () => false));