我在PhpStorm - phpunit -c app
在OSX终端工作良好的Symfony项目中工作时遇到了麻烦。
错误如下:
Unable to attach test reporter to test framework of test framework quit unexpectedly
/Applications/MAMP/bin/php/php5.4.4/bin/php/private/var/folders/4l/hw8g4qlj6nnc37lfkc6hcj7w0000gn/T/ide-phpunit.php --bootstrap
/Users/greg/Repos/MyApp/app/bootstrap.php.cache --configuration
/Users/greg/Repos/MyApp/app/phpunit.xml.dist
MyApp'MyBundle'Tests'Controller'MyControllerTest
/Users/greg/Repos/MyApp/src/HvH/MyBundle/Tests/Controller/MyControllerTest.php
Testing started at 11:45 AM ...
Process finished with exit code 255
编辑:这是PHP日志中的错误:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The "app/" directory does not exist.' in /Users/greg/Repos/MyApp/vendor/symfony/symfony/src/Symfony/Component/Finder/Finder.php:650
我遇到了同样的问题,并在文档中找到了以下解决方案:http://symfony.com/doc/current/book/testing.html your-first-functional-test
要运行功能测试,WebTestCase类将引导应用程序的内核。在大多数情况下,这是自动发生的。但是,如果内核位于非标准目录中,则需要这样做修改phpunit.xml.dist文件来设置KERNEL_DIR环境变量到内核目录:
<phpunit> <!-- ... --> <php> <server name="KERNEL_DIR" value="/path/to/your/app/" /> </php> <!-- ... --> </phpunit>
所以检查你的phpunit.xml.dist配置文件,并尝试将绝对路径添加到你的app目录。
希望能有所帮助。
PhpStorm并不总是从项目根实例化测试运行器,要解决这个问题,请在run/debug配置中的'custom working directory'下添加项目根的绝对路径。这将使你不必在phpunit.xml.dist配置中添加应用程序的绝对路径,它还将确保可以找到文件中包含的任何相对路径(例如JSON测试数据)。
让它工作的步骤(在PHPStorm 8.0.1中测试):
1)在 Preferences > PHP > PHPUnit
确保默认配置文件或默认引导文件没有设置。
2)通过 Command Line
小节中的 Run > Edit Configurations >
自定义PHPUnit配置,并确保:
一套) Custom working directory:
, /absolute/path/to/vendor
。
b)选中"使用替代配置文件:"并将其设置为 /absolute/path/to/vendor/your_app/(sub_app_if_applicable)/phpunit.xml.dist
然后您可以通过指定类和文件来运行套件中的任何测试类,或者只是选中"Defined in the configuration file"来根据配置运行所有的测试类。
我遇到了同样的问题。如果您正在使用yii2/phpStorm,请尝试在调试配置部分的'alternative configuration file'下选择codeception.yml
而不是unit.yml
。