From 34f640cd55af92256557c32291283cb12ba92a9d Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 25 Jan 2026 18:24:01 +0100 Subject: [PATCH] better integrate old phpunit tests in blackbox --- tests/Adapter/FilesystemTest.php | 24 ++++++------- tests/DirectoryTest.php | 18 +++++----- tests/File/Content/LineTest.php | 30 ++++++++-------- tests/FileTest.php | 36 +++++++++---------- tests/NameTest.php | 60 ++++++++++++++++---------------- 5 files changed, 84 insertions(+), 84 deletions(-) diff --git a/tests/Adapter/FilesystemTest.php b/tests/Adapter/FilesystemTest.php index 423e380..3417294 100644 --- a/tests/Adapter/FilesystemTest.php +++ b/tests/Adapter/FilesystemTest.php @@ -355,9 +355,9 @@ public function testPathTooLongThrowAnException() ))->unwrap(); } - public function testPersistedNameCanStartWithAnyAsciiCharacter() + public function testPersistedNameCanStartWithAnyAsciiCharacter(): BlackBox\Proof { - $this + return $this ->forAll( Set::either( Set::integers()->between(1, 46), @@ -365,7 +365,7 @@ public function testPersistedNameCanStartWithAnyAsciiCharacter() ), Set::strings(), ) - ->then(function($ord, $content) { + ->prove(function($ord, $content) { $path = \sys_get_temp_dir().'/innmind/filesystem/'; (new FS)->remove($path); @@ -390,9 +390,9 @@ public function testPersistedNameCanStartWithAnyAsciiCharacter() }); } - public function testPersistedNameCanContainWithAnyAsciiCharacter() + public function testPersistedNameCanContainWithAnyAsciiCharacter(): BlackBox\Proof { - $this + return $this ->forAll( Set::either( Set::integers()->between(1, 46), @@ -400,7 +400,7 @@ public function testPersistedNameCanContainWithAnyAsciiCharacter() ), Set::strings(), ) - ->then(function($ord, $content) { + ->prove(function($ord, $content) { $path = \sys_get_temp_dir().'/innmind/filesystem/'; (new FS)->remove($path); @@ -425,9 +425,9 @@ public function testPersistedNameCanContainWithAnyAsciiCharacter() }); } - public function testPersistedNameCanContainOnlyOneAsciiCharacter() + public function testPersistedNameCanContainOnlyOneAsciiCharacter(): BlackBox\Proof { - $this + return $this ->forAll( Set::either( Set::integers()->between(1, 8), @@ -437,7 +437,7 @@ public function testPersistedNameCanContainOnlyOneAsciiCharacter() ), Set::strings(), ) - ->then(function($ord, $content) { + ->prove(function($ord, $content) { $path = \sys_get_temp_dir().'/innmind/filesystem/'; (new FS)->remove($path); @@ -502,11 +502,11 @@ public function testThrowsWhenListContainsALink() ); } - public function testDotFilesAreListed() + public function testDotFilesAreListed(): BlackBox\Proof { - $this + return $this ->forAll(FName::strings()->prefixedBy('.')) - ->then(function($name) { + ->prove(function($name) { $path = \sys_get_temp_dir().'/innmind/filesystem/'; (new FS)->remove($path); (new FS)->mkdir($path); diff --git a/tests/DirectoryTest.php b/tests/DirectoryTest.php index 72ce96f..1736277 100644 --- a/tests/DirectoryTest.php +++ b/tests/DirectoryTest.php @@ -186,14 +186,14 @@ public function testFilter() $this->assertSame('foobar', $files->toList()[1]->name()->toString()); } - public function testDirectoryLoadedWithDifferentFilesWithTheSameNameThrows() + public function testDirectoryLoadedWithDifferentFilesWithTheSameNameThrows(): BlackBox\Proof { - $this + return $this ->forAll( FName::any(), FName::any(), ) - ->then(function($directory, $file) { + ->prove(function($directory, $file) { $this->expectException(\LogicException::class); $this->expectExceptionMessage("Same file '{$file->toString()}' found multiple times"); @@ -207,14 +207,14 @@ public function testDirectoryLoadedWithDifferentFilesWithTheSameNameThrows() }); } - public function testNamedDirectoryLoadedWithDifferentFilesWithTheSameNameThrows() + public function testNamedDirectoryLoadedWithDifferentFilesWithTheSameNameThrows(): BlackBox\Proof { - $this + return $this ->forAll( FName::any(), FName::any(), ) - ->then(function($directory, $file) { + ->prove(function($directory, $file) { $this->expectException(\LogicException::class); $this->expectExceptionMessage("Same file '{$file->toString()}' found multiple times"); @@ -228,11 +228,11 @@ public function testNamedDirectoryLoadedWithDifferentFilesWithTheSameNameThrows( }); } - public function testLazyLoadingADirectoryDoesntLoadFiles() + public function testLazyLoadingADirectoryDoesntLoadFiles(): BlackBox\Proof { - $this + return $this ->forAll(FName::any()) - ->then(function($name) { + ->prove(function($name) { $this->assertInstanceOf( Directory::class, Directory::lazy( diff --git a/tests/File/Content/LineTest.php b/tests/File/Content/LineTest.php index 992cced..4902172 100644 --- a/tests/File/Content/LineTest.php +++ b/tests/File/Content/LineTest.php @@ -15,14 +15,14 @@ class LineTest extends TestCase { use BlackBox; - public function testDoesntAcceptNewLineDelimiter() + public function testDoesntAcceptNewLineDelimiter(): BlackBox\Proof { - $this + return $this ->forAll( Set::strings()->unicode(), Set::strings()->unicode(), ) - ->then(function($start, $end) { + ->prove(function($start, $end) { try { Line::of(Str::of($start."\n".$end)); @@ -33,20 +33,20 @@ public function testDoesntAcceptNewLineDelimiter() }); } - public function testLineIsNotAltered() + public function testLineIsNotAltered(): BlackBox\Proof { - $this + return $this ->forAll($this->strings()) - ->then(function($content) { + ->prove(function($content) { $this->assertSame($content, Line::of(Str::of($content))->toString()); }); } - public function testEndOfLineDelimiterIsRemovedAutomaticallyWhenReadingFromStream() + public function testEndOfLineDelimiterIsRemovedAutomaticallyWhenReadingFromStream(): BlackBox\Proof { - $this + return $this ->forAll(Set::strings()->unicode()) - ->then(function($content) { + ->prove(function($content) { $this->assertStringEndsNotWith( "\n", Line::fromStream(Str::of($content))->toString(), @@ -54,14 +54,14 @@ public function testEndOfLineDelimiterIsRemovedAutomaticallyWhenReadingFromStrea }); } - public function testMap() + public function testMap(): BlackBox\Proof { - $this + return $this ->forAll( $this->strings(), $this->strings(), ) - ->then(function($original, $replacement) { + ->prove(function($original, $replacement) { $line = Line::of(Str::of($original)); $mapped = $line->map(function($content) use ($original, $replacement) { $this->assertSame($original, $content->toString()); @@ -75,11 +75,11 @@ public function testMap() }); } - public function testMappedLineCannotContainEndOfLineDelimiter() + public function testMappedLineCannotContainEndOfLineDelimiter(): BlackBox\Proof { - $this + return $this ->forAll($this->strings()) - ->then(function($content) { + ->prove(function($content) { $line = Line::of(Str::of($content)); try { diff --git a/tests/FileTest.php b/tests/FileTest.php index f52e3b8..89f5383 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -54,14 +54,14 @@ public function testMediaType() $this->assertSame($mt, $f->mediaType()); } - public function testContentIsNeverAltered() + public function testContentIsNeverAltered(): BlackBox\Proof { - $this + return $this ->forAll( FName::any(), FMediaType::any(), ) - ->then(function($name, $mediaType) { + ->prove(function($name, $mediaType) { $file = File::of( $name, $content = Content::none(), @@ -74,11 +74,11 @@ public function testContentIsNeverAltered() }); } - public function testByDefaultTheMediaTypeIsOctetStream() + public function testByDefaultTheMediaTypeIsOctetStream(): BlackBox\Proof { - $this + return $this ->forAll(FName::any()) - ->then(function($name) { + ->prove(function($name) { $file = File::of( $name, Content::none(), @@ -91,14 +91,14 @@ public function testByDefaultTheMediaTypeIsOctetStream() }); } - public function testNamedConstructorNeverAltersTheContent() + public function testNamedConstructorNeverAltersTheContent(): BlackBox\Proof { - $this + return $this ->forAll( FName::any(), FMediaType::any(), ) - ->then(function($name, $mediaType) { + ->prove(function($name, $mediaType) { $file = File::named( $name->toString(), $content = Content::none(), @@ -111,14 +111,14 @@ public function testNamedConstructorNeverAltersTheContent() }); } - public function testWithContent() + public function testWithContent(): BlackBox\Proof { - $this + return $this ->forAll( FName::any(), FMediaType::any(), ) - ->then(function($name, $mediaType) { + ->prove(function($name, $mediaType) { $file = File::of( $name, $content = Content::none(), @@ -133,14 +133,14 @@ public function testWithContent() }); } - public function testWithContentKeepsTheMediaTypeByDefault() + public function testWithContentKeepsTheMediaTypeByDefault(): BlackBox\Proof { - $this + return $this ->forAll( FName::any(), FMediaType::any(), ) - ->then(function($name, $mediaType) { + ->prove(function($name, $mediaType) { $file = File::of( $name, Content::none(), @@ -153,14 +153,14 @@ public function testWithContentKeepsTheMediaTypeByDefault() }); } - public function testRename() + public function testRename(): BlackBox\Proof { - $this + return $this ->forAll( FName::any(), FName::any(), ) - ->then(function($name1, $name2) { + ->prove(function($name1, $name2) { $file1 = File::of( $name1, Content::none(), diff --git a/tests/NameTest.php b/tests/NameTest.php index 1060ca6..ce74f99 100644 --- a/tests/NameTest.php +++ b/tests/NameTest.php @@ -46,40 +46,40 @@ public function testEmptyNameIsNotAllowed() Name::of(''); } - public function testAcceptsAnyValueNotContainingASlash() + public function testAcceptsAnyValueNotContainingASlash(): BlackBox\Proof { - $this + return $this ->forAll( Fixture::strings(), ) - ->then(function($value) { + ->prove(function($value) { $name = Name::of($value); $this->assertSame($value, $name->toString()); }); } - public function testNameContainingASlashIsNotAccepted() + public function testNameContainingASlashIsNotAccepted(): BlackBox\Proof { - $this + return $this ->forAll( Fixture::strings(), Fixture::strings(), ) - ->then(function($a, $b) { + ->prove(function($a, $b) { $this->expectException(\DomainException::class); Name::of("$a/$b"); }); } - public function testNameEqualsItself() + public function testNameEqualsItself(): BlackBox\Proof { - $this + return $this ->forAll( Fixture::strings(), ) - ->then(function($value) { + ->prove(function($value) { $name1 = Name::of($value); $name2 = Name::of($value); @@ -88,14 +88,14 @@ public function testNameEqualsItself() }); } - public function testNameDoesntEqualDifferentName() + public function testNameDoesntEqualDifferentName(): BlackBox\Proof { - $this + return $this ->forAll( Fixture::strings(), Fixture::strings(), ) - ->then(function($a, $b) { + ->prove(function($a, $b) { $name1 = Name::of($a); $name2 = Name::of($b); @@ -104,11 +104,11 @@ public function testNameDoesntEqualDifferentName() }); } - public function testDotFoldersAreNotAccepted() + public function testDotFoldersAreNotAccepted(): BlackBox\Proof { - $this + return $this ->forAll(Set::of('.', '..')) - ->then(function($name) { + ->prove(function($name) { try { Name::of($name); @@ -126,9 +126,9 @@ public function testChr0IsNotAccepted() Name::of('a'.\chr(0).'a'); } - public function testNamesLongerThan255AreNotAccepted() + public function testNamesLongerThan255AreNotAccepted(): BlackBox\Proof { - $this + return $this ->forAll( Set::sequence( Set::of( @@ -141,7 +141,7 @@ public function testNamesLongerThan255AreNotAccepted() ->map(static fn(array $chrs): string => \implode('', $chrs)) ->filter(static fn(string $name): bool => $name !== '.' && $name !== '..'), ) - ->then(function($name) { + ->prove(function($name) { try { Name::of($name); @@ -152,14 +152,14 @@ public function testNamesLongerThan255AreNotAccepted() }); } - public function testNameWithOnlyWhiteSpacesIsNotAccepted() + public function testNameWithOnlyWhiteSpacesIsNotAccepted(): BlackBox\Proof { - $this + return $this ->forAll(Set::of( 32, ...\range(9, 13), )) - ->then(function($ord) { + ->prove(function($ord) { try { Name::of(\chr($ord)); @@ -170,13 +170,13 @@ public function testNameWithOnlyWhiteSpacesIsNotAccepted() }); } - public function testAnySequenceOfNamesConstitutesAValidPath() + public function testAnySequenceOfNamesConstitutesAValidPath(): BlackBox\Proof { - $this + return $this ->forAll(Set::sequence( Fixture::any(), )->between(1, 10)) // enough to prove the behaviour - ->then(function($names) { + ->prove(function($names) { $strings = \array_map( static fn($name) => $name->toString(), $names, @@ -190,20 +190,20 @@ public function testAnySequenceOfNamesConstitutesAValidPath() }); } - public function testUnicodeCharactersAreAccepted() + public function testUnicodeCharactersAreAccepted(): BlackBox\Proof { - $this + return $this ->forAll(Set::strings()->unicode()->latinExtendedA()) - ->then(function(string $name) { + ->prove(function(string $name) { $this->assertInstanceOf(Name::class, Name::of($name)); }); } - public function testStr() + public function testStr(): BlackBox\Proof { - $this + return $this ->forAll(Fixture::strings()) - ->then(function($value) { + ->prove(function($value) { $this->assertInstanceOf(Str::class, Name::of($value)->str()); $this->assertSame( $value,