[英]How do I run directory-structured tests in phpunit?
The PHPUnit docs say that I can shove all my tests into a folder and run phpunit
on the folder to execute them all in one go: PHPUnit文档说我可以把所有测试都推到一个文件夹中并在文件夹上运行
phpunit
来一次执行它们:
http://www.phpunit.de/manual/current/en/organizing-tests.html http://www.phpunit.de/manual/current/en/organizing-tests.html
But when I try on my forked copy of Slim (https://github.com/codeguy/Slim) it doesn't work! 但是,当我尝试我的Slim的分叉副本(https://github.com/codeguy/Slim)时,它不起作用! I have installed PHPUnit via PEAR so I don't think there's anything odd about it.
我已经通过PEAR安装了PHPUnit,所以我认为没有什么奇怪的。
Here's the output: 这是输出:
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
Any ideas what I'm doing wrong? 我有什么想法我做错了吗?
-EDIT- -编辑-
I'm using PHPUnit 3.5.15. 我正在使用PHPUnit 3.5.15。
Here are the contents of the directories Slim
and tests
: 以下是
Slim
和tests
目录的内容:
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
I've literally just forked Slim and cloned it, nothing fancy! 我真的只是分叉了Slim并克隆了它,没什么特别的!
Normally you issue the phpunit
command inside whichever folder contains phpunit.xml
and/or bootstrap.php
. 通常,您在包含
phpunit.xml
和/或bootstrap.php
文件夹中发出phpunit
命令。 My guess is that these are located inside the tests
folder. 我的猜测是这些都位于
tests
文件夹中。
.../Slim$ cd tests
.../Slim/tests$ phpunit
It turns out that this error is what you see when you specify a folder but the folder doesn't contain any files that match the pattern *Test.php
. 事实证明,此错误是您在指定文件夹时看到的但该文件夹不包含与模式
*Test.php
匹配的任何文件。
This is NOT my problem, however. 但是,这不是我的问题。 I'm running the tests from within a shared folder inside an Ubuntu VM using VirtualBox.
我正在使用VirtualBox在Ubuntu VM内的共享文件夹中运行测试。 This doesn't play well with PHPUnit, apparently.
显然,这与PHPUnit不太匹配。 Or it might be PHP.
或者它可能是PHP。 Either way, it's incorrectly erroring because when I move the folder into a non-shared location inside the VM it works just fine.
无论哪种方式,它都是错误的错误,因为当我将文件夹移动到VM内部的非共享位置时,它可以正常工作。
Edit 编辑
I was running VirtualBox 4.1.0 which apparently has this problem. 我正在运行VirtualBox 4.1.0,显然有这个问题。 Upgrading to 4.1.2 fixed it and everything is running fine now.
升级到4.1.2修复它,现在一切正常。 Thanks to everyone for their help.
感谢大家的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.