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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

### Changed

- Requires PHP `8.5`
- Requires `innmind/black-box:~7.0`

## 4.1.1 - 2026-04-09

### Fixed
Expand Down
21 changes: 9 additions & 12 deletions blackbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
146 changes: 69 additions & 77 deletions proofs/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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"),
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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(...)))
Expand Down Expand Up @@ -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(...)))
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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(...)))
Expand Down Expand Up @@ -428,10 +421,9 @@ static function($assert, $chunks) {
static fn() => null,
),
);
},
);
});

yield test(
yield $prove->test(
'IO::files()->require()',
static function($assert) {
$assert->same(
Expand Down
Loading
Loading