首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >尝试从PhpStorm运行PHPUnit时出错

尝试从PhpStorm运行PHPUnit时出错
EN

Stack Overflow用户
提问于 2013-04-12 20:22:46
回答 4查看 23K关注 0票数 19

当我尝试在集成开发环境PhpStorm中运行PHPUnit测试时,我遇到了一些问题。

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

代码语言:javascript
复制
{
    "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安装版本时,测试工作正常。

//编辑示例测试类:

代码语言:javascript
复制
 class ReaderTest extends PHPUnit_Framework_TestCase
    {
        /**
         * @test
         */
        public function shouldGetReadedValue ()
        {
            $this->assertTrue(true);
        }
    }

//EDIT2跟踪:

代码语言:javascript
复制
/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
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-04-15 14:26:41

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

在这个测试正常运行之后,我在Edit configuration In directory中设置了我的测试目录(/path/to/my/project/tests)的路径。

票数 12
EN

Stack Overflow用户

发布于 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

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

票数 6
EN

Stack Overflow用户

发布于 2013-06-23 10:22:54

我在使用composer时也遇到了同样的问题。

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

代码语言:javascript
复制
<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>

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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15971310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档