简体   繁体   English

PHPUnit和PHPStorm ... ResultPrinter.php错误

[英]PHPUnit and PHPStorm… ResultPrinter.php Error

Whenever I run phpunit tests from PHPStorm I get an error. 每当我从PHPStorm运行phpunit测试时,我都会收到错误消息。 I have provided more info below. 我在下面提供了更多信息。 I am not sure where I have miss configured the setup. 我不确定我在哪里错过配置设置。

My Setup 我的设置

  • Ubuntu Ubuntu的
  • PHPStorm 8.0.1 PHPStorm 8.0.1
  • PHPUnit 4.3.4 PHPUnit 4.3.4

More Info: 更多信息:

PHPUnit.phar is located at /usr/local/bin/phpunit.phar . PHPUnit.phar位于/usr/local/bin/phpunit.phar I have setup PHPUnit path directly in PHPStorm. 我已经在PHPStorm中直接设置了PHPUnit路径。 Tests run from bash with no issues. 测试从bash运行没有问题。 I have also setup my configuration file phpunit.xml in PHPUnit, which is located in the root of my project. 我还在PHPUnit中设置了我的配置文件phpunit.xml ,它位于我项目的根目录中。 The phpunit.xml file tells phpunit to load the composer autoload.php file. phpunit.xml文件告诉phpunit加载composer autoload.php文件。

PHPUnit Output: PHPUnit输出:

/usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 /tmp/ide-phpunit.php --configuration /home/mkelley/projects/CompanyName/phpunit.xml
Testing started at 10:33 AM ...
PHPUnit 4.3.4 by Sebastian Bergmann.

Configuration read from /home/mkelley/projects/CompanyName/phpunit.xml

PHP Fatal error:  Call to undefined method  CompanyNameTests\Boundaries\BoardMemberVotingBoundaryTest::hasExpectationOnOutput() in phar:///usr/local/bin/phpunit.phar/phpunit/TextUI/ResultPrinter.php on line 545
PHP Stack trace:
PHP   1. {main}() /tmp/ide-phpunit.php:0
PHP   2. IDE_Base_PHPUnit_TextUI_Command::main($exit = *uninitialized*) /tmp/ide-phpunit.php:500
PHP   3. PHPUnit_TextUI_Command->run($argv = *uninitialized*, $exit = *uninitialized*) /tmp/ide-phpunit.php:243
PHP   4. PHPUnit_TextUI_TestRunner->doRun($suite = *uninitialized*, $arguments = *uninitialized*) phar:///usr/local/bin/phpunit.phar/phpunit/TextUI/Command.php:186
PHP   5. PHPUnit_Framework_TestSuite->run($result = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:423
PHP   6. PHPUnit_Framework_TestSuite->run($result = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestSuite.php:703
PHP   7. PHPUnit_Framework_TestCase->run($result = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestSuite.php:703
PHP   8. PHPUnit_Framework_TestResult->run($test = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestCase.php:771
PHP   9. PHPUnit_Framework_TestResult->endTest($test = *uninitialized*, $time = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestResult.php:760
PHP  10. PHPUnit_TextUI_ResultPrinter->endTest($test = *uninitialized*, $time = *uninitialized*) /home/mkelley/projects/CompanyName/vendor/phpunit/phpunit/src/Framework/TestResult.php:378

Process finished with exit code 255

I have searched Google and was unable to find a similar issue. 我搜索了Google,但无法找到类似的问题。 I appreciate any help! 我感谢任何帮助!

EDIT 编辑

Here is my phpunit.xml file. 这是我的phpunit.xml文件。 PHPStorm is using this as a "Use alternative configuration file" PHPStorm将此用作“使用备用配置文件”

<?xml version="1.0" encoding="UTF-8"?>
    <phpunit backupGlobals="false"
         backupStaticAttributes="false"
         colors="true"
         bootstrap="./vendor/autoload.php"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false"
>
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

This appears to be the autoloading issue. 这似乎是自动加载问题。 When you bootstrap your app for the test suite you must initialise your autoloader, which doesn't seem to be happening, as something doesn't get found. 当您为测试套件引导应用程序时,必须初始化自动加载器,这似乎不会发生,因为找不到某些内容。 The easiest way would be to use Composer to manage the PHPUnit dependency and autoload your classes via the autoload directive. 最简单的方法是使用Composer管理PHPUnit依赖项并通过autoload指令自动加载您的类。 See the the psr-4 part in documentation . 请参阅文档中psr-4部分。

Then in your PhpStorm PHPUnit configuration window select Use custom autoloader and specify path to your vendor/autoload.php script. 然后在PhpStorm PHPUnit配置窗口中选择Use custom autoloader并指定vendor/autoload.php脚本的路径。

I will answer my own question in case someone else comes across this issue. 我会回答我自己的问题,以防其他人遇到这个问题。

The issue was autoloading PHPUnit via composer and using phpunit.phar. 问题是通过composer和phpunit.phar自动加载PHPUnit。 Once I removed the phpunit dependence from composer PHPStorm was able to successfully run all my tests. 一旦我从作曲家PHPStorm中删除了phpunit依赖,就能够成功运行我的所有测试。

Sometimes is better an image... 有时候是更好的形象......

在此输入图像描述

As you can see, you can also use your phpunit.phar file. 如您所见,您还可以使用phpunit.phar文件。

The problem isn't that you autoloading phpunit via composer, but that in the composer you use an old version of phpUnit. 问题不是你通过composer自动加载phpunit,而是在作曲家中使用旧版本的phpUnit。 In my case instead of using 4.0.0 I updated to 4.6.*. 在我的情况下,而不是使用4.0.0我更新到4.6。*。

I've been having this same issue with composer and found using the .phar didnt have any issues. 我和composer一直有同样的问题,发现使用.phar没有任何问题。 Today I've just realised slaps forehead it was just caused by installing phpunit via composer and then not reindexing the vendor folder. 今天我刚刚意识到slaps 额头只是因为通过composer安装phpunit然后没有重新索引供应商文件夹引起的。

I haven't found that I've had this issue previously when installing new packages with composer but for some reason when installing phpunit it hadn't reindexed the vendor folder causing inconsistencies. 我没有发现我之前在使用composer安装新软件包时遇到过这个问题,但出于某些原因安装phpunit时,它没有重新索引供应商文件夹导致不一致。

Reindex, everything working normally. Reindex,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM