当我尝试在集成开发环境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.'
怎么啦?当我包含pear安装版本时,测试工作正常。
//编辑示例测试类:
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
发布于 2013-04-15 14:26:41
我找到了这个问题的解决方案。
在这个测试正常运行之后,我在Edit configuration In directory中设置了我的测试目录(/path/to/my/project/tests
)的路径。
发布于 2014-11-27 10:55:26
多亏了Piotr上面的回答,这就是对我有效的方法,但我在这里提供了我必须执行的所有步骤的更准确的细节:
使其工作的步骤(在PHPStorm 8.0.1中测试):
1)在 Preferences > PHP > PHPUnit
中,确保没有为默认配置文件或默认引导程序文件设置任何内容。
2)通过 Run > Edit Configurations >
中的 Command Line
小节进行自定义的配置,并确保:
a)将 Custom working directory:
设置为 /absolute/path/to/vendor
。
b)勾选"Use alternative configuration file:“并将其设置为 /absolute/path/to/vendor/your_app/(sub_app_if_applicable)/phpunit.xml.dist
然后,您可以通过指定类和文件来运行套件中的任何测试类,或者只选中“在配置文件中定义”以根据配置运行所有这些测试类。
发布于 2013-06-23 10:22:54
我在使用composer时也遇到了同样的问题。
解决方案是将测试文件放在它自己的目录中。这是我的工作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>
如果有人有同样的问题,希望它能解决..:)
https://stackoverflow.com/questions/15971310
复制相似问题