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);
Inheritance

Constructors

FakeDisk(String name)
An empty fake named name.

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 directory and all its sub-folders.
inherited
allFiles([String directory = '']) → Future<List<String>>
The paths of the files in directory and all its sub-folders.
inherited
append(String path, String text, {String separator = '\n'}) → Future<void>
Adds text to the end of the file at path, after separator when the file already has content. Creates the file if needed.
inherited
assertCount(String directory, int count, {bool recursive = false}) → void
Asserts directory holds count files, counting sub-folders when recursive.
assertDirectoryEmpty(String directory) → void
Asserts there are no files in directory or 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 path as bytes.
inherited
checksum(String path, {String algorithm = 'md5'}) → Future<String>
A hash of the file at path, as lowercase hex. algorithm is md5 (the default, as in Laravel), sha1, sha224, sha256, sha384 or sha512.
inherited
copy(String from, String to) → Future<void>
Copies the file at from to to.
inherited
copyToDisk(String disk, String path, [String? to]) → Future<void>
Copies the file at path to the same path on disk, or to to.
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 path and 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 url into path, 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 path as 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 path last 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 when recursive. Sorted by path.
inherited
makeDirectory(String path) → Future<void>
Creates the folder at path and 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 from to to.
inherited
moveToDisk(String disk, String path, [String? to]) → Future<void>
Moves the file at path to the same path on disk, or to to.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
path(String path) → Future<String>
The absolute path of path on 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 text to the start of the file at path, before separator when 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 contents to path: a String (as UTF-8), a List<int> of bytes, or a Stream<List<int>>. Replaces any file there.
inherited
putFile(String directory, Object file) → Future<String>
Stores file in directory under 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 file in directory as name, and returns the path.
inherited
putJson(String path, Object? value) → Future<void>
Writes value as JSON. Models are encoded through their toJson().
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 directory inside 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 for path, 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