gpt4 book ai didi

PhpUnit ...Killed 为什么会被杀死?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:07 25 4
gpt4 key购买 nike

我的phpunit.xml

<phpunit
bootstrap="bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>

<logging>
<log type="coverage-html" target="coverage" lowUpperBound="75" highUpperBound="100" />
</logging>
</phpunit>

我的bootstrap.php:

<?php

/** ---------------------------------------------------- **/
// Require the vendors autoload file.
/** ---------------------------------------------------- **/
require_once 'vendor/autoload.php';

/** ---------------------------------------------------- **/
// We neeed WordPress Bootstrap files for its test.
/** ---------------------------------------------------- **/
define('WP_TEST_DIR', parse_ini_file('test-config.ini')['test-location']);

// Include the bootstrap file.
require_once WP_TEST_DIR . 'includes/bootstrap.php';

// Include the Functions file
require_once WP_TEST_DIR . 'includes/functions.php';

当我在日志部分未注释的情况下运行它时,我得到:

vagrant@vagrant-ubuntu-trusty-64:/vagrant/Freya/Routes$ phpunit
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.6.6 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Routes/phpunit.xml

...............Killed

当我注释掉日志记录时,我得到:

vagrant@vagrant-ubuntu-trusty-64:/vagrant/Freya/Routes$ phpunit
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.6.6 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Routes/phpunit.xml

..................................

Time: 9.64 seconds, Memory: 45.50Mb

OK (34 tests, 38 assertions)

为什么它会在没有可见错误的情况下死掉?这是内存问题吗?如果是这样,为什么不那样说呢?这些测试集确实包括 WordPress 测试套件类 WP_UnitTestCase 以允许我为一些测试设置一个假的 Wordpress 安装但是正如你所看到的,我第二次运行测试时日志记录被注释out 我使用了 45.50mb 内存。没什么。

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = On
display_startup_errors = Off

PHP 版本为 5.5.9

这是怎么回事? (是的,覆盖文件夹存在)

更新1

原来 dmesg 正在显示:

[942618.313174] Out of memory: Kill process 12987 (php) score 384 or sacrifice child
[942618.315188] Killed process 12987 (php) total-vm:453360kB, anon-rss:192380kB, file-rss:12kB
[942757.404416] php5-fpm invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0
[942757.404421] php5-fpm cpuset=/ mems_allowed=0
[942757.404424] CPU: 0 PID: 16427 Comm: php5-fpm Tainted: G OX 3.13.0-37-generic #64-Ubuntu
[942757.404426] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[942757.404428] 0000000000000000 ffff88000200d980 ffffffff8171ed09 ffff88001dfbb000
[942757.404431] ffff88000200da08 ffffffff817195c4 0000000000000000 0000000000000000
[942757.404432] 0000000000000000 0000000000000000 0000000000000000 0000000000000000

在这种情况下,我需要增加 PHP 的内存吗?

最佳答案

我发现在 PHPUnit 中诊断 fatal error 的最佳(唯一?)方法是在 Bootstrap 中添加一个关闭错误陷阱。 PHPUnit 自身会捕获错误以帮助报告,但出于某种原因,这会完全阻止报告某些核心/致命类型错误。

我将其添加到我的所有项目中:

phpunit.xml:

< phpunit
bootstrap="bootstrap.php"
...

bootstrap.php:

// PHPUnit dies silently with FATAL ERRORS which makes it hard to debug the tests.
register_shutdown_function('PHPUnit_shutdownFunction');
function PHPUnit_shutdownFunction() {
// http://www.php.net/manual/en/errorfunc.constants.php
$error = error_get_last();
if (!is_null($error)){
if($error['type'] & (E_ERROR + E_PARSE + E_CORE_ERROR + E_COMPILE_ERROR + E_USER_ERROR + E_RECOVERABLE_ERROR)){
echo 'Test Bootstrap: Caught untrapped fatal error: ';
var_export($error);
}
}
}

这些神秘的问题将成为过去。

关于PhpUnit ...Killed 为什么会被杀死?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30685945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com