This library is intended to be used to mock the php://
stream wrapper.
It's highly recommended that you register/unregister this ONLY when you need it in a test. Otherwise it could interfere with other built-in php streams during the course of it being registered.
composer install syberisle/mock-php-stream
Using this to test a Slim 3 app's ability to do direct file uploads, where the body IS the content, is now easier.
MockPhpStream::register();
file_put_contents('php://input', 'you test data');
$app = new Slim\App();
$app->post('', function ($request) {
// direct file uploads
$request->getBody()->detach();
$from = fopen("php://input", 'r');
$to = fopen('/my/path/file', 'w');
stream_copy_to_stream($from, $to);
fclose($from);
fclose($to);
});
MockPhpStream::unregister();
Using this in production could potentially cause problems as it overrides the built-in php stream functions.
The idea was based off on this blog article Mocking php://input.
The MIT License (MIT). Please see License File for more information.