echo in phpunit tests(在 phpunit 测试中回显)
问题描述
我一直在尝试在我的 phpunit 测试中 echo
东西,但到目前为止没有运气.
I have been trying to echo
stuff in my phpunit tests but no luck so far.
我阅读了有关 xml 配置文件的文档,显然 debug
参数是我正在寻找的.不幸的是,它仍然不起作用.无论如何,这是我的 xml 配置文件:
I read the documentation about the xml config file and apparently the debug
parameter is what I am looking for. Unfortunately it still doesn't work. Anyhow here is my xml config file:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
processIsolation="true"
verbose="true"
debug="true">
</phpunit>
processIsolation
和 verbose
都被接受,但 debug
不被接受.
Both processIsolation
and verbose
are accepted but debug
is not.
当我像这样直接将它传递给 phpunit 时,该命令实际上工作得很好:
The command actually works pretty fine when I directly pass it to phpunit like this:
phpunit --debug MyTest.php # here stuff is echoed correctly
但是对于 xml 配置文件,它看起来被忽略了.
but with the xml config file it looks like it is ignored.
推荐答案
当前版本的 PHPUnit >3.6.4
(以及所有 3.5.*
版本)将只是打印您在测试用例中echo
的所有内容.
Current versions of PHPUnit >3.6.4
(and all 3.5.*
versions) will just print everything you echo
in a test case.
<?php
class OutputTestCase extends PHPUnit_Framework_TestCase {
public function testEcho() {
echo "Hi";
}
}
产生:
phpunit foo.php
PHPUnit 3.6.7 by Sebastian Bergmann.
.Hi
Time: 0 seconds, Memory: 3.25Mb
OK (1 test, 0 assertions)
因此,如果您使用的是旧的 3.6
版本,只需升级 :)
So if you are on an old 3.6
version just upgrade :)
这篇关于在 phpunit 测试中回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 phpunit 测试中回显


- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01