在 phpunit 测试中回显 [英] echo in phpunit tests

查看:19
本文介绍了在 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> 

processIsolationverbose 都被接受,但 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 测试中回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆