webforge / configuration-tester
从命令行或单元测试测试您的PHP配置
1.0.0
2014-09-16 08:21 UTC
Requires
- guzzle/guzzle: 3.7.4@stable
Requires (Dev)
- satooshi/php-coveralls: dev-master
- webforge/testplate: 1.*
This package is auto-updated.
Last update: 2024-09-07 03:03:41 UTC
README
从命令行或单元测试测试您的PHP配置 ConfigurationTester能够将环境配置(目前是PHP-ini值)与一组固定值进行比较。可以通过ConfigurationRetriever(例如从apache dump-script)接收php.ini设置。
use Webforge\Setup\ConfigurationTester; $t = new ConfigurationTester(); $t->INI('mbstring.internal_encoding', 'utf-8');
您可以使用多个运算符来比较值
$t->INI('post_max_size','2M', '>='); $t->INI('post_max_size',1024, '<');
类似"2M"(文件大小)这样的值将被归一化,以便于比较。
// if ini_get('post_max_size') is "2M" or 2097152 doesn't matter $t->INI('post_max_size',2*1024*1024); $t->INI('post_max_size','2M');
您可以使用ConfigurationTester来测试您的web服务器(或其他远程)的PHP-ini值
use Webforge\Setup\ConfigurationTester; use Webforge\Setup\RemoteConfigurationRetriever; $t = new ConfigurationTester(new RemoteConfigurationRetriever('https://:80/dump-inis.php'));
将dump-inis.php放入webroot,内容如下
<?php print json_encode(ini_get_all()); ?>
您可以通过检索缺陷来获取检查的结果。它们是ConfigurationDefect类的实例,可以转换为字符串以详细说明其失败
if (count($t->getDefects()) > 0) { throw new \RuntimeException('Please check your Config: '.implode("\n", $t->getDefects())); }
您可以使用ConfigurationTester::__toString()来获取更美观的输出格式。这可能在将来改为ConfigurationTesterPrinter或类似的东西。
print $t;