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 测试中回显


基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在多维数组中查找最大值 2021-01-01