syberisle/ mock-php-stream
php://的流包装器
1.1.0
2020-08-20 15:32 UTC
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.4
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-09-24 15:12:05 UTC
README
此库旨在用于模拟php://
流包装器。
强烈建议仅在测试中需要时注册/注销此功能。否则,在注册过程中可能会干扰其他内置的PHP流。
安装
composer install syberisle/mock-php-stream
用法
使用此工具测试Slim 3应用直接文件上传能力(其中正文是内容),现在变得更容易。
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();
安全
在生产环境中使用此工具可能会引起潜在问题,因为它会覆盖内置的PHP流函数。
致谢
这个想法基于这篇博客文章Mocking php://input。
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。