您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit参数enforce-time-limit与enforceTimeLimit(2) 配置pcntl进程控制支持
发布时间:2021-09-21 12:10:49编辑:雪饮阅读()
在上篇中了解了可以通过enforce-time-limit与enforceTimeLimit来检查带有 @large 标注的测试方法的执行时间,但是会发现有抛出:
Error: PHP extension pcntl is required for enforcing time limits
这样的错误
意思就是说php要支持pcntl才可以。
那么pcntl在php官方说是非unix类系统不支持的,而windows只有1和2,底层和unix有关,后续版本就完全无关了
为了尽量还原,和之前我们的测试环境一致,所以我们需要在linux中安装和之前php相同的版本(7.3.4),不过是不是nts就无所谓了。
环境是centos7,具体是centos7的什么详细版本,影响也是不大的。
安装php支持pcntl
tar -zxvf php-7.3.4.tar.gz
cd php-7.3.4
yum install libxml2-devel
./configure --prefix=/usr/local/php734 --enable-pcntl --enable-mbstring make && make install
cp php.ini-development /usr/local/php734/lib/php/php.ini
[root@localhost php-7.3.4]# /usr/local/php734/bin/php -m
[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
mbstring
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
[Zend Modules]
安装phpunit
这不是同样为了尽量还原和之前windows上版本一致,这里同样安装phpunit9.5.8
[root@localhost local]# /usr/local/php734/bin/php phpunit-9.5.8.phar --version
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
测试组织测试
接下来我们将之前组织测试代码拷贝到linux中然后注意linux大小写
src/Database.php
还有phpunit.xml:
<phpunit bootstrap="src/autoload.php" beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutOutputDuringTests="true" enforceTimeLimit="true">
<testsuites>
<testsuite name="Database">
<file>tests/UserTest.php</file>
<file>tests/DatabaseTest.php</file>
</testsuite>
</testsuites>
</phpunit>
然后运行命令如:
[root@localhost organizing]# /usr/local/php734/bin/php /usr/local/phpunit-9.5.8.phar --testsuite Database --enforce-time-limit
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
...R 4 / 4 (100%)
Time: 00:01.010, Memory: 18.00 MB
There was 1 risky test:
1) DatabaseTest::testAdd
Warning: include(PHPUnit\Composer\Autoload\ClassLoader.php): failed to open stream: No such file or directory in /usr/local/organizing/src/autoload.php on line 3
Warning: include(): Failed opening 'PHPUnit\Composer\Autoload\ClassLoader.php' for inclusion (include_path='.:/usr/local/php734/lib/php') in /usr/local/organizing/src/autoload.php on line 3
Execution aborted after 1 second
OK, but incomplete, skipped, or risky tests!
Tests: 4, Assertions: 4, Risky: 1.
这里已经不存在:
Error: PHP extension pcntl is required for enforcing time limits
这样的报错了,但是出现了新的错误
这个错误我发现只要我添加enforceTimeLimit="true"在phpunit.xml中或者
--enforce-time-limit追加于phpunit命令后面就会出现这个错误,暂时不晓得什么原因,后面再看呗。
关键字词:phpunit,enforce-time-limit,enforceTimeLimit,pcntl