【问题标题】:How do I run directory-structured tests in phpunit?如何在 phpunit 中运行目录结构测试?
【发布时间】:2011-09-01 20:50:08
【问题描述】:

PHPUnit 文档说我可以将所有测试放入一个文件夹并在该文件夹上运行 phpunit 以一次性执行它们:

http://www.phpunit.de/manual/current/en/organizing-tests.html

但是当我尝试使用我的分叉副本 Slim (https://github.com/codeguy/Slim) 时,它不起作用!我已经通过 PEAR 安装了 PHPUnit,所以我不认为有什么奇怪的地方。

这是输出:

mark@ubuntu:/project/submodules/Slim$ phpunit tests     
PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "tests.php" nor "tests.php" could be opened.' in /usr/share/php/PHPUnit/Util/Skeleton/Test.php:102
Stack trace:
#0 /usr/share/php/PHPUnit/TextUI/Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('tests', '')
#1 /usr/share/php/PHPUnit/TextUI/Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#2 /usr/bin/phpunit(49): PHPUnit_TextUI_Command::main()
#3 {main}
  thrown in /usr/share/php/PHPUnit/Util/Skeleton/Test.php on line 102

任何想法我做错了什么?

-编辑-

我正在使用 PHPUnit 3.5.15。

这里是目录Slimtests的内容:

mark@ubuntu:/project/submodules/Slim$ ls -l 
total 20
-rw-r--r-- 1 mark mark 4320 Aug 23 14:41 README.markdown
drwxr-xr-x 1 mark mark  408 Aug 24 02:39 Slim
-rw-r--r-- 1 mark mark 6993 Aug 23 14:41 index.php
-rw-r--r-- 1 mark mark 1398 Aug 23 14:41 logo.png
drwxr-xr-x 1 mark mark  476 Aug 23 14:41 tests
mark@ubuntu:/project/submodules/Slim$ ls -l tests
total 104
-rw-r--r-- 1 mark mark    73 Aug 23 14:41 Foo.php
drwxr-xr-x 1 mark mark   204 Aug 23 14:41 Http
-rw-r--r-- 1 mark mark  4398 Aug 23 14:41 LogTest.php
-rw-r--r-- 1 mark mark  5088 Aug 23 14:41 LoggerTest.php
-rw-r--r-- 1 mark mark   734 Aug 23 14:41 README
-rw-r--r-- 1 mark mark 11115 Aug 23 14:41 RouteTest.php
-rw-r--r-- 1 mark mark 10327 Aug 23 14:41 RouterTest.php
drwxr-xr-x 1 mark mark   102 Aug 23 14:41 Session
-rw-r--r-- 1 mark mark 47703 Aug 23 14:41 SlimTest.php
-rw-r--r-- 1 mark mark  6447 Aug 23 14:41 ViewTest.php
drwxr-xr-x 1 mark mark   102 Aug 23 14:41 logs
drwxr-xr-x 1 mark mark   102 Aug 23 14:41 templates

我实际上只是将 Slim 分叉并克隆了它,没什么特别的!

【问题讨论】:

  • 你能粘贴Slimtests文件夹的内容吗?
  • 为我工作。那是什么 PHPUnit 版本?
  • 这是 PHPUnit v3.5.15。我将编辑问题以包含文件夹的内容。谢谢!

标签: php phpunit slim


【解决方案1】:

通常您在包含phpunit.xml 和/或bootstrap.php 的文件夹中发出phpunit 命令。我的猜测是这些位于tests 文件夹内。

.../Slim$ cd tests
.../Slim/tests$ phpunit

【讨论】:

  • 谢谢!我已经添加了目录内容,但不幸的是tests 文件夹中没有phpunit.xmlbootstrap.php。有任何想法吗? Slim 文档说我只需要在 Slim 目录中运行 phpunit tests...
  • 您是否尝试过从tests 目录中运行上述命令?
  • 我做到了,是的,但它失败了:(
【解决方案2】:

事实证明,当您指定一个文件夹但该文件夹不包含任何与*Test.php 模式匹配的文件时,您会看到此错误。

不过,这不是我的问题。我正在使用 VirtualBox 从 Ubuntu VM 内的共享文件夹中运行测试。显然,这不适用于 PHPUnit。或者它可能是 PHP。无论哪种方式,它都会出错,因为当我将文件夹移动到 VM 内的非共享位置时,它工作得很好。

编辑

我运行的 VirtualBox 4.1.0 显然有这个问题。升级到 4.1.2 修复了它,现在一切运行良好。感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 2011-09-21
    • 2012-01-08
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2021-12-24
    • 2010-12-26
    • 1970-01-01
    相关资源
    最近更新 更多