From 7f3d5aa537a6df4ea79c8f7d6beff9c297203c33 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 14 May 2026 15:38:54 +0200 Subject: [PATCH 1/2] use blackbox 7 --- CHANGELOG.md | 6 + composer.json | 6 +- proofs/attempt.php | 210 +++++------ proofs/either.php | 39 +- proofs/identity.php | 76 ++-- proofs/map.php | 15 +- proofs/maybe.php | 48 ++- proofs/monoid/append.php | 15 +- proofs/monoid/arrayMerge.php | 15 +- proofs/monoid/concat.php | 15 +- proofs/monoid/mergeMap.php | 15 +- proofs/monoid/mergeSet.php | 15 +- proofs/predicate.php | 10 +- proofs/sequence.php | 404 ++++++++++----------- proofs/set.php | 60 ++- proofs/validation.php | 126 +++---- properties/Monoid.php | 2 +- properties/Monoid/Associativity.php | 4 +- properties/Sequence.php | 2 +- properties/Sequence/LookupFirstAttempt.php | 2 +- properties/Sequence/LookupFirstEither.php | 2 +- properties/Sequence/LookupFirstMaybe.php | 2 +- properties/Sequence/LookupLastAttempt.php | 2 +- properties/Sequence/LookupLastEither.php | 2 +- properties/Sequence/LookupLastMaybe.php | 2 +- tests/Fixtures/SetTest.php | 2 +- tests/RegExpTest.php | 9 +- 27 files changed, 520 insertions(+), 586 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b98acea2..498debc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires `innmind/blackbox:~7.0` + ## 6.1.0 - 2026-04-05 ### Added diff --git a/composer.json b/composer.json index 8b53c523..234304b3 100644 --- a/composer.json +++ b/composer.json @@ -31,16 +31,16 @@ }, "require-dev": { "innmind/static-analysis": "~1.3", - "innmind/black-box": "^6.4.1", + "innmind/black-box": "~7.0", "innmind/coding-standard": "~2.0" }, "conflict": { - "innmind/black-box": "<6.0|~7.0" + "innmind/black-box": "<7.0|~8.0" }, "suggest": { "innmind/black-box": "For property based testing" }, "provide": { - "innmind/black-box-sets": "6.0" + "innmind/black-box-sets": "7.0" } } diff --git a/proofs/attempt.php b/proofs/attempt.php index d651614e..6ffa8911 100644 --- a/proofs/attempt.php +++ b/proofs/attempt.php @@ -4,7 +4,7 @@ use Innmind\Immutable\Attempt; use Innmind\BlackBox\Set; -return static function() { +return static function($prove) { $exceptions = Set::of( new RuntimeException, new LogicException, @@ -13,10 +13,10 @@ new Error, ); - yield proof( - 'Attempt::of() catches exceptions', - given($exceptions), - static function($assert, $e) { + yield $prove + ->proof('Attempt::of() catches exceptions') + ->given($exceptions) + ->test(static function($assert, $e) { $attempt = Attempt::of(static fn() => throw $e); $assert->same( @@ -26,17 +26,16 @@ static function($assert, $e) { static fn($e) => $e, ), ); - }, - ); + }); - yield proof( - 'Attempt::map()', - given( + yield $prove + ->proof('Attempt::map()') + ->given( Set::type(), Set::type(), $exceptions, - ), - static function($assert, $start, $end, $e) { + ) + ->test(static function($assert, $start, $end, $e) { $attempt = Attempt::result($start) ->map(static function($value) use ($assert, $start, $end) { $assert->same($start, $value); @@ -62,17 +61,16 @@ static function($assert, $start, $end, $e) { static fn($value) => $value, ), ); - }, - ); + }); - yield proof( - 'Attempt::flatMap()', - given( + yield $prove + ->proof('Attempt::flatMap()') + ->given( Set::type(), Set::type(), $exceptions, - ), - static function($assert, $start, $end, $e) { + ) + ->test(static function($assert, $start, $end, $e) { $attempt = Attempt::result($start) ->flatMap(static function($value) use ($assert, $start, $end) { $assert->same($start, $value); @@ -113,17 +111,16 @@ static function($assert, $start, $end, $e) { static fn($value) => $value, ), ); - }, - ); + }); - yield proof( - 'Attempt::mapError()', - given( + yield $prove + ->proof('Attempt::mapError()') + ->given( $exceptions, $exceptions, Set::type(), - ), - static function($assert, $start, $end, $value) { + ) + ->test(static function($assert, $start, $end, $value) { $attempt = Attempt::error($start) ->mapError(static function($e) use ($assert, $start, $end) { $assert->same($start, $e); @@ -149,17 +146,17 @@ static function($assert, $start, $end, $value) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Attempt::mapErrorCase()', - given( + yield $prove + ->proof('Attempt::mapErrorCase()') + ->given( $exceptions, $exceptions, $exceptions, - )->filter(static fn($a, $b, $c) => !($a instanceof $c)), - static function($assert, $start, $end, $other) { + ) + ->filter(static fn($a, $b, $c) => !($a instanceof $c)) + ->test(static function($assert, $start, $end, $other) { $assert->same( $end, Attempt::error($start) @@ -178,17 +175,16 @@ static function($assert, $start, $end, $other) { static fn($e) => $e, ), ); - }, - ); + }); - yield proof( - 'Attempt::recover()', - given( + yield $prove + ->proof('Attempt::recover()') + ->given( $exceptions, $exceptions, Set::type(), - ), - static function($assert, $start, $end, $value) { + ) + ->test(static function($assert, $start, $end, $value) { $attempt = Attempt::error($start) ->recover(static function($e) use ($assert, $start, $end) { $assert->same($start, $e); @@ -229,18 +225,18 @@ static function($assert, $start, $end, $value) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Attempt::recoverCase()', - given( + yield $prove + ->proof('Attempt::recoverCase()') + ->given( $exceptions, $exceptions, $exceptions, Set::type(), - )->filter(static fn($a, $b, $c) => !($a instanceof $c)), - static function($assert, $start, $end, $other, $value) { + ) + ->filter(static fn($a, $b, $c) => !($a instanceof $c)) + ->test(static function($assert, $start, $end, $other, $value) { $assert->same( $value, Attempt::error($start) @@ -256,16 +252,15 @@ static function($assert, $start, $end, $other, $value) { static fn($e) => $e, ), ); - }, - ); + }); - yield proof( - 'Attempt::maybe()', - given( + yield $prove + ->proof('Attempt::maybe()') + ->given( Set::type(), $exceptions, - ), - static function($assert, $result, $e) { + ) + ->test(static function($assert, $result, $e) { $assert->same( $result, Attempt::result($result) @@ -283,16 +278,15 @@ static function($assert, $result, $e) { static fn() => true, ), ); - }, - ); + }); - yield proof( - 'Attempt::either()', - given( + yield $prove + ->proof('Attempt::either()') + ->given( Set::type(), $exceptions, - ), - static function($assert, $result, $e) { + ) + ->test(static function($assert, $result, $e) { $assert->same( $result, Attempt::result($result) @@ -311,16 +305,15 @@ static function($assert, $result, $e) { static fn($value) => $value, ), ); - }, - ); + }); - yield proof( - 'Attempt::memoize()', - given( + yield $prove + ->proof('Attempt::memoize()') + ->given( Set::type(), $exceptions, - ), - static function($assert, $result, $e) { + ) + ->test(static function($assert, $result, $e) { $assert->same( $result, Attempt::result($result) @@ -379,18 +372,17 @@ static function($assert, $result, $e) { ); $_ = $attempt->memoize(); $assert->same(1, $called); - }, - ); + }); - yield proof( - 'Attempt::defer()', - given( + yield $prove + ->proof('Attempt::defer()') + ->given( Set::type(), Set::type(), $exceptions, $exceptions, - ), - static function($assert, $result1, $result2, $e1, $e2) { + ) + ->test(static function($assert, $result1, $result2, $e1, $e2) { $loaded = false; $attempt = Attempt::defer(static function() use ($result1, &$loaded) { $loaded = true; @@ -430,16 +422,15 @@ static function($assert, $result1, $result2, $e1, $e2) { static fn($value) => $value, ), ); - }, - ); + }); - yield proof( - 'Attempt::unwrap()', - given( + yield $prove + ->proof('Attempt::unwrap()') + ->given( Set::type(), $exceptions, - ), - static function($assert, $result, $e) { + ) + ->test(static function($assert, $result, $e) { $assert->same( $result, Attempt::result($result)->unwrap(), @@ -449,18 +440,17 @@ static function($assert, $result, $e) { static fn() => Attempt::error($e)->unwrap(), $e::class, ); - }, - ); + }); - yield proof( - 'Attempt::eitherWay()', - given( + yield $prove + ->proof('Attempt::eitherWay()') + ->given( Set::type(), Set::type(), $exceptions, $exceptions, - ), - static function($assert, $result1, $result2, $error1, $error2) { + ) + ->test(static function($assert, $result1, $result2, $error1, $error2) { $assert->same( $result1, Attempt::result($result1) @@ -521,18 +511,17 @@ static function($assert, $result1, $result2, $error1, $error2) { static fn($value) => $value, ), ); - }, - ); + }); - yield proof( - 'Attempt::defer()->eitherWay()', - given( + yield $prove + ->proof('Attempt::defer()->eitherWay()') + ->given( Set::type(), Set::type(), $exceptions, $exceptions, - ), - static function($assert, $result1, $result2, $error1, $error2) { + ) + ->test(static function($assert, $result1, $result2, $error1, $error2) { $loaded = false; $attempt = Attempt::defer(static function() use (&$loaded, $result1) { $loaded = true; @@ -622,16 +611,15 @@ static function($assert, $result1, $result2, $error1, $error2) { static fn($value) => $value, ), ); - }, - ); + }); - yield proof( - 'Attempt::guard()', - given( + yield $prove + ->proof('Attempt::guard()') + ->given( Set::integers()->above(1), Set::integers()->below(-1), - ), - static function($assert, $positive, $negative) { + ) + ->test(static function($assert, $positive, $negative) { $fail = new Exception; $assert->same( $positive, @@ -676,16 +664,15 @@ static function($assert, $positive, $negative) { static fn($e) => $e, ), ); - }, - ); + }); - yield proof( - 'Attempt::defer()->guard()', - given( + yield $prove + ->proof('Attempt::defer()->guard()') + ->given( Set::integers()->above(1), Set::integers()->below(-1), - ), - static function($assert, $positive, $negative) { + ) + ->test(static function($assert, $positive, $negative) { $fail = new Exception; $assert->same( $positive, @@ -730,6 +717,5 @@ static function($assert, $positive, $negative) { static fn($e) => $e, ), ); - }, - ); + }); }; diff --git a/proofs/either.php b/proofs/either.php index 745de283..4b827360 100644 --- a/proofs/either.php +++ b/proofs/either.php @@ -4,11 +4,11 @@ use Innmind\Immutable\Either; use Innmind\BlackBox\Set; -return static function() { - yield proof( - 'Either::memoize() any composition', - given(Set::type()->filter(static fn($value) => !\is_null($value))), - static function($assert, $value) { +return static function($prove) { + yield $prove + ->proof('Either::memoize() any composition') + ->given(Set::type()->filter(static fn($value) => !\is_null($value))) + ->test(static function($assert, $value) { $loaded = false; $either = Either::defer(static fn() => Either::right($value)) ->flatMap(static function() use ($value, &$loaded) { @@ -22,16 +22,15 @@ static function($assert, $value) { $assert->false($loaded); $_ = $either->memoize(); $assert->true($loaded); - }, - ); + }); - yield proof( - 'Either->attempt()', - given( + yield $prove + ->proof('Either->attempt()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $right, $left) { + ) + ->test(static function($assert, $right, $left) { $assert->same( $right, Either::right($right) @@ -53,16 +52,15 @@ static function($assert, $right, $left) { static fn($error) => $error, ), ); - }, - ); + }); - yield proof( - 'Either::defer()->attempt()', - given( + yield $prove + ->proof('Either::defer()->attempt()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $right, $left) { + ) + ->test(static function($assert, $right, $left) { $loaded = false; $attempt = Either::defer(static function() use (&$loaded, $right) { $loaded = true; @@ -98,6 +96,5 @@ static function($assert, $right, $left) { ), ); $assert->true($loaded); - }, - ); + }); }; diff --git a/proofs/identity.php b/proofs/identity.php index c8e0de74..cc08a074 100644 --- a/proofs/identity.php +++ b/proofs/identity.php @@ -7,23 +7,22 @@ }; use Innmind\BlackBox\Set; -return static function() { - yield proof( - 'Identity::unwrap()', - given(Set::type()), - static fn($assert, $value) => $assert->same( +return static function($prove) { + yield $prove + ->proof('Identity::unwrap()') + ->given(Set::type()) + ->test(static fn($assert, $value) => $assert->same( $value, Identity::of($value)->unwrap(), - ), - ); + )); - yield proof( - 'Identity::map()', - given( + yield $prove + ->proof('Identity::map()') + ->given( Set::type(), Set::type(), - ), - static fn($assert, $initial, $expected) => $assert->same( + ) + ->test(static fn($assert, $initial, $expected) => $assert->same( $expected, Identity::of($initial) ->map(static function($value) use ($assert, $initial, $expected) { @@ -32,16 +31,15 @@ return $expected; }) ->unwrap(), - ), - ); + )); - yield proof( - 'Identity::flatMap()', - given( + yield $prove + ->proof('Identity::flatMap()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $initial, $expected) { + ) + ->test(static function($assert, $initial, $expected) { $assert->same( $expected, Identity::of($initial) @@ -96,17 +94,16 @@ static function($assert, $initial, $expected) { $identity->unwrap(), ); $assert->same(2, $loaded); - }, - ); + }); - yield proof( - 'Identity::map() and ::flatMap() interchangeability', - given( + yield $prove + ->proof('Identity::map() and ::flatMap() interchangeability') + ->given( Set::type(), Set::type(), Set::type(), - ), - static fn($assert, $initial, $intermediate, $expected) => $assert->same( + ) + ->test(static fn($assert, $initial, $intermediate, $expected) => $assert->same( Identity::of($initial) ->flatMap(static fn() => Identity::of($intermediate)) ->map(static fn() => $expected) @@ -118,13 +115,12 @@ static function($assert, $initial, $expected) { ), ) ->unwrap(), - ), - ); + )); - yield proof( - 'Identity::toSequence()', - given(Set::sequence(Set::type())), - static function($assert, $values) { + yield $prove + ->proof('Identity::toSequence()') + ->given(Set::sequence(Set::type())) + ->test(static function($assert, $values) { $inMemory = Sequence::of(...$values); $assert->same( @@ -179,16 +175,15 @@ static function($assert, $values) { $sequence->toList(), ); $assert->same(2, $loaded); - }, - ); + }); - yield proof( - 'Identity::defer() holds intermediary values', - given( + yield $prove + ->proof('Identity::defer() holds intermediary values') + ->given( Set::type(), Set::type(), - ), - static function($assert, $value1, $value2) { + ) + ->test(static function($assert, $value1, $value2) { $m1 = Identity::defer(static function() use ($value1) { static $loaded = false; @@ -212,6 +207,5 @@ static function($assert, $value1, $value2) { $m1->unwrap(), ), ); - }, - ); + }); }; diff --git a/proofs/map.php b/proofs/map.php index c2c3a50d..6c154f41 100644 --- a/proofs/map.php +++ b/proofs/map.php @@ -4,14 +4,14 @@ use Innmind\Immutable\Map; use Innmind\BlackBox\Set; -return static function() { - yield proof( - 'Map::toSequence()', - given( +return static function($prove) { + yield $prove + ->proof('Map::toSequence()') + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $keys, $values) { + ) + ->test(static function($assert, $keys, $values) { $map = Map::of(); foreach ($keys as $index => $key) { @@ -26,6 +26,5 @@ static function($assert, $keys, $values) { ->toList(), )), ); - }, - ); + }); }; diff --git a/proofs/maybe.php b/proofs/maybe.php index 7717b967..6b0342fe 100644 --- a/proofs/maybe.php +++ b/proofs/maybe.php @@ -4,14 +4,14 @@ use Innmind\Immutable\Maybe; use Innmind\BlackBox\Set; -return static function() { - yield proof( - 'Maybe::defer() holds intermediary values', - given( +return static function($prove) { + yield $prove + ->proof('Maybe::defer() holds intermediary values') + ->given( Set::type(), Set::type(), - ), - static function($assert, $value1, $value2) { + ) + ->test(static function($assert, $value1, $value2) { $m1 = Maybe::defer(static function() use ($value1) { static $loaded = false; @@ -41,13 +41,12 @@ static function($assert, $value1, $value2) { ), ), ); - }, - ); + }); - yield proof( - 'Maybe::memoize() any composition', - given(Set::type()->filter(static fn($value) => !\is_null($value))), - static function($assert, $value) { + yield $prove + ->proof('Maybe::memoize() any composition') + ->given(Set::type()->filter(static fn($value) => !\is_null($value))) + ->test(static function($assert, $value) { $loaded = false; $maybe = Maybe::defer(static fn() => Maybe::just($value)) ->flatMap(static function() use ($value, &$loaded) { @@ -61,13 +60,12 @@ static function($assert, $value) { $assert->false($loaded); $_ = $maybe->memoize(); $assert->true($loaded); - }, - ); + }); - yield proof( - 'Maybe->attempt()', - given(Set::type()), - static function($assert, $value) { + yield $prove + ->proof('Maybe->attempt()') + ->given(Set::type()) + ->test(static function($assert, $value) { $assert->same( $value, Maybe::just($value) @@ -85,13 +83,12 @@ static function($assert, $value) { static fn($error) => $error, ), ); - }, - ); + }); - yield proof( - 'Maybe::defer()->attempt()', - given(Set::type()), - static function($assert, $value) { + yield $prove + ->proof('Maybe::defer()->attempt()') + ->given(Set::type()) + ->test(static function($assert, $value) { $loaded = false; $attempt = Maybe::defer(static function() use (&$loaded, $value) { $loaded = true; @@ -123,6 +120,5 @@ static function($assert, $value) { ), ); $assert->true($loaded); - }, - ); + }); }; diff --git a/proofs/monoid/append.php b/proofs/monoid/append.php index dfa11240..610fb7ff 100644 --- a/proofs/monoid/append.php +++ b/proofs/monoid/append.php @@ -8,23 +8,22 @@ use Innmind\BlackBox\Set; use Properties\Innmind\Immutable\Monoid; -return static function() { +return static function($prove) { $equals = static fn($a, $b) => $a->equals($b); $set = Set::sequence(Set::type())->map( static fn($values) => Sequence::of(...$values), ); - yield properties( + yield $prove->properties( 'Append properties', Monoid::properties($set, $equals), - Set::of(Append::of()), + Set::of(static fn() => Append::of()), ); foreach (Monoid::list($set, $equals) as $property) { - yield proof( - 'Append property', - given($property), - static fn($assert, $property) => $property->ensureHeldBy($assert, Append::of()), - ); + yield $prove + ->proof('Append property') + ->given($property) + ->test(static fn($assert, $property) => $property->ensureHeldBy($assert, Append::of())); } }; diff --git a/proofs/monoid/arrayMerge.php b/proofs/monoid/arrayMerge.php index 28a3dfb1..35da3850 100644 --- a/proofs/monoid/arrayMerge.php +++ b/proofs/monoid/arrayMerge.php @@ -8,7 +8,7 @@ use Innmind\BlackBox\Set; use Properties\Innmind\Immutable\Monoid; -return static function() { +return static function($prove) { $equals = static fn($a, $b) => $a === $b; $set = Set::sequence( Set::compose( @@ -29,17 +29,16 @@ \array_column($pairs, 1), )); - yield properties( + yield $prove->properties( 'ArrayMerge properties', Monoid::properties($set, $equals), - Set::of(ArrayMerge::monoid), + Set::of(static fn() => ArrayMerge::monoid), ); foreach (Monoid::list($set, $equals) as $property) { - yield proof( - 'ArrayMerge property', - given($property), - static fn($assert, $property) => $property->ensureHeldBy($assert, ArrayMerge::monoid), - ); + yield $prove + ->proof('ArrayMerge property') + ->given($property) + ->test(static fn($assert, $property) => $property->ensureHeldBy($assert, ArrayMerge::monoid)); } }; diff --git a/proofs/monoid/concat.php b/proofs/monoid/concat.php index f50145b9..43533eb0 100644 --- a/proofs/monoid/concat.php +++ b/proofs/monoid/concat.php @@ -8,21 +8,20 @@ use Innmind\BlackBox\Set; use Properties\Innmind\Immutable\Monoid; -return static function() { +return static function($prove) { $equals = static fn($a, $b) => $a->toString() === $b->toString(); $set = Set::strings()->unicode()->map(Str::of(...)); - yield properties( + yield $prove->properties( 'Concat properties', Monoid::properties($set, $equals), - Set::of(Concat::monoid), + Set::of(static fn() => Concat::monoid), ); foreach (Monoid::list($set, $equals) as $property) { - yield proof( - 'Concat property', - given($property), - static fn($assert, $property) => $property->ensureHeldBy($assert, Concat::monoid), - ); + yield $prove + ->proof('Concat property') + ->given($property) + ->test(static fn($assert, $property) => $property->ensureHeldBy($assert, Concat::monoid)); } }; diff --git a/proofs/monoid/mergeMap.php b/proofs/monoid/mergeMap.php index c23487b7..f15458af 100644 --- a/proofs/monoid/mergeMap.php +++ b/proofs/monoid/mergeMap.php @@ -9,7 +9,7 @@ use Innmind\BlackBox\Set; use Properties\Innmind\Immutable\Monoid; -return static function() { +return static function($prove) { $equals = static fn($a, $b) => $a->equals($b); $set = Set::sequence( Set::compose( @@ -27,17 +27,16 @@ }) ->map(static fn($pairs) => Map::of(...$pairs)); - yield properties( + yield $prove->properties( 'MergeMap properties', Monoid::properties($set, $equals), - Set::of(MergeMap::of()), + Set::of(static fn() => MergeMap::of()), ); foreach (Monoid::list($set, $equals) as $property) { - yield proof( - 'MergeMap property', - given($property), - static fn($assert, $property) => $property->ensureHeldBy($assert, MergeMap::of()), - ); + yield $prove + ->proof('MergeMap property') + ->given($property) + ->test(static fn($assert, $property) => $property->ensureHeldBy($assert, MergeMap::of())); } }; diff --git a/proofs/monoid/mergeSet.php b/proofs/monoid/mergeSet.php index 7aa8d137..511080fa 100644 --- a/proofs/monoid/mergeSet.php +++ b/proofs/monoid/mergeSet.php @@ -6,24 +6,23 @@ use Fixtures\Innmind\Immutable\Set as FSet; use Properties\Innmind\Immutable\Monoid; -return static function() { +return static function($prove) { $equals = static fn($a, $b) => $a->equals($b); $set = FSet::of( Set::integers()->between(0, 200), Set::integers()->between(1, 10), ); - yield properties( + yield $prove->properties( 'MergeSet properties', Monoid::properties($set, $equals), - Set::of(MergeSet::of()), + Set::of(static fn() => MergeSet::of()), ); foreach (Monoid::list($set, $equals) as $property) { - yield proof( - 'MergeSet property', - given($property), - static fn($assert, $property) => $property->ensureHeldBy($assert, MergeSet::of()), - ); + yield $prove + ->proof('MergeSet property') + ->given($property) + ->test(static fn($assert, $property) => $property->ensureHeldBy($assert, MergeSet::of())); } }; diff --git a/proofs/predicate.php b/proofs/predicate.php index dde7ec16..7adc5e23 100644 --- a/proofs/predicate.php +++ b/proofs/predicate.php @@ -3,8 +3,8 @@ use Innmind\Immutable\Predicate\Instance; -return static function() { - yield test( +return static function($prove) { + yield $prove->test( 'Or predicate', static function($assert) { $array = new SplFixedArray; @@ -27,7 +27,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Or predicate is chainable', static function($assert) { $array = new SplFixedArray; @@ -59,7 +59,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'And predicate', static function($assert) { $array = new SplFixedArray; @@ -82,7 +82,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'And predicate is chainable', static function($assert) { $array = new SplFixedArray; diff --git a/proofs/sequence.php b/proofs/sequence.php index 35518970..6f02bbc1 100644 --- a/proofs/sequence.php +++ b/proofs/sequence.php @@ -13,11 +13,11 @@ use Properties\Innmind\Immutable\Sequence as Properties; use Innmind\BlackBox\Set; -return static function() { - yield proof( - 'Sequence::toIdentity()', - given(Set::sequence(Set::type())), - static function($assert, $values) { +return static function($prove) { + yield $prove + ->proof('Sequence::toIdentity()') + ->given(Set::sequence(Set::type())) + ->test(static function($assert, $values) { $sequence = Sequence::of(...$values); $assert->same( @@ -27,16 +27,15 @@ static function($assert, $values) { ->unwrap() ->toList(), ); - }, - ); + }); - yield proof( - 'Sequence::prepend()', - given( + yield $prove + ->proof('Sequence::prepend()') + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $first, $second) { + ) + ->test(static function($assert, $first, $second) { $assert->same( [...$first, ...$second], Sequence::of(...$second) @@ -65,16 +64,15 @@ static function($assert, $first, $second) { })) ->toList(), ); - }, - ); + }); - yield proof( - 'Sequence::chunk()', - given( + yield $prove + ->proof('Sequence::chunk()') + ->given( Set::strings()->atLeast(100), Set::integers()->between(1, 50), - ), - static function($assert, $string, $chunk) { + ) + ->test(static function($assert, $string, $chunk) { $chunks = Str::of($string, Str\Encoding::ascii) ->split() ->chunk($chunk); @@ -100,16 +98,15 @@ static function($assert, $string, $chunk) { ->fold(Concat::monoid) ->toString(), ); - }, - ); + }); - yield proof( - 'Sequende::defer() holds intermediary values even when no longer used', - given( + yield $prove + ->proof('Sequende::defer() holds intermediary values even when no longer used') + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $prefix, $suffix) { + ) + ->test(static function($assert, $prefix, $suffix) { $initial = Sequence::defer((static function() use ($prefix, $suffix) { foreach ($prefix as $value) { yield $value; @@ -142,13 +139,12 @@ static function($assert, $prefix, $suffix) { [...$prefix, ...$suffix], $another->toList(), ); - }, - ); + }); - yield proof( - "Sequence::defer() stack trace doesn't show intermediary sequences when not used", - given(Set::integers()->between(1, 10)), - static function($assert, $calls) { + yield $prove + ->proof("Sequence::defer() stack trace doesn't show intermediary sequences when not used") + ->given(Set::integers()->between(1, 10)) + ->test(static function($assert, $calls) { $expected = null; $sequence = Sequence::defer((static function() use (&$expected) { yield null; @@ -173,13 +169,12 @@ static function($assert, $calls) { $assert->count(1, $accumulations); } - }, - ); + }); - yield proof( - 'Sequence::sink()->until()', - given(Set::sequence(Set::type())), - static function($assert, $values) { + yield $prove + ->proof('Sequence::sink()->until()') + ->given(Set::sequence(Set::type())) + ->test(static function($assert, $values) { $all = Sequence::of(...$values) ->sink([]) ->until(static fn($all, $value, $continuation) => $continuation->continue( @@ -195,13 +190,12 @@ static function($assert, $values) { )); $assert->same([], $none); - }, - ); + }); - yield proof( - 'Sequence::sink()->until() when deferred', - given(Set::sequence(Set::type())), - static function($assert, $values) { + yield $prove + ->proof('Sequence::sink()->until() when deferred') + ->given(Set::sequence(Set::type())) + ->test(static function($assert, $values) { $all = Sequence::defer((static function() use ($values) { yield from $values; })()) @@ -221,16 +215,15 @@ static function($assert, $values) { )); $assert->same([], $none); - }, - ); + }); - yield proof( - "Sequence::sink()->until() when deferred doesn't load values after stop", - given( + yield $prove + ->proof("Sequence::sink()->until() when deferred doesn't load values after stop") + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $prefix, $suffix) { + ) + ->test(static function($assert, $prefix, $suffix) { $stop = new stdClass; $loaded = false; $all = Sequence::defer((static function() use ($prefix, $suffix, $stop, &$loaded) { @@ -249,13 +242,12 @@ static function($assert, $prefix, $suffix) { $assert->same($prefix, $all); $assert->false($loaded); - }, - ); + }); - yield proof( - 'Sequence::sink()->until() when lazy', - given(Set::sequence(Set::type())), - static function($assert, $values) { + yield $prove + ->proof('Sequence::sink()->until() when lazy') + ->given(Set::sequence(Set::type())) + ->test(static function($assert, $values) { $all = Sequence::lazy(static function() use ($values) { yield from $values; }) @@ -275,16 +267,15 @@ static function($assert, $values) { )); $assert->same([], $none); - }, - ); + }); - yield proof( - "Sequence::sink()->until() when lazy doesn't load values after stop", - given( + yield $prove + ->proof("Sequence::sink()->until() when lazy doesn't load values after stop") + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $prefix, $suffix) { + ) + ->test(static function($assert, $prefix, $suffix) { $stop = new stdClass; $loaded = false; $all = Sequence::lazy(static function() use ($prefix, $suffix, $stop, &$loaded) { @@ -303,16 +294,15 @@ static function($assert, $prefix, $suffix) { $assert->same($prefix, $all); $assert->false($loaded); - }, - ); + }); - yield proof( - 'Sequence::sink()->until() when lazy cleans up on stop', - given( + yield $prove + ->proof('Sequence::sink()->until() when lazy cleans up on stop') + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $prefix, $suffix) { + ) + ->test(static function($assert, $prefix, $suffix) { $stop = new stdClass; $cleaned = false; $all = Sequence::lazy(static function($register) use ($prefix, $suffix, $stop, &$cleaned) { @@ -333,16 +323,15 @@ static function($assert, $prefix, $suffix) { $assert->same($prefix, $all); $assert->true($cleaned); - }, - ); + }); - yield proof( - 'Sequence::sink()->maybe()', - given( + yield $prove + ->proof('Sequence::sink()->maybe()') + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $prefix, $suffix) { + ) + ->test(static function($assert, $prefix, $suffix) { $all = Sequence::of(...$prefix, ...$suffix) ->sink([]) ->maybe(static fn($all, $value) => Maybe::just( @@ -373,16 +362,15 @@ static function($assert, $prefix, $suffix) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Sequence::sink()->either()', - given( + yield $prove + ->proof('Sequence::sink()->either()') + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $prefix, $suffix) { + ) + ->test(static function($assert, $prefix, $suffix) { $all = Sequence::of(...$prefix, ...$suffix) ->sink([]) ->either(static fn($all, $value) => Either::right( @@ -414,16 +402,15 @@ static function($assert, $prefix, $suffix) { static fn($all) => $all, ), ); - }, - ); + }); - yield proof( - 'Sequence::sink()->attempt()', - given( + yield $prove + ->proof('Sequence::sink()->attempt()') + ->given( Set::sequence(Set::type()), Set::sequence(Set::type()), - ), - static function($assert, $prefix, $suffix) { + ) + ->test(static function($assert, $prefix, $suffix) { $all = Sequence::of(...$prefix, ...$suffix) ->sink([]) ->attempt(static fn($all, $value) => Attempt::result( @@ -455,15 +442,14 @@ static function($assert, $prefix, $suffix) { static fn($e) => $e, ), ); - }, - ); + }); - yield proof( - 'Sequence::lazy()->take() should not load an extra element', - given( + yield $prove + ->proof('Sequence::lazy()->take() should not load an extra element') + ->given( Set::sequence(Set::type()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $sequence = Sequence::lazy(static function() use ($values) { yield from $values; @@ -476,15 +462,14 @@ static function($assert, $values) { $sequence->toList(), ), ); - }, - ); + }); - yield proof( - 'Sequence::defer()->take() should not load an extra element', - given( + yield $prove + ->proof('Sequence::defer()->take() should not load an extra element') + ->given( Set::sequence(Set::type()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $sequence = Sequence::defer((static function() use ($values) { yield from $values; @@ -497,10 +482,9 @@ static function($assert, $values) { $sequence->toList(), ), ); - }, - ); + }); - yield test( + yield $prove->test( 'Partial load a deferred Sequence appended to a lazy one', static function($assert) { $lazy = Sequence::lazy(static function() { @@ -543,7 +527,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Sequence::defer()->zip() with a partially loaded lazy Sequence', static function($assert) { $defer = Sequence::defer((static function() { @@ -578,7 +562,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Lazy Sequence::toSet()', static function($assert) { $loaded = false; @@ -596,7 +580,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Deferred Sequence::filter() is iterable twice', static function($assert) { $defer = Sequence::defer((static function() { @@ -613,7 +597,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Consuming out of order deferred sequences', static function($assert) { $source = Sequence::defer((static function() { @@ -627,7 +611,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Calling first inside a lazy Sequence::flatMap()', static function($assert) { $lazy = Sequence::lazy(static function() { @@ -645,10 +629,10 @@ static function($assert) { }, ); - yield proof( - 'Sequence::aggregate() should not alter the initial Sequence by default', - given(Set::sequence(Set::type())), - static function($assert, $values) { + yield $prove + ->proof('Sequence::aggregate() should not alter the initial Sequence by default') + ->given(Set::sequence(Set::type())) + ->test(static function($assert, $values) { $inMemory = Sequence::of(...$values); $assert->same( @@ -679,17 +663,16 @@ static function($assert, $values) { ->aggregate(static fn($a, $b) => Sequence::of($a, $b)) ->toList(), ); - }, - ); + }); - yield proof( - 'Sequence::snap() loads a lazy sequence only once', - given( + yield $prove + ->proof('Sequence::snap() loads a lazy sequence only once') + ->given( Set::type(), Set::sequence(Set::type()), Set::type(), - ), - static function($assert, $value, $rest, $last) { + ) + ->test(static function($assert, $value, $rest, $last) { $loaded = 0; $sequence = Sequence::lazy(static function() use (&$loaded, $value, $rest, $last) { yield $value; @@ -718,17 +701,16 @@ static function($assert, $value, $rest, $last) { ), ); $assert->same(1, $loaded); - }, - ); + }); - yield proof( - 'Sequence::snap() keeps in memory intermediary steps', - given( + yield $prove + ->proof('Sequence::snap() keeps in memory intermediary steps') + ->given( Set::type(), Set::sequence(Set::type()), Set::type(), - ), - static function($assert, $value, $rest, $last) { + ) + ->test(static function($assert, $value, $rest, $last) { $loaded = 0; $snapped = Sequence::lazy(static function() use (&$loaded, $value, $rest, $last) { yield $value; @@ -765,17 +747,16 @@ static function($assert, $value, $rest, $last) { ), ); $assert->same(1, $loaded); - }, - ); + }); - yield proof( - 'Sequence::snap() loads a deferred sequence at once', - given( + yield $prove + ->proof('Sequence::snap() loads a deferred sequence at once') + ->given( Set::type(), Set::sequence(Set::type()), Set::type(), - ), - static function($assert, $value, $rest, $last) { + ) + ->test(static function($assert, $value, $rest, $last) { $loaded = 0; $sequence = Sequence::defer((static function() use (&$loaded, $value, $rest, $last) { yield $value; @@ -804,12 +785,11 @@ static function($assert, $value, $rest, $last) { ), ); $assert->same(1, $loaded); - }, - ); + }); - yield proof( - 'Sequence::via()', - given( + yield $prove + ->proof('Sequence::via()') + ->given( Set::sequence(Set::type()), Set::of( static fn(array $values) => Sequence::of(...$values), @@ -821,8 +801,8 @@ static function($assert, $value, $rest, $last) { ), ), Set::sequence(Set::type()), - ), - static function($assert, $initial, $build, $new) { + ) + ->test(static function($assert, $initial, $build, $new) { $sequence = $build($initial); $sequence2 = $sequence->via(static function($sequence) use ($assert, $initial, $build, $new) { $assert->same($initial, $sequence->toList()); @@ -831,12 +811,11 @@ static function($assert, $initial, $build, $new) { }); $assert->same($new, $sequence2->toList()); - }, - ); + }); - yield proof( - "Sequence::via() doesn't load underlying generators", - given( + yield $prove + ->proof("Sequence::via() doesn't load underlying generators") + ->given( Set::sequence(Set::type()), Set::of( static fn(bool &$loaded, array $values) => Sequence::defer( @@ -852,23 +831,22 @@ static function() use (&$loaded, $values) { }, ), ), - ), - static function($assert, $initial, $build) { + ) + ->test(static function($assert, $initial, $build) { $loaded = false; $sequence = $build($loaded, $initial); $sequence2 = $sequence->via(static fn($sequence) => $sequence); $assert->false($loaded); $assert->same($initial, $sequence2->toList()); - }, - ); + }); - yield proof( - 'Sequence::via() on a lazy sequence calls the function everytime the sequence is unwrapped', - given( + yield $prove + ->proof('Sequence::via() on a lazy sequence calls the function everytime the sequence is unwrapped') + ->given( Set::sequence(Set::type()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $loaded = 0; $sequence = Sequence::lazy( static fn() => yield from $values, @@ -884,15 +862,14 @@ static function($assert, $values) { $assert->same(1, $loaded); $assert->same($values, $sequence2->toList()); $assert->same(2, $loaded); - }, - ); + }); - yield proof( - 'Sequence::lazy()->snap()->via() loads the generator once', - given( + yield $prove + ->proof('Sequence::lazy()->snap()->via() loads the generator once') + ->given( Set::sequence(Set::type()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $loaded = 0; $sequence = Sequence::lazy( static fn() => yield from $values, @@ -910,15 +887,14 @@ static function($assert, $values) { $assert->same(1, $loaded); $assert->same($values, $sequence2->toList()); $assert->same(1, $loaded); - }, - ); + }); - yield proof( - 'Sequence::lazy()->snap()->via() loads the initial snapped sequence only once', - given( + yield $prove + ->proof('Sequence::lazy()->snap()->via() loads the initial snapped sequence only once') + ->given( Set::sequence(Set::type()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $loaded = 0; $sequence = Sequence::lazy( static function() use ($values, &$loaded) { @@ -935,13 +911,12 @@ static function() use ($values, &$loaded) { $assert->same(1, $loaded); $assert->same($values, $sequence->toList()); $assert->same(1, $loaded); - }, - ); + }); - yield proof( - 'Sequence->snap()->toSet()', - given( - Set::sequence(Set\Integers::any()), + yield $prove + ->proof('Sequence->snap()->toSet()') + ->given( + Set::sequence(Set::integers()), Set::of( static fn(array $values) => Sequence::of(...$values), static fn(array $values) => Sequence::defer( @@ -951,8 +926,8 @@ static function() use ($values, &$loaded) { static fn() => yield from $values, ), ), - ), - static function($assert, $values, $build) { + ) + ->test(static function($assert, $values, $build) { $assert->same( \array_unique($values), $build($values) @@ -960,15 +935,14 @@ static function($assert, $values, $build) { ->toSet() ->toList(), ); - }, - ); + }); - yield proof( - 'Sequence::lazy()->snap()->toSet() only load the generator once', - given( + yield $prove + ->proof('Sequence::lazy()->snap()->toSet() only load the generator once') + ->given( Set::sequence(Set::integers()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $loaded = 0; $sequence = Sequence::lazy(static function() use ($values, &$loaded) { yield from $values; @@ -983,15 +957,14 @@ static function($assert, $values) { $assert->same(1, $loaded); $assert->same($values, $sequence->toList()); $assert->same(1, $loaded); - }, - ); + }); - yield proof( - 'Sequence::lazy()->snap() should not keep the original sequence when no longer used', - given( + yield $prove + ->proof('Sequence::lazy()->snap() should not keep the original sequence when no longer used') + ->given( Set::sequence(Set::integers()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $beacon = new stdClass; $sequence = Sequence::lazy(static function() use ($values, $beacon) { yield from $values; @@ -1002,15 +975,14 @@ static function($assert, $values) { $assert->same($values, $sequence->toList()); $assert->null($beacon->get()); $assert->same($values, $sequence->toList()); - }, - ); + }); - yield proof( - 'Sequence::lazy()->snap()->toSet() should keep values in memory', - given( + yield $prove + ->proof('Sequence::lazy()->snap()->toSet() should keep values in memory') + ->given( Set::sequence(Set::integers()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $set = Sequence::lazy(static fn() => yield from $values) ->snap() ->toSet() @@ -1020,13 +992,12 @@ static function($assert, $values) { $set->toList(), $set->toList(), ); - }, - ); + }); - yield proof( - 'Sequence::equals() should not load its data when compared to itself', - given(Set::sequence(Set::type())), - static function($assert, $values) { + yield $prove + ->proof('Sequence::equals() should not load its data when compared to itself') + ->given(Set::sequence(Set::type())) + ->test(static function($assert, $values) { $loaded = false; $sequence = Sequence::lazy(static function() use (&$loaded, $values) { $loaded = true; @@ -1036,10 +1007,9 @@ static function($assert, $values) { $assert->true($sequence->equals($sequence)); $assert->false($loaded); - }, - ); + }); - yield test( + yield $prove->test( 'Sequence::union()', static function($assert) { $assert->same( @@ -1097,27 +1067,27 @@ static function($assert) { $values = Set::sequence(Set::type()); $sequences = Set::either( - $values->map(static fn($values) => Sequence::of(...$values)), + $values->map(static fn($values) => static fn() => Sequence::of(...$values)), $values->map( - static fn($values) => Sequence::lazy( + static fn($values) => static fn() => Sequence::lazy( static fn() => yield from $values, ), ), $values->map( - static fn($values) => Sequence::defer( + static fn($values) => static fn() => Sequence::defer( (static fn() => yield from $values)(), ), ), ); - yield properties( + yield $prove->properties( 'Sequence', Properties::properties(), $sequences, ); foreach (Properties::list() as $property) { - yield property( + yield $prove->property( $property, $sequences, ); diff --git a/proofs/set.php b/proofs/set.php index a60743ea..fe21c034 100644 --- a/proofs/set.php +++ b/proofs/set.php @@ -7,15 +7,16 @@ }; use Innmind\BlackBox\Set as DataSet; -return static function() { - yield proof( - 'Set::match()', - given( +return static function($prove) { + yield $prove + ->proof('Set::match()') + ->given( DataSet::type(), DataSet::sequence(DataSet::type()) ->map(static fn($values) => Sequence::of(...$values)->distinct()->toList()), - )->filter(static fn($first, $rest) => !\in_array($first, $rest, true)), - static function($assert, $first, $rest) { + ) + ->filter(static fn($first, $rest) => !\in_array($first, $rest, true)) + ->test(static function($assert, $first, $rest) { $assert->same( $first, Set::of()->match( @@ -32,15 +33,14 @@ static function($assert, $first, $rest) { $assert->not()->null($packed); $assert->same($first, $packed[0]); $assert->same($rest, $packed[1]->toList()); - }, - ); + }); - yield proof( - 'Set::unsorted()', - given( + yield $prove + ->proof('Set::unsorted()') + ->given( DataSet::sequence(DataSet::type()), - ), - static function($assert, $values) { + ) + ->test(static function($assert, $values) { $set = Set::of(...$values); $sequence = $set->unsorted(); @@ -50,10 +50,9 @@ static function($assert, $values) { $assert->true( $set->matches($sequence->contains(...)), ); - }, - ); + }); - yield test( + yield $prove->test( 'Set defer nesting calls', static function($assert) { $set = Set::lazy(static function() { @@ -104,7 +103,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Set nesting calls', static function($assert) { $set = Set::of(1, 2, 3); @@ -151,7 +150,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Set defer partial nesting calls', static function($assert) { $set = Set::lazy(static function() { @@ -179,13 +178,14 @@ static function($assert) { }, ); - yield proof( - 'Set::snap() loads a lazy set only once', - given( + yield $prove + ->proof('Set::snap() loads a lazy set only once') + ->given( DataSet::type(), DataSet::sequence(DataSet::type()), - )->filter(static fn($value, $rest) => !\in_array($value, $rest, true)), - static function($assert, $value, $rest) { + ) + ->filter(static fn($value, $rest) => !\in_array($value, $rest, true)) + ->test(static function($assert, $value, $rest) { $loaded = 0; $sequence = Set::lazy(static function() use (&$loaded, $value, $rest) { yield $value; @@ -213,13 +213,12 @@ static function($assert, $value, $rest) { ), ); $assert->same(1, $loaded); - }, - ); + }); - yield proof( - 'Set::equals() should not load its data when compared to itself', - given(DataSet::sequence(DataSet::type())), - static function($assert, $values) { + yield $prove + ->proof('Set::equals() should not load its data when compared to itself') + ->given(DataSet::sequence(DataSet::type())) + ->test(static function($assert, $values) { $loaded = false; $set = Set::lazy(static function() use (&$loaded, $values) { $loaded = true; @@ -229,6 +228,5 @@ static function($assert, $values) { $assert->true($set->equals($set)); $assert->false($loaded); - }, - ); + }); }; diff --git a/proofs/validation.php b/proofs/validation.php index d6ffa234..1199322a 100644 --- a/proofs/validation.php +++ b/proofs/validation.php @@ -4,11 +4,11 @@ use Innmind\Immutable\Validation; use Innmind\BlackBox\Set; -return static function() { - yield proof( - 'Validation::match()', - given(Set::type()), - static function($assert, $value) { +return static function($prove) { + yield $prove + ->proof('Validation::match()') + ->given(Set::type()) + ->test(static function($assert, $value) { $assert->same( $value, Validation::success($value)->match( @@ -23,16 +23,15 @@ static function($assert, $value) { static fn($value) => $value->toList(), ), ); - }, - ); + }); - yield proof( - 'Validation::map()', - given( + yield $prove + ->proof('Validation::map()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $initial, $new) { + ) + ->test(static function($assert, $initial, $new) { $assert->same( [$initial, $new], Validation::success($initial) @@ -50,16 +49,15 @@ static function($assert, $initial, $new) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Validation::flatMap()', - given( + yield $prove + ->proof('Validation::flatMap()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $initial, $new) { + ) + ->test(static function($assert, $initial, $new) { $assert->same( [$initial, $new], Validation::success($initial) @@ -86,16 +84,15 @@ static function($assert, $initial, $new) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Validation::mapFailures()', - given( + yield $prove + ->proof('Validation::mapFailures()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $initial, $new) { + ) + ->test(static function($assert, $initial, $new) { $assert->same( [[$initial, $new]], Validation::fail($initial) @@ -113,16 +110,15 @@ static function($assert, $initial, $new) { static fn($value) => $value->toList(), ), ); - }, - ); + }); - yield proof( - 'Validation::otherwise()', - given( + yield $prove + ->proof('Validation::otherwise()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $initial, $new) { + ) + ->test(static function($assert, $initial, $new) { $assert->null( Validation::success($initial) ->otherwise(static fn($value) => Validation::success([$value, $new])) @@ -149,13 +145,12 @@ static function($assert, $initial, $new) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Validation::maybe()', - given(Set::type()), - static function($assert, $value) { + yield $prove + ->proof('Validation::maybe()') + ->given(Set::type()) + ->test(static function($assert, $value) { $assert->same( $value, Validation::success($value) @@ -173,13 +168,12 @@ static function($assert, $value) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Validation::either()', - given(Set::type()), - static function($assert, $value) { + yield $prove + ->proof('Validation::either()') + ->given(Set::type()) + ->test(static function($assert, $value) { $assert->same( $value, Validation::success($value) @@ -198,16 +192,15 @@ static function($assert, $value) { static fn($value) => $value->toList(), ), ); - }, - ); + }); - yield proof( - 'Validation::and()', - given( + yield $prove + ->proof('Validation::and()') + ->given( Set::type(), Set::type(), - ), - static function($assert, $a, $b) { + ) + ->test(static function($assert, $a, $b) { $success = Validation::success($a); $fail = Validation::fail($b); @@ -259,17 +252,16 @@ static function($assert, $a, $b) { static fn($value) => $value->toList(), ), ); - }, - ); + }); - yield proof( - 'Validation::guard()', - given( + yield $prove + ->proof('Validation::guard()') + ->given( Set::integers()->above(1), Set::integers()->below(-1), Set::type(), - ), - static function($assert, $positive, $negative, $fail) { + ) + ->test(static function($assert, $positive, $negative, $fail) { $assert->same( $positive, Validation::success($positive) @@ -313,16 +305,15 @@ static function($assert, $positive, $negative, $fail) { static fn($failures) => $failures->toList(), ), ); - }, - ); + }); - yield proof( - 'Validation::attempt()', - given( + yield $prove + ->proof('Validation::attempt()') + ->given( Set::type(), Set::sequence(Set::type())->atLeast(1), - ), - static function($assert, $success, $errors) { + ) + ->test(static function($assert, $success, $errors) { $assert->same( $success, Validation::success($success) @@ -355,6 +346,5 @@ static function($assert, $success, $errors) { static fn($e) => $e, ), ); - }, - ); + }); }; diff --git a/properties/Monoid.php b/properties/Monoid.php index 00e19cc4..f72c4da9 100644 --- a/properties/Monoid.php +++ b/properties/Monoid.php @@ -20,7 +20,7 @@ final class Monoid */ public static function properties(Set $values, callable $equals): Set { - return Set\Properties::any(...self::list($values, $equals))->atMost(10); + return Set::properties(...self::list($values, $equals))->atMost(10); } /** diff --git a/properties/Monoid/Associativity.php b/properties/Monoid/Associativity.php index b4d98f0f..6838ce66 100644 --- a/properties/Monoid/Associativity.php +++ b/properties/Monoid/Associativity.php @@ -50,9 +50,9 @@ public static function any(): Set * @param Set $values * @param callable(A, A): bool $equals * - * @return Set\Provider> + * @return Set> */ - public static function of(Set $values, callable $equals): Set\Provider + public static function of(Set $values, callable $equals): Set { return Set::compose( static fn($a, $b, $c) => new self($a, $b, $c, $equals), diff --git a/properties/Sequence.php b/properties/Sequence.php index 8d833d9b..2d73a54a 100644 --- a/properties/Sequence.php +++ b/properties/Sequence.php @@ -19,7 +19,7 @@ final class Sequence */ public static function properties(): Set|Set\Provider { - return Set\Properties::any( + return Set::properties( ...\array_map( static fn($class) => $class::any(), self::list(), diff --git a/properties/Sequence/LookupFirstAttempt.php b/properties/Sequence/LookupFirstAttempt.php index fc6fc110..0840ca6b 100644 --- a/properties/Sequence/LookupFirstAttempt.php +++ b/properties/Sequence/LookupFirstAttempt.php @@ -25,7 +25,7 @@ private function __construct( ) { } - public static function any(): Set\Provider + public static function any(): Set { return Set::compose( static fn(...$args) => new self(...$args), diff --git a/properties/Sequence/LookupFirstEither.php b/properties/Sequence/LookupFirstEither.php index 6347e3cd..cd3f9ac3 100644 --- a/properties/Sequence/LookupFirstEither.php +++ b/properties/Sequence/LookupFirstEither.php @@ -26,7 +26,7 @@ private function __construct( ) { } - public static function any(): Set\Provider + public static function any(): Set { return Set::compose( static fn(...$args) => new self(...$args), diff --git a/properties/Sequence/LookupFirstMaybe.php b/properties/Sequence/LookupFirstMaybe.php index a535b940..6495ed09 100644 --- a/properties/Sequence/LookupFirstMaybe.php +++ b/properties/Sequence/LookupFirstMaybe.php @@ -25,7 +25,7 @@ private function __construct( ) { } - public static function any(): Set\Provider + public static function any(): Set { return Set::compose( static fn(...$args) => new self(...$args), diff --git a/properties/Sequence/LookupLastAttempt.php b/properties/Sequence/LookupLastAttempt.php index fb7ee477..28f360b0 100644 --- a/properties/Sequence/LookupLastAttempt.php +++ b/properties/Sequence/LookupLastAttempt.php @@ -25,7 +25,7 @@ private function __construct( ) { } - public static function any(): Set\Provider + public static function any(): Set { return Set::compose( static fn(...$args) => new self(...$args), diff --git a/properties/Sequence/LookupLastEither.php b/properties/Sequence/LookupLastEither.php index 5f4f61cd..4c6d8d53 100644 --- a/properties/Sequence/LookupLastEither.php +++ b/properties/Sequence/LookupLastEither.php @@ -26,7 +26,7 @@ private function __construct( ) { } - public static function any(): Set\Provider + public static function any(): Set { return Set::compose( static fn(...$args) => new self(...$args), diff --git a/properties/Sequence/LookupLastMaybe.php b/properties/Sequence/LookupLastMaybe.php index 81fa5287..d2b1a111 100644 --- a/properties/Sequence/LookupLastMaybe.php +++ b/properties/Sequence/LookupLastMaybe.php @@ -25,7 +25,7 @@ private function __construct( ) { } - public static function any(): Set\Provider + public static function any(): Set { return Set::compose( static fn(...$args) => new self(...$args), diff --git a/tests/Fixtures/SetTest.php b/tests/Fixtures/SetTest.php index c0475e57..8be15700 100644 --- a/tests/Fixtures/SetTest.php +++ b/tests/Fixtures/SetTest.php @@ -35,7 +35,7 @@ public function testGenerate(): BlackBox\Proof DataSet::strings() ->madeOf(DataSet::strings()->chars()) ->between(1, 2), - DataSet\Integers::between(0, 5), + DataSet::integers()->between(0, 5), )) ->prove(function($set) { $this->assertInstanceOf(Structure::class, $set); diff --git a/tests/RegExpTest.php b/tests/RegExpTest.php index a7c609b0..2649ef19 100644 --- a/tests/RegExpTest.php +++ b/tests/RegExpTest.php @@ -30,9 +30,12 @@ public function testOf() public function testThrowWhenInvalidRegexp() { - $this->expectException(LogicException::class); - - $_ = RegExp::of('/foo'); + $this + ->assert() + ->throws( + static fn() => RegExp::of('/foo'), + LogicException::class, + ); } public function testMatches() From aadfe90ccc244550fafc4216305e4516de620895 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 14 May 2026 15:40:12 +0200 Subject: [PATCH 2/2] fix use of removed method --- blackbox.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blackbox.php b/blackbox.php index 103a6a5d..8e3e8f2a 100644 --- a/blackbox.php +++ b/blackbox.php @@ -19,8 +19,7 @@ __DIR__.'/proofs/', __DIR__.'/fixtures/', ) - ->dumpTo('coverage.clover') - ->enableWhen(true), + ->dumpTo('coverage.clover'), ) ->scenariiPerProof(50), default => $app,