在phpunit测试中回显 [英] echo in phpunit tests
问题描述
我一直在尝试在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
.
当我将命令直接传递给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测试中回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!