fidry / filesystem
Symfony Filesystem with a few more utilities.
Fund package maintenance!
theofidry
Installs: 301 683
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- symfony/filesystem: ^6.4 || ^7.0
- thecodingmachine/safe: ^2.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.4
- ergebnis/composer-normalize: ^2.28
- infection/infection: >=0.26
- phpunit/phpunit: ^10.3
- symfony/finder: ^6.4 || ^7.0
This package is auto-updated.
Last update: 2024-12-04 12:24:18 UTC
README
This is a tiny wrapper around the Symfony filesystem. It provides:
- A new class
FileSystem
(extending the Symfony one) which has a few more methods. - A
FS
static class for when you are not interested of using dependency injection for your filesystem layer. - A PHPUnit
FileSystemTestCase
which lets you easily write a file-system dependent test.
Usage
An example of PHPUnit test:
<?php declare(strict_types=1); namespace App; use Fidry\FileSystem\FS; use Fidry\FileSystem\Test\FileSystemTestCase; use PHPUnit\Framework\Attributes\CoversClass; use Symfony\Component\Finder\Finder; use function getenv; use function is_string; final class MyAppFileSystemTest extends FileSystemTestCase { public static function getTmpDirNamespace(): string { // This is to make it thread safe with Infection. If you are not using // infection or do not need thread safety, this can return a constant // string, e.g. your project/library name. $threadId = getenv('TEST_TOKEN'); if (!is_string($threadId)) { $threadId = ''; } return 'MyApp'.$threadId; } public function test_it_works(): void { // This file is dumped into a temporary directory. Here // something like '/private/var/folders/p3/lkw0cgjj2fq0656q_9rd0mk80000gn/T/MyApp/MyAppFileSystemTest10000' // on OSX. FS::dumpFile('file1', ''); $files = Finder::create() ->files() ->in($this->tmp); self::assertSame(['file1'], $this->normalizePaths($files)); } }
Contributing
GNU Make is your friend. Try make
or make help
!.