diff --git a/CHANGELOG.md b/CHANGELOG.md index e5ff2b5..a533b86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires PHP `8.5` +- Requires `innmind/black-box:~7.0` + ## 4.1.1 - 2026-04-09 ### Fixed diff --git a/blackbox.php b/blackbox.php index c109cd0..18d7970 100644 --- a/blackbox.php +++ b/blackbox.php @@ -8,28 +8,25 @@ Runner\Load, Runner\CodeCoverage, PHPUnit, + Prove, }; Application::new($argv) - ->when( - \getenv('BLACKBOX_SET_SIZE') !== false, - static fn(Application $app) => $app->scenariiPerProof((int) \getenv('BLACKBOX_SET_SIZE')), - ) - ->when( - \getenv('ENABLE_COVERAGE') !== false, - static fn(Application $app) => $app + ->map(static fn($app) => match (\getenv('BLACKBOX_ENV')) { + 'extensive' => $app->scenariiPerProof(1_000), + 'coverage' => $app ->codeCoverage( CodeCoverage::of( __DIR__.'/src/', __DIR__.'/tests/', __DIR__.'/proofs/', ) - ->dumpTo('coverage.clover') - ->enableWhen(true), + ->dumpTo('coverage.clover'), ), - ) - ->tryToProve(static function() { + default => $app, + }) + ->tryToProve(static function(Prove $prove) { yield from PHPUnit\Load::testsAt(__DIR__.'/tests/'); - yield from Load::everythingIn(__DIR__.'/proofs/')(); + yield from Load::everythingIn(__DIR__.'/proofs/')($prove); }) ->exit(); diff --git a/composer.json b/composer.json index 72978a7..1b867e4 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "issues": "http://github.com/innmind/io/issues" }, "require": { - "php": "~8.4", + "php": "~8.5", "innmind/immutable": "~6.0", "innmind/mutable": "~1.0", "innmind/url": "~5.0", @@ -35,7 +35,7 @@ }, "require-dev": { "innmind/static-analysis": "~1.3", - "innmind/black-box": "~6.1", + "innmind/black-box": "~7.0", "innmind/coding-standard": "~2.0" } } diff --git a/proofs/files.php b/proofs/files.php index aab248e..ee63b36 100644 --- a/proofs/files.php +++ b/proofs/files.php @@ -14,9 +14,12 @@ Monoid\Concat, SideEffect, }; -use Innmind\BlackBox\Set; +use Innmind\BlackBox\{ + Set, + Prove, +}; -return static function() { +return static function(Prove $prove) { // Here we make sure to only use characters that are "reversible". Writing // and then reading should return the exact same character. $string = Set::strings()->madeOf( @@ -34,13 +37,13 @@ Set::sequence($string)->between(0, 20), ); - yield proof( - 'IO::files()->read()->chunks()', - given( + yield $prove + ->proof('IO::files()->read()->chunks()') + ->given( $strings, Set::integers()->between(1, 100), - ), - static function($assert, $chunks, $size) { + ) + ->test(static function($assert, $chunks, $size) { $tmp = \tempnam(\sys_get_temp_dir(), 'innmind/io'); $data = \implode('', $chunks); \file_put_contents($tmp, $data); @@ -75,17 +78,16 @@ static function($assert, $chunks, $size) { ->fold(Concat::monoid) ->toString(), ); - }, - ); + }); - yield proof( - 'IO::files()->read()->toEncoding()->chunks()', - given( + yield $prove + ->proof('IO::files()->read()->toEncoding()->chunks()') + ->given( $strings, Set::integers()->between(1, 100), Set::of(...Str\Encoding::cases()), - ), - static function($assert, $chunks, $size, $encoding) { + ) + ->test(static function($assert, $chunks, $size, $encoding) { $tmp = \tempnam(\sys_get_temp_dir(), 'innmind/io'); $data = \implode('', $chunks); \file_put_contents($tmp, $data); @@ -99,12 +101,11 @@ static function($assert, $chunks, $size, $encoding) { $encoding, $chunk->encoding(), )); - }, - ); + }); - yield proof( - 'IO::files()->read()->lines()', - given( + yield $prove + ->proof('IO::files()->read()->lines()') + ->given( Set::either( Set::sequence($string->between(0, 20)->filter( static fn($line) => !\str_contains($line, "\n"), @@ -113,8 +114,8 @@ static function($assert, $chunks, $size, $encoding) { static fn($line) => !\str_contains($line, "\n"), ))->between(0, 20), ), - ), - static function($assert, $lines) { + ) + ->test(static function($assert, $lines) { $tmp = \tempnam(\sys_get_temp_dir(), 'innmind/io'); $data = \implode("\n", $lines); \file_put_contents($tmp, $data); @@ -161,16 +162,15 @@ static function($assert, $lines) { ->map(static fn($line) => $line->toString()) ->toList(), ); - }, - ); + }); - yield proof( - 'IO::files()->read()->toEncoding()->lines()', - given( + yield $prove + ->proof('IO::files()->read()->toEncoding()->lines()') + ->given( $strings, Set::of(...Str\Encoding::cases()), - ), - static function($assert, $lines, $encoding) { + ) + ->test(static function($assert, $lines, $encoding) { $tmp = \tempnam(\sys_get_temp_dir(), 'innmind/io'); $data = \implode("\n", $lines); \file_put_contents($tmp, $data); @@ -184,13 +184,12 @@ static function($assert, $lines, $encoding) { $encoding, $line->encoding(), )); - }, - ); + }); - yield proof( - 'IO::files()->read()->size()', - given($strings), - static function($assert, $chunks) { + yield $prove + ->proof('IO::files()->read()->size()') + ->given($strings) + ->test(static function($assert, $chunks) { $tmp = \tempnam(\sys_get_temp_dir(), 'innmind/io'); $data = \implode('', $chunks); \file_put_contents($tmp, $data); @@ -208,16 +207,15 @@ static function($assert, $chunks) { ->number($size) ->int(); $assert->same(\strlen($data), $size); - }, - ); + }); - yield proof( - 'IO::files()->write()->sink()', - given( + yield $prove + ->proof('IO::files()->write()->sink()') + ->given( $strings, Set::of(...Str\Encoding::cases()), - ), - static function($assert, $chunks, $encoding) { + ) + ->test(static function($assert, $chunks, $encoding) { $tmp = \tempnam(\sys_get_temp_dir(), 'innmind/io'); $sideEffect = IO::fromAmbientAuthority() @@ -240,16 +238,15 @@ static function($assert, $chunks, $encoding) { \implode('', $chunks), \file_get_contents($tmp), ); - }, - ); + }); - yield proof( - 'IO::files()->write()->watch()->sink()', - given( + yield $prove + ->proof('IO::files()->write()->watch()->sink()') + ->given( $strings, Set::of(...Str\Encoding::cases()), - ), - static function($assert, $chunks, $encoding) { + ) + ->test(static function($assert, $chunks, $encoding) { $tmp = \tempnam(\sys_get_temp_dir(), 'innmind/io'); $sideEffect = IO::fromAmbientAuthority() @@ -273,13 +270,12 @@ static function($assert, $chunks, $encoding) { \implode('', $chunks), \file_get_contents($tmp), ); - }, - ); + }); - yield proof( - 'IO::files()->temporary()->read()', - given($strings), - static function($assert, $chunks) { + yield $prove + ->proof('IO::files()->temporary()->read()') + ->given($strings) + ->test(static function($assert, $chunks) { $read = IO::fromAmbientAuthority() ->files() ->temporary(Sequence::of(...$chunks)->map(Str::of(...))) @@ -309,17 +305,16 @@ static function($assert, $chunks) { ->toString(), 'Temporary file should be accessible multiple times', ); - }, - ); + }); - yield proof( - 'IO::files()->temporary()->pull()', - given( + yield $prove + ->proof('IO::files()->temporary()->pull()') + ->given( $strings, Set::integers()->between(1, 100), Set::of(...Str\Encoding::cases()), - ), - static function($assert, $chunks, $size, $encoding) { + ) + ->test(static function($assert, $chunks, $size, $encoding) { $pull = IO::fromAmbientAuthority() ->files() ->temporary(Sequence::of(...$chunks)->map(Str::of(...))) @@ -349,16 +344,15 @@ static function($assert, $chunks, $size, $encoding) { $expected, $read, ); - }, - ); + }); - yield proof( - 'IO::files()->temporary()->push()', - given( + yield $prove + ->proof('IO::files()->temporary()->push()') + ->given( $strings, Set::of(...Str\Encoding::cases()), - ), - static function($assert, $chunks, $encoding) { + ) + ->test(static function($assert, $chunks, $encoding) { $tmp = IO::fromAmbientAuthority() ->files() ->temporary(Sequence::of()) @@ -389,13 +383,12 @@ static function($assert, $chunks, $encoding) { ->fold(Concat::monoid) ->toString(), ); - }, - ); + }); - yield proof( - 'IO::files()->temporary()->close()', - given($strings), - static function($assert, $chunks) { + yield $prove + ->proof('IO::files()->temporary()->close()') + ->given($strings) + ->test(static function($assert, $chunks) { $tmp = IO::fromAmbientAuthority() ->files() ->temporary(Sequence::of(...$chunks)->map(Str::of(...))) @@ -428,10 +421,9 @@ static function($assert, $chunks) { static fn() => null, ), ); - }, - ); + }); - yield test( + yield $prove->test( 'IO::files()->require()', static function($assert) { $assert->same( diff --git a/proofs/frames.php b/proofs/frames.php index 066d192..9e3d0a8 100644 --- a/proofs/frames.php +++ b/proofs/frames.php @@ -14,9 +14,12 @@ Sequence, Predicate, }; -use Innmind\BlackBox\Set; +use Innmind\BlackBox\{ + Set, + Prove, +}; -return static function() { +return static function(Prove $prove) { $reader = static function(Str $data) { $tmp = \tmpfile(); \fwrite($tmp, $data->toString()); @@ -28,15 +31,15 @@ ); }; - yield proof( - 'Frame::just()', - given( + yield $prove + ->proof('Frame::just()') + ->given( Set::type(), Set::strings() ->unicode() ->map(Str::of(...)), - ), - static function($assert, $value, $read) use ($reader) { + ) + ->test(static function($assert, $value, $read) use ($reader) { $frame = Frame::just($value); $assert->same( @@ -46,18 +49,17 @@ static function($assert, $value, $read) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::maybe()', - given( + yield $prove + ->proof('Frame::maybe()') + ->given( Set::type(), Set::strings() ->unicode() ->map(Str::of(...)), - ), - static function($assert, $value, $read) use ($reader) { + ) + ->test(static function($assert, $value, $read) use ($reader) { $frame = Frame::maybe(Maybe::just($value)); $assert->same( @@ -67,17 +69,16 @@ static function($assert, $value, $read) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::maybe() nothing', - given( + yield $prove + ->proof('Frame::maybe() nothing') + ->given( Set::strings() ->unicode() ->map(Str::of(...)), - ), - static function($assert, $read) use ($reader) { + ) + ->test(static function($assert, $read) use ($reader) { $frame = Frame::maybe(Maybe::nothing()); $assert->null( @@ -86,18 +87,17 @@ static function($assert, $read) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::chunk()', - given( + yield $prove + ->proof('Frame::chunk()') + ->given( Set::strings() ->unicode() ->map(Str::of(...)) ->map(static fn($str) => $str->toEncoding(Str\Encoding::ascii)), - ), - static function($assert, $string) use ($reader) { + ) + ->test(static function($assert, $string) use ($reader) { $size = $string->length(); $frame = Frame::chunk($size)->loose(); @@ -108,18 +108,17 @@ static function($assert, $string) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::line()', - given( + yield $prove + ->proof('Frame::line()') + ->given( Set::strings() ->unicode() ->filter(static fn($string) => !\str_contains($string, "\n")) ->map(Str::of(...)), - ), - static function($assert, $string) use ($reader) { + ) + ->test(static function($assert, $string) use ($reader) { $frame = Frame::line(); $assert->same( @@ -129,18 +128,17 @@ static function($assert, $string) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::sequence()', - given(Set::sequence( + yield $prove + ->proof('Frame::sequence()') + ->given(Set::sequence( Set::strings() ->unicode() ->atLeast(1) ->filter(static fn($string) => !\str_contains($string, "\n")), - )), - static function($assert, $lines) use ($reader) { + )) + ->test(static function($assert, $lines) use ($reader) { $frame = Frame::sequence(Frame::line()); $data = \implode("\n", $lines); @@ -169,18 +167,17 @@ static function($assert, $lines) use ($reader) { ->map(static fn($line) => $line->rightTrim("\n")->toString()) ->toList(), ); - }, - ); + }); - yield proof( - 'Frame::filter()', - given( + yield $prove + ->proof('Frame::filter()') + ->given( Set::strings() ->unicode() ->map(Str::of(...)) ->map(static fn($string) => $string->toEncoding(Str\Encoding::ascii)), - ), - static function($assert, $string) use ($reader) { + ) + ->test(static function($assert, $string) use ($reader) { $frame = Frame::chunk($string->length())->strict(); $assert->same( @@ -200,18 +197,17 @@ static function($assert, $string) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::keep()', - given( + yield $prove + ->proof('Frame::keep()') + ->given( Set::strings() ->unicode() ->map(Str::of(...)) ->map(static fn($string) => $string->toEncoding(Str\Encoding::ascii)), - ), - static function($assert, $string) use ($reader) { + ) + ->test(static function($assert, $string) use ($reader) { $frame = Frame::chunk($string->length())->strict(); $assert->same( @@ -231,12 +227,11 @@ static function($assert, $string) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::buffer()', - given( + yield $prove + ->proof('Frame::buffer()') + ->given( Set::strings() ->unicode() ->atLeast(1) @@ -247,8 +242,8 @@ static function($assert, $string) use ($reader) { ->map(Str::of(...)) ->map(static fn($string) => $string->toEncoding(Str\Encoding::ascii)), Set::integers()->between(1, 100), - ), - static function($assert, $a, $b, $size) use ($reader) { + ) + ->test(static function($assert, $a, $b, $size) use ($reader) { $frame = Frame::buffer( $a->length(), Frame::chunk($size)->loose(), @@ -266,19 +261,18 @@ static function($assert, $a, $b, $size) use ($reader) { static fn() => null, ), ); - }, - ); + }); - yield proof( - 'Frame::buffer() fails when not used with a fixed size frame', - given( + yield $prove + ->proof('Frame::buffer() fails when not used with a fixed size frame') + ->given( Set::strings() ->unicode() ->atLeast(1) ->map(Str::of(...)) ->map(static fn($string) => $string->toEncoding(Str\Encoding::ascii)), - ), - static function($assert, $a) use ($reader) { + ) + ->test(static function($assert, $a) use ($reader) { $frame = Frame::buffer( $a->length(), Frame::line(), @@ -287,15 +281,14 @@ static function($assert, $a) use ($reader) { $assert->throws( static fn() => $frame($reader($a)), ); - }, - ); + }); - yield proof( - 'Frame::compose()', - given( + yield $prove + ->proof('Frame::compose()') + ->given( Set::sequence(Set::strings())->atLeast(1), - ), - static function($assert, $chunks) use ($reader) { + ) + ->test(static function($assert, $chunks) use ($reader) { $frame = Frame::compose( static fn(...$chunks) => $chunks, ...\array_map( @@ -314,6 +307,5 @@ static function($assert, $chunks) use ($reader) { static fn($e) => $e, ), ); - }, - ); + }); }; diff --git a/proofs/sockets.php b/proofs/sockets.php index 1b7fa0d..01b41c7 100644 --- a/proofs/sockets.php +++ b/proofs/sockets.php @@ -12,9 +12,10 @@ Sequence, Str, }; +use Innmind\BlackBox\Prove; -return static function() { - yield test( +return static function(Prove $prove) { + yield $prove->test( 'IO::fromAmbientAuthority()->sockets()->pair()', static function($assert) { [$parent, $child] = IO::fromAmbientAuthority() @@ -50,7 +51,7 @@ static function($assert) { }, ); - yield test( + yield $prove->test( 'Socket client poll', static function($assert) { @\unlink('/tmp/foo.sock'); diff --git a/proofs/stream.php b/proofs/stream.php index c19e5e9..6ce4994 100644 --- a/proofs/stream.php +++ b/proofs/stream.php @@ -5,10 +5,13 @@ Stream\Size, Stream\Size\Unit, }; -use Innmind\BlackBox\Set; +use Innmind\BlackBox\{ + Set, + Prove, +}; -return static function() { - yield test( +return static function(Prove $prove) { + yield $prove->test( 'Empty stream size', static function($assert) { $model = Size::of(0); @@ -18,13 +21,13 @@ static function($assert) { }, ); - yield proof( - 'Stream sizes', - given( + yield $prove + ->proof('Stream sizes') + ->given( Set::integers()->between(1, 999), Set::of(...Unit::cases()), - ), - static function($assert, $size, $unit) { + ) + ->test(static function($assert, $size, $unit) { $model = $unit->of($size); $extension = match ($unit) { Unit::bytes => 'B', @@ -37,21 +40,20 @@ static function($assert, $size, $unit) { $assert->same($unit, $model->unit()); $assert->same("$size$extension", $model->toString()); - }, - ); + }); - yield proof( - 'Stream::lessThan()', - given( + yield $prove + ->proof('Stream::lessThan()') + ->given( Set::integers()->above(0), Set::integers()->above(1), - )->filter(static fn($a, $b) => \is_int($a + $b)), - static function($assert, $size, $additionnal) { + ) + ->filter(static fn($a, $b) => \is_int($a + $b)) + ->test(static function($assert, $size, $additionnal) { $model = Size::of($size); $assert->false($model->lessThan($model)); $assert->true($model->lessThan(Size::of($size + $additionnal))); $assert->false(Size::of($size + $additionnal)->lessThan($model)); - }, - ); + }); }; diff --git a/proofs/streams.php b/proofs/streams.php index 59c5f10..b98f2ab 100644 --- a/proofs/streams.php +++ b/proofs/streams.php @@ -11,9 +11,12 @@ SideEffect, Monoid\Concat, }; -use Innmind\BlackBox\Set; +use Innmind\BlackBox\{ + Set, + Prove, +}; -return static function() { +return static function(Prove $prove) { // Here we make sure to only use characters that are "reversible". Writing // and then reading should return the exact same character. $string = Set::strings()->madeOf( @@ -31,7 +34,7 @@ Set::sequence($string)->between(0, 20), ); - yield test( + yield $prove->test( 'IO::streams()->acquire()->read()->frames()->one()', static function($assert) { $http = <<acquire()->read()->frames()->sequence()', - given( + yield $prove + ->proof('IO::streams()->acquire()->read()->frames()->sequence()') + ->given( Set::either( Set::sequence($string->between(0, 20)->filter( static fn($line) => !\str_contains($line, "\n"), @@ -129,8 +132,8 @@ static function($assert) { static fn($line) => !\str_contains($line, "\n"), ))->between(0, 20), ), - ), - static function($assert, $lines) { + ) + ->test(static function($assert, $lines) { $tmp = \tmpfile(); \fwrite($tmp, \implode("\n", $lines)); @@ -162,12 +165,11 @@ static function($assert, $lines) { ->fold(Concat::monoid) ->toString(), ); - }, - ); + }); - yield proof( - 'IO::streams()->acquire()->read()->nonBlocking()->frames()->sequence()', - given( + yield $prove + ->proof('IO::streams()->acquire()->read()->nonBlocking()->frames()->sequence()') + ->given( Set::either( Set::sequence($string->between(0, 20)->filter( static fn($line) => !\str_contains($line, "\n"), @@ -176,8 +178,8 @@ static function($assert, $lines) { static fn($line) => !\str_contains($line, "\n"), ))->between(0, 20), ), - ), - static function($assert, $lines) { + ) + ->test(static function($assert, $lines) { $tmp = \tmpfile(); \fwrite($tmp, \implode("\n", $lines)); @@ -210,12 +212,11 @@ static function($assert, $lines) { ->fold(Concat::monoid) ->toString(), ); - }, - ); + }); - yield proof( - 'IO::streams()->acquire()->read()->frames()->rewindable()->sequence()', - given( + yield $prove + ->proof('IO::streams()->acquire()->read()->frames()->rewindable()->sequence()') + ->given( Set::either( Set::sequence($string->between(0, 20)->filter( static fn($line) => !\str_contains($line, "\n"), @@ -224,8 +225,8 @@ static function($assert, $lines) { static fn($line) => !\str_contains($line, "\n"), ))->between(0, 20), ), - ), - static function($assert, $lines) { + ) + ->test(static function($assert, $lines) { $tmp = \tmpfile(); \fwrite($tmp, \implode("\n", $lines)); @@ -251,17 +252,16 @@ static function($assert, $lines) { ->fold(Concat::monoid) ->toString(), ); - }, - ); + }); - yield proof( - 'IO::streams()->acquire()->read()->pool()->chunks()', - given( + yield $prove + ->proof('IO::streams()->acquire()->read()->pool()->chunks()') + ->given( $string, $string, Set::of(...Str\Encoding::cases()), - ), - static function($assert, $a, $b, $encoding) { + ) + ->test(static function($assert, $a, $b, $encoding) { $tmpA = \tmpfile(); \fwrite($tmpA, $a); $tmpB = \tmpfile(); @@ -303,17 +303,16 @@ static function($assert, $a, $b, $encoding) { ->map(static fn($chunk) => $chunk->value()->toString()) ->toList(), ); - }, - ); + }); - yield proof( - 'IO::streams()->acquire()->read()->pool()->nonBlocking()->chunks()', - given( + yield $prove + ->proof('IO::streams()->acquire()->read()->pool()->nonBlocking()->chunks()') + ->given( $string, $string, Set::of(...Str\Encoding::cases()), - ), - static function($assert, $a, $b, $encoding) { + ) + ->test(static function($assert, $a, $b, $encoding) { $tmpA = \tmpfile(); \fwrite($tmpA, $a); $tmpB = \tmpfile(); @@ -356,13 +355,12 @@ static function($assert, $a, $b, $encoding) { ->map(static fn($chunk) => $chunk->value()->toString()) ->toList(), ); - }, - ); + }); - yield proof( - 'IO::streams()->acquire()->close()', - given($string), - static function($assert, $content) { + yield $prove + ->proof('IO::streams()->acquire()->close()') + ->given($string) + ->test(static function($assert, $content) { $tmp = \tmpfile(); \fwrite($tmp, $content); @@ -392,16 +390,15 @@ static function($assert, $content) { ->sequence() ->toList(), ); - }, - ); + }); - yield proof( - 'IO::streams()->acquire()->write()->sink()', - given( + yield $prove + ->proof('IO::streams()->acquire()->write()->sink()') + ->given( $strings, Set::of(...Str\Encoding::cases()), - ), - static function($assert, $chunks, $encoding) { + ) + ->test(static function($assert, $chunks, $encoding) { $tmp = \tmpfile(); $sideEffect = IO::fromAmbientAuthority() @@ -426,6 +423,5 @@ static function($assert, $chunks, $encoding) { \implode('', $chunks), \stream_get_contents($tmp), ); - }, - ); + }); };