syberisle/mock-php-stream
最新稳定版本:2.0.0
Composer 安装命令:
composer require syberisle/mock-php-stream
包简介
Stream wrapper for mocking php://
README 文档
README
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.
NOTE Since version 2.0 the php://temp[/maxmemory:NN] and php://memory paths will behave as PHP does. The content
written to them will not be available after the stream_close call. This means that file_put_contents and
file_get_contents cannot be used to read and write these two paths.
Installation
composer install syberisle/mock-php-stream
Usage
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();
Security
Using this in production could potentially cause problems as it overrides the built-in php stream functions.
Credits
The idea was based off on this blog article Mocking php://input.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 6.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-10