19

当我尝试在 IDE PhpStorm 中运行 PHPUnit 测试时,我没有什么问题。

我使用 Composer 文件,它看起来:

{
    "require": {
        "phpunit/phpunit": "3.7.19"
    }
}

现在,当我运行测试时,我收到异常: PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.'

怎么了?当我包括梨安装版本测试工作正常。

//编辑 示例测试类:

 class ReaderTest extends PHPUnit_Framework_TestCase
    {
        /**
         * @test
         */
        public function shouldGetReadedValue ()
        {
            $this->assertTrue(true);
        }
    }

// EDIT2 跟踪:

/usr/bin/php /tmp/ide-phpunit.php --no-configuration /path/to/my/project
Testing started at 14:53 ...
PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.' in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:183
Stack trace:
#0 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(315): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass))
#1 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(389): PHPUnit_Framework_TestSuite->addTestSuite(Object(ReflectionClass))
#2 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('/var/www/php-sh...')
#3 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Runner/BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#4 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php(150): PHPUnit_Runner_BaseTestRunner->getTest('/var/www/php-sh...', '', A in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php on line 183

Process finished with exit code 255
4

4 回答 4

12

我找到了关于这个问题的解决方案。

/path/to/my/project/tests在此测试正常运行后,在目录中的编辑配置中,我设置了测试目录 ( ) 的路径。

于 2013-04-15T06:26:41.280 回答
6

这对我有用,这要感谢 Piotr 上面的回答,但我在这里提供了更准确的细节,所有我必须做的步骤:

使其工作的步骤(在 PHPStorm 8.0.1 中测试):

1) Preferences > PHP > PHPUnit 确保没有为默认配置文件或默认引导文件设置任何内容。

2)通过 Run > Edit Configurations > Command Line 小节中进行自定义 PHPUnit 配置,并确保:

a) 设置 Custom working directory: /absolute/path/to/vendor

b)选中“使用替代配置文件:”并将其设置为 /absolute/path/to/vendor/your_app/(sub_app_if_applicable)/phpunit.xml.dist

然后您可以通过指定类和文件来运行套件中的任何测试类,或者只需选中“在配置文件中定义”即可根据配置运行所有测试类。

于 2014-11-27T02:55:25.810 回答
5

使用作曲家时我有同样的问题。

解决方案是将您的测试文件放在它自己的目录中。这是我的工作 phpunit,我将所有测试都放在test目录中。

<phpunit bootstrap="vendor/autoload.php" 
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    stopOnFailure="true">
    <testsuites>
        <testsuite name="Test Suite">
            <directory>test</directory>
        </testsuite>
    </testsuites>
</phpunit>

希望它解决如果有人有同样的问题.. :)

于 2013-06-23T02:22:53.680 回答
0

在 PHPUnit_Framework_TestSuite 内部,此代码存在于构造函数中

if (!$theClass->isSubclassOf('PHPUnit_Framework_TestCase')) {
   throw new PHPUnit_Framework_Exception(
      'Class "' . $theClass->name . '" does not extend PHPUnit_Framework_TestCase.'
   );
}

我在您的示例中看到您正在扩展,PHPUnit_Framework_TestCase但错误表明您正在使用PHPUnit_Extensions_RepeatedTestwhich extendsPHPUnit_Extensions_TestDecorator最终扩展PHPUnit_Framework_Assert

PHPUnit_Framework_Assert
   |
   --PHPUnit_Extensions_TestDecorator
      |
      --PHPUnit_Extensions_RepeatedTest

仔细检查您的测试,因为错误表明您正在尝试使用测试扩展来运行 TestSuite PHPUnit_Extensions_RepeatedTest。您是否尝试使用测试装饰器来扩展 PHUnit?

http://docs.tadiavo.com/phpunit/www.phpunit.de/pocket_guide/3.1/en/extending-phpunit.html

这就是我目前可以提供的所有建议,而无需查看您的实际测试以及您如何运行它们。

于 2013-04-12T12:55:18.390 回答