Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试从PhpStorm运行PHPUnit时出错_Php_Testing_Phpunit_Phpstorm_Composer Php - Fatal编程技术网

尝试从PhpStorm运行PHPUnit时出错

尝试从PhpStorm运行PHPUnit时出错,php,testing,phpunit,phpstorm,composer-php,Php,Testing,Phpunit,Phpstorm,Composer Php,当我试图在IDEPHPStorm中运行PHPUnit测试时,我没有什么问题 我使用的composer文件如下所示: { "require": { "phpunit/phpunit": "3.7.19" } } 现在,当我运行测试时,我收到异常: PHP致命错误:未捕获的异常“PHPUnit\u Framework\u exception”和消息“Class“PHPUnit\u Extensions\u RepeatedTest”不扩展PHPUnit\u Fram

当我试图在IDEPHPStorm中运行PHPUnit测试时,我没有什么问题

我使用的composer文件如下所示:

{
    "require": {
        "phpunit/phpunit": "3.7.19"
    }
}
现在,当我运行测试时,我收到异常:
PHP致命错误:未捕获的异常“PHPUnit\u Framework\u exception”和消息“Class“PHPUnit\u Extensions\u RepeatedTest”不扩展PHPUnit\u Framework\u TestCase”。

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

//编辑 样本测试类别:

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


在PHPUnit_框架_测试套件中,以下代码:

我在您的示例中看到您正在扩展
PHPUnit\u框架测试用例
,但错误表明您正在使用
PHPUnit\u扩展\u重复测试
,它扩展了
PHPUnit\u扩展\u测试装饰器
,最终扩展了
PHPUnit\u框架\u断言

PHPUnit_Framework_Assert
   |
   --PHPUnit_Extensions_TestDecorator
      |
      --PHPUnit_Extensions_RepeatedTest
仔细检查您的测试,因为错误表明您正在尝试使用测试扩展
PHPUnit\u Extensions\u RepeatedTest运行测试套件。您是否尝试使用测试装饰器来扩展PHUnit


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

我找到了解决此问题的方法


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

解决方案是将测试文件放在它自己的目录中。这是我的工作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>

测试

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

多亏了Piotr上面的回答,这对我来说是有效的,但我在这里提供了一个更精确的细节——我必须完成的所有步骤:

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

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

2)通过
命令行
小节中的
运行>编辑配置
进行自定义PHPUnit配置,并确保:

a)将
自定义工作目录:
设置为
/absolute/path/to/vendor

b)选中“使用备用配置文件:”并将其设置为
/absolute/path/to/vendor/your_app/(sub_app_,如果适用)/phpunit.xml.dist


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

你能展示你的单元测试吗?您的测试类是否扩展了PHPUnit\u Framework\u测试用例?我编辑了我的问题,并添加了示例测试类。我有几个测试类。好吧,但为什么当我从控制台运行测试时一切都正常呢?我很肯定我的考试很好。当我将PHPUnit用作包含外部库并在PhpStorm中设置适当的配置时,效果很好。您的问题指出它在PhpStorm中不起作用。也许您的IDE配置不正确,现在它可以工作了?我是像在手册中一样配置IDE的。我成功地添加了依赖项,然后将自定义加载程序设置为
vendor/autoload.php
。这就是我所做的。需要注意的是,必须通过以下方式设置路径:
Run>Edit Configuration>PhpUnit
,在那里,可以设置
目录
。在PhpStorm中的
文件>设置下找不到(!)此选项。
PHPUnit_Framework_Assert
   |
   --PHPUnit_Extensions_TestDecorator
      |
      --PHPUnit_Extensions_RepeatedTest
<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>