Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: (62 commits) fix unicity filter not being applied in every case fix error in documentation add documentation to explain how to use properties to test new implementations prove the authorized names always constitutes a valid path remove duplication to generate valid names add properties for Directory::replaceAt ignore fixtures and properties from coverage add filtering properties remove unreachable code exclude forbidden value from scenarii CS do not allow names with space characters only 1014 file path limit only applies to macOS use directory properties to randomly add/remove file to/from the generated directory reduce the depth of generated directories to avoid hitting the filesystem path length limit remove restriction on file names disable memory limit throw an exception when file path to persisted is too long disable memory limit for coverage reduce the number of scenarii ...
- Loading branch information
Showing
58 changed files
with
3,367 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ignore_paths: | ||
- fixtures/* | ||
- properties/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Fixtures\Innmind\Filesystem; | ||
|
||
use Innmind\Filesystem\{ | ||
Directory\Directory as Model, | ||
File as FileInterface, | ||
}; | ||
use Properties\Innmind\Filesystem\Directory as Properties; | ||
use Innmind\BlackBox\{ | ||
Set as DataSet, | ||
Properties as Ensure, | ||
}; | ||
use Fixtures\Innmind\Immutable\Set; | ||
use function Innmind\Immutable\unwrap; | ||
|
||
final class Directory | ||
{ | ||
/** | ||
* Will generate random directory tree with a maximum depth of 3 directories | ||
* | ||
* @return DataSet<Model> | ||
*/ | ||
public static function any(): DataSet | ||
{ | ||
return self::atDepth(0, 1); | ||
} | ||
|
||
/** | ||
* @return DataSet<Model> | ||
*/ | ||
public static function maxDepth(int $depth): DataSet | ||
{ | ||
return self::atDepth(0, $depth); | ||
} | ||
|
||
private static function atDepth(int $depth, int $maxDepth): DataSet | ||
{ | ||
if ($depth === $maxDepth) { | ||
$files = Set::of( | ||
FileInterface::class, | ||
new DataSet\Randomize( | ||
File::any(), | ||
), | ||
DataSet\Integers::between(0, 5), | ||
); | ||
} else { | ||
$files = Set::of( | ||
FileInterface::class, | ||
new DataSet\Either( | ||
new DataSet\Randomize( | ||
File::any(), | ||
), | ||
self::atDepth($depth + 1, $maxDepth), | ||
), | ||
DataSet\Integers::between(0, 5), | ||
); | ||
} | ||
|
||
$directory = DataSet\Composite::immutable( | ||
static fn($name, $files): Model => new Model( | ||
$name, | ||
$files, | ||
), | ||
Name::any(), | ||
$files->filter(static function($files): bool { | ||
if ($files->empty()) { | ||
return true; | ||
} | ||
|
||
// do not accept duplicated files | ||
return $files | ||
->groupBy(static fn($file) => $file->name()->toString()) | ||
->size() === $files->size(); | ||
}), | ||
); | ||
|
||
$modified = DataSet\Composite::immutable( | ||
static fn($directory, $properties): Model => $properties->ensureHeldBy($directory), | ||
$directory, | ||
DataSet\Decorate::immutable( | ||
static fn(array $properties): Ensure => new Ensure(...$properties), | ||
DataSet\Sequence::of( | ||
new DataSet\Either( | ||
DataSet\Property::of( | ||
Properties\RemoveFile::class, | ||
), | ||
DataSet\Property::of( | ||
Properties\AddFile::class, | ||
File::any(), | ||
), | ||
), | ||
DataSet\Integers::between(1, 10), | ||
), | ||
), | ||
); | ||
|
||
return new DataSet\Either( | ||
$directory, | ||
$modified | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Fixtures\Innmind\Filesystem; | ||
|
||
use Innmind\Filesystem\File\File as Model; | ||
use Innmind\BlackBox\Set; | ||
use Innmind\Stream\{ | ||
Readable\Stream, | ||
Stream\Position, | ||
}; | ||
use Fixtures\Innmind\MediaType\MediaType; | ||
|
||
final class File | ||
{ | ||
public static function any(): Set | ||
{ | ||
return Set\Composite::immutable( | ||
static function($name, $content, $mediaType, $seek): Model { | ||
$file = new Model( | ||
$name, | ||
$stream = Stream::ofContent($content), | ||
$mediaType, | ||
); | ||
|
||
if (\is_int($seek)) { | ||
// as the generated seeked position may be higher than the | ||
// actual content size | ||
$seek = \min(\strlen($content), $seek); | ||
|
||
$stream->seek(new Position($seek)); | ||
} | ||
|
||
return $file; | ||
}, | ||
Name::any(), | ||
Set\Strings::any(), | ||
MediaType::any(), | ||
new Set\Either( | ||
Set\Integers::between(0, 128), // 128 is the max string length by default | ||
Set\Elements::of(null), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Fixtures\Innmind\Filesystem; | ||
|
||
use Innmind\Filesystem\Name as Model; | ||
use Innmind\BlackBox\Set; | ||
|
||
final class Name | ||
{ | ||
/** | ||
* @return Set<Model> | ||
*/ | ||
public static function any(): Set | ||
{ | ||
return Set\Decorate::immutable( | ||
static fn(string $name): Model => new Model($name), | ||
self::strings(), | ||
); | ||
} | ||
|
||
/** | ||
* @return Set<string> | ||
*/ | ||
public static function strings(): Set | ||
{ | ||
return Set\Decorate::immutable( | ||
static fn(array $chrs): string => \implode('', $chrs), | ||
Set\Sequence::of( | ||
Set\Decorate::immutable( | ||
static fn(int $chr): string => \chr($chr), | ||
new Set\Either( | ||
Set\Integers::between(1, 46), | ||
Set\Integers::between(48, 127), | ||
), | ||
), | ||
Set\Integers::between(1, 255), | ||
), | ||
)->filter( | ||
static fn(string $name): bool => $name !== '.' && | ||
$name !== '..' && | ||
!\preg_match('~\s+~', $name) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.