jelix/fakeserverconf
Composer 安装命令:
composer require jelix/fakeserverconf
包简介
Fill the $_SERVER array with various PHP server configuration for unit tests.
README 文档
README
This PHP Library will allow you to simulate different PHP server configuration.
In a CLI environment (where you run PHPUnit for instance), you could have some difficulties to test a class that uses some $_SERVER values. This global variable does not contain the same thing as if the script is called in an Apache environment for example. Moreover the content of $_SERVER is not the same between a server configured with mod_php, and a server running PHP as a CGI, as FPM etc..
FakeServerConf allow you to fill automatically $_SERVER with good values (and $_GET, $_POST...), only by given an URL to "virtual" PHP server.
You don't need anymore to setup several real PHP HTTP server to test your libraries in different environment. Just call FakeServerConf in your unit tests.
For example, in your test, you want to have a $_SERVER filled as if the URL "http://testapp.local/info.php/foo/bar?baz=2" was requested. In your PHPUnit/Atoum/Simpletest/whatever class, call this:
// let's says we are running an Apache server configured with mod_php. // Indicate to this server the script name (it can be hidden in the http request) $server = new \Jelix\FakeServerConf\ApacheMod(null, '/info.php'); // now simulate an HTTP request $server->setHttpRequest('http://testapp.local/info.php/foo/bar?baz=2');
$_SERVER is now filled correctly, and you can test your classes (routers, url parser etc...)
You can also set the document root and other things...
Supported servers
- Apache + mod_php
- Apache + php-cgi
- Apache + mod_fastcgi + php-fpm
Adding servers
You don't find your server configuration in FakeServerConf? Help us to provide additionnal support.
- First configure your server. It's better if it's a fresh installation in a virtual machine. You should install the curl extension for php.
- Configure a virtual host named "testapp.local". It should accept multiviews queries (without .php)
- The document root of the server should be /var/www/ and it should content files you can find in tests/www. You can also set the document root to tests/www.
- In your browser, call http://testapp.local/generateserverdata.php. It generates some PHP code that you have to add into a test class in tests/. See existing test class.
- Create a new class in src/jelix/FakeServerConf, that inherits from FakeServerConf
- In your test class, you should instantiate this class
- Run tests with phpunit, and fix in your new class the issues detected in your tests.
- Don't touch the FakeServerConf class except if it makes sens for all server configuration.
installing
You can use Composer. Into your composer.json file, add
"require": {
"jelix/fakeserverconf": "1.0.0"
}
running test
Install phpunit (run composer install) and launch it into the tests/ directory
cd tests
../vendor/bin/phpunit
# or if you installed phpunit globally:
phpunit
jelix/fakeserverconf 适用场景与选型建议
jelix/fakeserverconf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 115.46k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2012 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「_SERVER PHP configuration unit tests」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jelix/fakeserverconf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jelix/fakeserverconf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jelix/fakeserverconf 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Configuration component
Utils to load, parse and work with configuration on Mezzio projects
Trait to support creating complex nested class structures from JSON/YAML objects.
Alfabank REST API integration
Advanced configuration manager for PHP with dotted-path access, file/directory/class loaders and a static facade.
VIVINIKO Configuration Service Provider
统计信息
- 总下载量: 115.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 23
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-11-15