命令行中的PHPUnit

编程入门 行业动态 更新时间:2024-10-10 03:24:49
本文介绍了命令行中的PHPUnit-显示的依赖项列表.如何使其仅显示测试脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经在Windows 7以及PHP和Pear上安装了PHPUnit.

I have installed PHPUnit on Windows 7, with PHP and Pear.

我有一个基本的测试脚本,开始于:

I have a basic test script, to start with:

<?php class StackTest extends PHPUnit_Framework_TestCase { public function testTest() { $this->assertTrue(false); } }

我正在命令提示符下以以下方式运行它:

I'm running it from the command prompt as:

phpunit unittest testTest.php

并获得以下回报:

PHPUnit 3.6.5 by Sebastian Bergmann. F Time: 0 seconds, Memory: 2.75Mb There was 1 failure: 1) StackTest::testTest Failed asserting that false is true. C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Constraint.php:145 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Constraint.php:92 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Assert.php:2100 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Assert.php:854 C:\Users\lbassett\Dropbox\Projects\Test\testTest.php:10 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:939 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:801 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestResult.php:649 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:748 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestSuite.php:772 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestSuite.php:745 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\TestRunner.php:325 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\Command.php:187 C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\Command.php:125 C:\Program Files (x86)\PHP\PEAR\phpunit:44 FAILURES! Tests: 1, Assertions: 1, Failures: 1.

我的问题是列出的不同文件的清单很长.

My problem is the long list of different files listed.

我只想在那里查看我的测试成绩单.我想念什么吗?

I only want to see my test scrip there. Am I missing something?

推荐答案

简短版本:

这是PHPUnit中的错误. 我已修复它.在下一个较小的发行版中它将起作用.

Short Version:

It's a bug in PHPUnit. I've fixed it. With the next minor release it will work.

您已经注意到您的文件包含在回溯中

You have already noticed that your file is included in the backtrace

C:\Users\lbassett\Dropbox\Projects\Test\testTest.php:10

所以问题是,为什么在您的课程中还有其他所有内容.

so the question is why is there all that other stuff around your classes.

PHPUnit 应进行过滤,以回溯并清除所有PHPUnit类,但是由于某些原因,这似乎不起作用.

PHPUnit should filter that backtrace and strip out all the PHPUnit classes but for some reasons that seems to not work.

Linux上的输出:

The output on linux:

PHPUnit 3.6.5 by Sebastian Bergmann. F Time: 0 seconds, Memory: 3.00Mb There was 1 failure: 1) failingTest::testFail Failed asserting that false is true. /home/edo/phpunit-dev/oneFailingTest/failingTest.php:6

起初,我期望Program Files中的空格出现问题,但我已将其安装在没有空格的文件夹中,并且它也在那里中断".

I at first was expecting an issue with the spaces in Program Files but I've installed it in a folder without spaces and it "breaks" there too.

对我来说,这是PHPUnit中的错误.

For me this is a bug in PHPUnit.

我建议 you file an issue at the github issue tracker 我已修复.应该在PHPUnit 3.6.6中解决(发行时).查看修改内容.

I suggest you file an issue at the github issue tracker that the backtrace filtering seems broken on windows and I'll see if I can take care of that then. I've pushed a fix. It should be solved in PHPUnit 3.6.6 (when it is released). See the edits.

是的.这个问题似乎来自PHPUnit_Util_Filter :: phpunitFiles();.用\而不是/返回路径.

Yeah. The issue seems to come from PHPUnit_Util_Filter::phpunitFiles(); returning the paths with \ instead of /.

如果在412行中的PHPUnit/Util/GlobalState.php中放置以下代码.(在return语句之前)

If you put the following code in: PHPUnit/Util/GlobalState.php at line 412. (Before the return statement)

foreach(self::$phpunitFiles as $key => $value) { unset(self::$phpunitFiles[$key]); self::$phpunitFiles[str_replace("/", "\\", $key)] = $value; }

然后您会看到一个很好的回溯轨迹.我会看到它已在3.6.6中用一个更好的补丁修复了.

then you get a nice looking backtrace. I'll see to it that it gets fixed in 3.6.6 with a nicer patch.

更多推荐

命令行中的PHPUnit

本文发布于:2023-06-03 09:49:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/471188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   PHPUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!