Skip to content
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 11 additions & 10 deletions tests/Unit/Option/BooleanTest.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\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
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
5 changes: 3 additions & 2 deletions tests/Unit/Option/ContainsTest.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\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
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
19 changes: 9 additions & 10 deletions tests/Unit/Option/ConvertToResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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,11 +27,11 @@ public function testOkOr(Option $option, mixed $err, Result $expected): void
}

/**
* @dataProvider okOrMatrix
* @param Option<mixed> $option
* @param Result<mixed, mixed> $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;

Expand All @@ -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);
}

/**
Expand All @@ -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<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
5 changes: 3 additions & 2 deletions tests/Unit/Option/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> $option
* @param array<T> $expectedCalls
*/
*/
#[DataProvider('filterMatrix')]
public function testFilter(Option $option, bool $filterResult, bool $expectNone, array $expectedCalls): void
{
$calls = [];
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Option/FlattenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
5 changes: 3 additions & 2 deletions tests/Unit/Option/FromValueTest.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\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
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
5 changes: 2 additions & 3 deletions tests/Unit/Option/InspectTest.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\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;
Expand All @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions tests/Unit/Option/IsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/Option/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<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,15 +60,15 @@ public static function mapMatrix(): iterable
}

/**
* @dataProvider mapOrMatrix
* @template T
* @template U
* @param Option<T> $option
* @param U $mapResult
* @param U $default
* @param U $expected
* @param array<T> $expectedCalls
*/
*/
#[DataProvider('mapOrMatrix')]
public function testMapOr(
Option $option,
mixed $mapResult,
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/Option/OfTest.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\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
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
5 changes: 2 additions & 3 deletions tests/Unit/Option/SerializationTest.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\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use TH\Maybe\Option;
use TH\Maybe\Tests\Provider;
Expand All @@ -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));
Expand Down
Loading