FakeDisk class
An in-memory disk with Laravel's Storage::fake() assertions.
Get one from FileStorage.fake('photos'); NyTest.init() also swaps
every writable disk for one. The assertions are synchronous, so they
need no await.
final FakeDisk photos = FileStorage.fake('photos');
await ProfileController().saveAvatar(FakeFile.image('me.png'));
photos.assertCount('avatars', 1);
Properties
- driver → DiskDriver
-
The backend that stores the bytes.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- memory → MemoryDiskDriver
-
The memory this disk writes to.
final
- name → String
-
The disk's name, e.g.
local.finalinherited - prefix → String
-
The folder inside driver this disk treats as its root.
finalinherited
- readOnly → bool
-
Whether writes are refused.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
allDirectories(
[String directory = '']) → Future< List< String> > -
The paths of the folders in
directoryand all its sub-folders.inherited -
allFiles(
[String directory = '']) → Future< List< String> > -
The paths of the files in
directoryand all its sub-folders.inherited -
append(
String path, String text, {String separator = '\n'}) → Future< void> -
Adds
textto the end of the file atpath, afterseparatorwhen the file already has content. Creates the file if needed.inherited -
assertCount(
String directory, int count, {bool recursive = false}) → void -
Asserts
directoryholdscountfiles, counting sub-folders whenrecursive. -
assertDirectoryEmpty(
String directory) → void -
Asserts there are no files in
directoryor its sub-folders. -
assertEmpty(
) → void - Asserts the disk holds no files at all.
-
assertExists(
Object paths) → void -
Asserts a file or folder exists at each of
paths. -
assertMissing(
Object paths) → void -
Asserts nothing exists at any of
paths. -
bytes(
String path) → Future< Uint8List> -
The file at
pathas bytes.inherited -
checksum(
String path, {String algorithm = 'md5'}) → Future< String> -
A hash of the file at
path, as lowercase hex.algorithmismd5(the default, as in Laravel),sha1,sha224,sha256,sha384orsha512.inherited -
copy(
String from, String to) → Future< void> -
Copies the file at
fromtoto.inherited -
copyToDisk(
String disk, String path, [String? to]) → Future< void> -
Copies the file at
pathto the same path ondisk, or toto.inherited -
delete(
Object paths) → Future< bool> -
Deletes one path, or every path in an
Iterable<String>.inherited -
deleteDirectory(
String path) → Future< bool> -
Deletes the folder at
pathand everything in it. Returns false when there was no folder.inherited -
directories(
[String directory = '']) → Future< List< String> > -
The paths of the folders in
directory.inherited -
directoryExists(
String path) → Future< bool> -
Whether a folder exists at
path.inherited -
download(
String url, String path, {ProgressCallback? onProgress, CancelToken? cancelToken, Map< String, dynamic> ? headers, Map<String, dynamic> ? queryParameters}) → Future<void> -
Downloads
urlintopath, replacing any file there only once the download has finished.inherited -
exists(
String path) → Future< bool> -
Whether a file exists at
path.inherited -
files(
[String directory = '']) → Future< List< String> > -
The paths of the files in
directory.inherited -
get(
String path) → Future< String> -
The file at
pathas UTF-8 text.inherited -
json<
T> (String path, {Map< Type, dynamic> ? modelDecoders}) → Future<T?> -
The file at
path, decoded from JSON.inherited -
lastModified(
String path) → Future< DateTime> -
When the file at
pathlast changed.inherited -
list(
[String directory = '', bool recursive = false]) → Future< List< DiskEntry> > -
The files and folders in
directory, with their size and date, or in all its sub-folders whenrecursive. Sorted by path.inherited -
makeDirectory(
String path) → Future< void> -
Creates the folder at
pathand any missing parents.inherited -
mimeType(
String path) → Future< String?> -
The MIME type of the file at
path, from its first bytes and its extension, e.g.image/png. Null when neither says.inherited -
missing(
String path) → Future< bool> -
Whether no file exists at
path.inherited -
move(
String from, String to) → Future< void> -
Moves the file at
fromtoto.inherited -
moveToDisk(
String disk, String path, [String? to]) → Future< void> -
Moves the file at
pathto the same path ondisk, or toto.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
path(
String path) → Future< String> -
The absolute path of
pathon the device, for plugins that need a real file. Throws for disks with no files on the device, such as memory disks and the app bundle.inherited -
prepend(
String path, String text, {String separator = '\n'}) → Future< void> -
Adds
textto the start of the file atpath, beforeseparatorwhen the file already has content. Creates the file if needed.inherited -
prune(
{required Duration olderThan}) → Future< int> -
Deletes the files last changed longer ago than
olderThan, and returns how many were deleted.inherited -
put(
String path, Object contents) → Future< void> -
Writes
contentstopath: aString(as UTF-8), aList<int>of bytes, or aStream<List<int>>. Replaces any file there.inherited -
putFile(
String directory, Object file) → Future< String> -
Stores
fileindirectoryunder a random 40-character name, with the extension its contents show it to have, and returns the path.inherited -
putFileAs(
String directory, Object file, String name) → Future< String> -
Stores
fileindirectoryasname, and returns the path.inherited -
putJson(
String path, Object? value) → Future< void> -
Writes
valueas JSON. Models are encoded through theirtoJson().inherited -
readStream(
String path) → Stream< List< int> > -
The file at
path, in chunks, without loading it all into memory.inherited -
scope(
String directory) → Disk -
A disk rooted at
directoryinside this one, e.g. one per user:disk().scope('users/${user.id}').inherited -
size(
String path) → Future< int> -
The size of the file at
path, in bytes.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
url(
String path) → Future< Uri> -
A
file://URL forpath, for web views and video players.inherited -
usage(
) → Future< int> -
The total size of the files on this disk, in bytes.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited