Skip to content

Convert PHPUnit annotations to attributes #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions tests/Unit/Option/BooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;

Expand All @@ -12,24 +13,24 @@ final class BooleanTest extends TestCase
use Provider\Options;

/**
* @dataProvider andMatrix
* @template T
* @param Option<T> $left
* @param Option<T> $right
* @param Option<T> $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<T> $left
* @param Option<T> $right
* @param Option<T> $expected
*/
#[DataProvider('andMatrix')]
public function testAndThen(Option $left, Option $right, Option $expected): void
{
$calls = [];
Expand All @@ -47,12 +48,12 @@ public function testAndThen(Option $left, Option $right, Option $expected): void
}

/**
* @dataProvider orMatrix
* @template T
* @param Option<T> $left
* @param Option<T> $right
* @param Option<T> $expected
*/
#[DataProvider('orMatrix')]
public function testOrElse(Option $left, Option $right, Option $expected): void
{
$calls = 0;
Expand All @@ -70,24 +71,24 @@ public function testOrElse(Option $left, Option $right, Option $expected): void
}

/**
* @dataProvider orMatrix
* @template T
* @param Option<T> $left
* @param Option<T> $right
* @param Option<T> $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<T> $left
* @param Option<T> $right
* @param Option<T> $expected
*/
#[DataProvider('xorMatrix')]
public function testXor(Option $left, Option $right, Option $expected): void
{
Assert::assertEquals($expected, $left->xor($right));
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Option/ContainsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;

Expand All @@ -12,9 +13,9 @@ final class ContainsTest extends TestCase
use Provider\Values;

/**
* @dataProvider containsMatrix
* @param Option<mixed> $option
*/
#[DataProvider('containsMatrix')]
public function testContains(Option $option, mixed $value, bool $expect, bool $strict = true): void
{
Assert::assertSame($expect, $option->contains($value, strict: $strict));
Expand Down
26 changes: 20 additions & 6 deletions tests/Unit/Option/ConvertToResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TH\Maybe\Tests\Unit\Option;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Result;
use TH\Maybe\Tests\Assert;
Expand All @@ -13,10 +14,10 @@ final class ConvertToResultTest extends TestCase
use Provider\Transpose;

/**
* @dataProvider okOrMatrix
* @param Option<mixed> $option
* @param Result<mixed, mixed> $expected
*/
#[DataProvider('okOrMatrix')]
public function testOkOr(Option $option, mixed $err, Result $expected): void
{
Assert::assertEquals($expected, $result = $option->okOr($err));
Expand All @@ -26,10 +27,10 @@ public function testOkOr(Option $option, mixed $err, Result $expected): void
}

/**
* @dataProvider okOrMatrix
* @param Option<mixed> $option
* @param Result<mixed, mixed> $expected
*/
#[DataProvider('okOrElseMatrix')]
public function testOkOrElse(Option $option, mixed $err, Result $expected, int $expectedCalls): void
{
$calls = 0;
Expand All @@ -47,30 +48,43 @@ public function testOkOrElse(Option $option, mixed $err, Result $expected, int $
}

/**
* @return iterable<array{Option<mixed>, mixed, Result<mixed, mixed>, int}>
* @return iterable<array{Option<mixed>, mixed, Result<mixed, mixed>}>
*/
public static function okOrMatrix(): iterable
{
yield "none" => [
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
* @return iterable<array{Option<mixed>, mixed, Result<mixed, mixed>, int}>
*/
public static function okOrElseMatrix(): iterable
{
foreach (self::okOrMatrix() as $key => [$option, $err, $result]) {
yield $key => [
$option,
$err,
$result,
$option instanceof Option\None ? 1 : 0,
];
}
}

/**
* @param Option<Result<mixed, mixed>> $option
* @param Result<mixed, mixed> $expected
*/
#[DataProvider('transposeMatrix')]
public function testTranspose(Option $option, Result $expected): void
{
Assert::assertEquals($expected, $result = Option\transpose($option));
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Option/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;

final class FilterTest extends TestCase
{
/**
* @dataProvider filterMatrix
* @template T
* @param Option<T> $option
* @param array<T> $expectedCalls
*/
#[DataProvider('filterMatrix')]
public function testFilter(Option $option, bool $filterResult, bool $expectNone, array $expectedCalls): void
{
$calls = [];
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Option/FlattenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;

final class FlattenTest extends TestCase
{
/**
* @dataProvider flattenMatrix
* @param Option<mixed> $expected
* @param Option<Option<mixed>> $option
*/
#[DataProvider('flattenMatrix')]
public function testFlatten(Option $expected, Option $option): void
{
Assert::assertEquals($expected, Option\flatten($option));
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Option/FromValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;

Expand All @@ -12,9 +13,9 @@ final class FromValueTest extends TestCase
use Provider\Options;

/**
* @dataProvider fromValueMatrix
* @param Option<mixed> $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));
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Option/InspectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;

Expand All @@ -12,8 +13,8 @@ final class InspectTest extends TestCase
use Provider\Values;

/**
* @dataProvider values
*/
#[DataProvider('values')]
public function testInspectSome(mixed $value): void
{
$option = Option\some($value);
Expand Down
7 changes: 4 additions & 3 deletions tests/Unit/Option/IsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TH\Maybe\Tests\Unit\Option;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Tests\Assert;
use TH\Maybe\Tests\Provider;
Expand All @@ -12,8 +13,8 @@ final class IsTest extends TestCase
use Provider\Values;

/**
* @dataProvider values
*/
#[DataProvider('values')]
public function testIsSome(mixed $value): void
{
$option = Option\some($value);
Expand All @@ -26,8 +27,8 @@ public function testIsSome(mixed $value): void
}

/**
* @dataProvider values
*/
#[DataProvider('values')]
public function testIsNone(mixed $value): void
{
$option = Option\some($value);
Expand All @@ -40,8 +41,8 @@ public function testIsNone(mixed $value): void
}

/**
* @dataProvider values
*/
#[DataProvider('values')]
public function testIsSomeAnd(mixed $value): void
{
$option = Option\some($value);
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Option/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;

final class MapTest extends TestCase
{
/**
* @dataProvider mapMatrix
* @template T
* @template U
* @param Option<T> $option
* @param U $mapResult
* @param Option<U> $expected
* @param array<T> $expectedCalls
*/
#[DataProvider('mapMatrix')]
public function testMap(Option $option, mixed $mapResult, Option $expected, array $expectedCalls): void
{
$calls = [];
Expand Down Expand Up @@ -59,7 +60,6 @@ public static function mapMatrix(): iterable
}

/**
* @dataProvider mapOrMatrix
* @template T
* @template U
* @param Option<T> $option
Expand All @@ -68,6 +68,7 @@ public static function mapMatrix(): iterable
* @param U $expected
* @param array<T> $expectedCalls
*/
#[DataProvider('mapOrMatrix')]
public function testMapOr(
Option $option,
mixed $mapResult,
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Option/OfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;

Expand All @@ -12,18 +13,18 @@ final class OfTest extends TestCase
use Provider\Options;

/**
* @dataProvider fromValueMatrix
* @param Option<mixed> $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<mixed> $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));
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Option/SerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;

Expand All @@ -20,8 +21,8 @@ public function testWithNone(): void
}

/**
* @dataProvider serializableValues
*/
#[DataProvider('serializableValues')]
public function testWithSomeValidValues(mixed $value): void
{
$this->testSerializableOption(Option\some($value));
Expand Down
Loading
Loading