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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This is a tiny wrapper around the [Symfony filesystem]. It provides:
- A class `NativeFileSystem` implementing `FileSystem`.
- A readonly implementation `ReadOnlyFileSystem`. It can be used to either do no write operation or to bailout on write
operations. Note that for a better read/write API, a library such as [Flysystem] is recommended.
- A `FakeFileSystem` implementation.
- A `FS` static class for when you are not interested of using dependency injection for your filesystem layer or for
usage within tests.
- A `SplFileInfoFactory` utility to create a Symfony Finder `SplFileInfo` instance without using `Finder`.
Expand Down
192 changes: 192 additions & 0 deletions src/FakeFileSystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php

/*
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2022, Théo FIDRY <theo.fidry@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

namespace Fidry\FileSystem;

use DomainException;
use Symfony\Component\Finder\Finder;
use Traversable;

final class FakeFileSystem implements FileSystem
{
public function isRelativePath(string $path): bool
{
throw new DomainException('Unexpected call.');
}

public function escapePath(string $path): string
{
throw new DomainException('Unexpected call.');
}

public function dumpFile(string $filename, $content = ''): void
{
throw new DomainException('Unexpected call.');
}

public function getFileContents(string $file): string
{
throw new DomainException('Unexpected call.');
}

public function makeTmpDir(string $namespace, string $className): string
{
throw new DomainException('Unexpected call.');
}

public function getNamespacedTmpDir(string $namespace): string
{
throw new DomainException('Unexpected call.');
}

public function isReadable(string $filename): bool
{
throw new DomainException('Unexpected call.');
}

public function isReadableFile(string $filename): bool
{
throw new DomainException('Unexpected call.');
}

public function isReadableDirectory(string $filename): bool
{
throw new DomainException('Unexpected call.');
}

public function createFinder(): Finder
{
throw new DomainException('Unexpected call.');
}

public function copy(string $originFile, string $targetFile, bool $overwriteNewerFiles = false): never
{
throw new DomainException('Unexpected call.');
}

public function mkdir(iterable|string $dirs, int $mode = 0o777): never
{
throw new DomainException('Unexpected call.');
}

public function exists(iterable|string $files): bool
{
throw new DomainException('Unexpected call.');
}

public function touch(iterable|string $files, ?int $time = null, ?int $atime = null): never
{
throw new DomainException('Unexpected call.');
}

public function remove(iterable|string $files): never
{
throw new DomainException('Unexpected call.');
}

public function chmod(
iterable|string $files,
int $mode,
int $umask = 0o000,
bool $recursive = false
): never {
throw new DomainException('Unexpected call.');
}

public function chown(iterable|string $files, int|string $user, bool $recursive = false): never
{
throw new DomainException('Unexpected call.');
}

public function chgrp(iterable|string $files, int|string $group, bool $recursive = false): never
{
throw new DomainException('Unexpected call.');
}

public function rename(string $origin, string $target, bool $overwrite = false): never
{
throw new DomainException('Unexpected call.');
}

public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false): never
{
throw new DomainException('Unexpected call.');
}

public function hardlink(string $originFile, iterable|string $targetFiles): never
{
throw new DomainException('Unexpected call.');
}

public function readlink(string $path, bool $canonicalize = false): ?string
{
throw new DomainException('Unexpected call.');
}

public function makePathRelative(string $endPath, string $startPath): string
{
throw new DomainException('Unexpected call.');
}

public function mirror(
string $originDir,
string $targetDir,
?Traversable $iterator = null,
array $options = []
): never {
throw new DomainException('Unexpected call.');
}

public function isAbsolutePath(string $file): bool
{
throw new DomainException('Unexpected call.');
}

public function tempnam(string $dir, string $prefix, string $suffix = ''): string
{
throw new DomainException('Unexpected call.');
}

public function appendToFile(string $filename, $content): never
{
throw new DomainException('Unexpected call.');
}

public function readFile(string $filename): string
{
throw new DomainException('Unexpected call.');
}
}