Download the PHP package christeredvartsen/testfs without Composer
On this page you can find all versions of the php package christeredvartsen/testfs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download christeredvartsen/testfs
More information about christeredvartsen/testfs
Files in christeredvartsen/testfs
Package testfs
Short Description Virtual filesystem that can be used for testing
License MIT
Homepage https://github.com/christeredvartsen/testfs/
Informations about the package testfs
TestFs
Virtual filesystem for PHP for use with testing, implemented using a stream wrapper.
Requirements
This library requires PHP >= 8.3.
Installation
Install using Composer:
Usage
Enable the stream wrapper
The stream wrapper is enabled once you register it:
When it is registered it will pick up usage of the tfs://
protocol used with filesystem functions, for instance fopen()
, file_get_contents()
and mkdir()
.
Mirror a local directory into the virtual filesystem
If you want to mirror a local directory into the virtual filesystem you can do this:
If the above code would be executed from a PHP file in the root of this project you would get something like this:
Converting paths to URLs
To convert regular file paths to URLs that will be picked up by TestFs you can use the TestFs::url(string $path)
function:
Wrappers for regular filesystem functions
The library contains simple wrappers around some of the filesystem functions in PHP that automatically prefixes paths with the correct protocol:
Refer to src/functions.php for the complete list of wrapped functions.
Development
License
MIT, see LICENSE.