christeredvartsen/testfs
Composer 安装命令:
composer require --dev christeredvartsen/testfs
包简介
Virtual filesystem that can be used for testing
README 文档
README
Virtual filesystem for PHP for use with testing, implemented using a stream wrapper.
Requirements
This library requires PHP >= 8.3.
Installation
Install using Composer:
composer require --dev christeredvartsen/testfs
Usage
Enable the stream wrapper
The stream wrapper is enabled once you register it:
require 'vendor/autoload.php'; use TestFs\StreamWrapper; StreamWrapper::register();
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:
require 'vendor/autoload.php'; use TestFs\StreamWrapper; StreamWrapper::register(); $device = StreamWrapper::getDevice(); $device->buildFromDirectory('./src'); echo $device->tree() . PHP_EOL;
If the above code would be executed from a PHP file in the root of this project you would get something like this:
/
├── Asset.php
├── Device.php
├── Directory.php
├── Exception
│ ├── DuplicateAssetException.php
│ ├── DuplicateGroupException.php
│ ├── DuplicateUserException.php
│ ├── InsufficientStorageException.php
│ ├── InvalidAssetNameException.php
│ ├── InvalidFopenModeException.php
│ ├── InvalidUrlException.php
│ ├── InvalidWhenceException.php
│ ├── ProtocolAlreadyRegisteredException.php
│ ├── RuntimeException.php
│ ├── UnknownAssetException.php
│ ├── UnknownGroupException.php
│ └── UnknownUserException.php
├── File.php
├── FopenMode.php
├── RootDirectory.php
├── StreamWrapper.php
└── functions.php
1 directory, 21 files
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:
<?php require 'vendor/autoload.php'; use function TestFs\url; echo url('path/to/file.php'); // tfs://path/to/file.php
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:
<?php require 'vendor/autoload.php'; use TestFs\StreamWrapper; use function TestFs\file_get_contents; use function TestFs\file_put_contents; use function TestFs\mkdir; StreamWrapper::register(); mkdir('foo/bar', 0777, true); file_put_contents('foo/bar/baz.txt', 'Hello World!'); echo file_get_contents('foo/bar/baz.txt'); // Hello World!
Refer to src/functions.php for the complete list of wrapped functions.
Development
git clone git@github.com:christeredvartsen/testfs.git
composer install
composer run ci
License
MIT, see LICENSE.
christeredvartsen/testfs 适用场景与选型建议
christeredvartsen/testfs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.01k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「testing」 「phpunit」 「streamwrapper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 christeredvartsen/testfs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 christeredvartsen/testfs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 christeredvartsen/testfs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
HiDev plugin for PHPUnit
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
The flysystem adapter for yandex disk rest api.
统计信息
- 总下载量: 4.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 23
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-22