phpunit 运行异常时运行一个非常简单的单元测试


phpunit running exception when run a very very simple unit test

  1. 我得到phpunit并使用最简单的方法将其安装为此链接进行测试。我只是下载phpunit.phar文件,chmod&rename并移动到/usr/local/bin然后,我运行phpunit --version,没关系。

  2. 我写了一个简单的php测试用例。

    class SimpleTest extends PHPUnit_Framework_TestCase {
        public function testSomething(){
           $this -> assertTrue(true);
        }
    }
    
  3. 在终端中,我转到我的php类文件夹,然后执行

    phpunit --colors SimpleTest
    
  4. 现在我得到了例外

    PHP ReflectionException:  Method suite does not exist 
    in phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php on line 113
    PHP Stack trace:
    PHP   1. {main}() /usr/local/bin/phpunit:0
    PHP   2. PHPUnit_TextUI_Command::main($exit = *uninitialized*)
             /usr/local/bin/phpunit:612
    PHP   3. PHPUnit_TextUI_Command->run($argv = array (
             0 =>  '/usr/local/bin/phpunit', 
             1 => '--colors', 
             2 => 'SimpleTest.php'), 
             $exit = TRUE) 
            phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:129
    
    PHP   4. PHPUnit_Runner_BaseTestRunner->getTest(
           $suiteClassName = 'SimpleTest',   
           $suiteClassFile = '/home/kevin/Workspace/php/laravel/app/tests/SimpleTest.php',   
           $suffixes = array (0 => 'Test.php', 1 => '.phpt')) 
           phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:150
    PHP   5. ReflectionClass->getMethod('suite')    
    phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php:113
    PHPUnit 3.7.27 by Sebastian Bergmann.
    

欢迎任何事情,谢谢。

看起来此错误来自 xdebug 设置。

解决方案似乎是将这一行添加到您的 php.ini 文件中(或将现有值更改为 0):

xdebug.show_exception_trace = 0

看看PHPUnit ReflectionException Method 套件不存在,并且为什么 PHPUnit 隐藏了我的 xdebug 回溯?了解更多信息。