bcncommerce / stream-wrapper
PHP stream wrapper for testing classes which interact with files
Installs: 11 984
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.3
Requires (Dev)
- fabpot/php-cs-fixer: ^1.10
- phpunit/phpunit: ~3.7.0
This package is auto-updated.
Last update: 2024-11-12 20:39:40 UTC
README
This library provide a lightweight class which allows substitute PHP streams. It's very useful for Unit Testing when you need to test a class which interact with files.
Stream class create an unique stream wrapper which redirect file system calls to instance of Stream class, making the process fully controllable.
Usage
Reading
$stream = new Stream("Content"); // This code use variable instead of using actual file $fh = fopen($stream, "r"); echo fgets($fh); // output Content fclose($fh);
Writing
$stream = new Stream(); // This code write everything into variable $fh = fopen($stream, "r"); fputs($fh, "Content"); fclose($fh); // Now you can perform actions on generated content echo $stream->getContent(); // output Content