gpt4 book ai didi

php - 为什么 PhpStorm 不知道 PHPUnit_Framework_TestCase

转载 作者:可可西里 更新时间:2023-11-01 13:27:25 25 4
gpt4 key购买 nike

我正在尝试配置 PhpStorm 2017.2 以将 PhpUnit 5 用于我的 PHP 5.6 项目。

  1. 我已经从the official source 下载了phpunit-5.7.21.phar 文件。并将它放在我的 PHP 5.6 安装目录中。

  2. PhpStorm Settings >> Languages & Frameworks >> PHP >> Test Frameworks 中,我已链接到 .phar 可执行文件并设置默认配置文件到项目根目录中的 phpunit.xml

enter image description here

  1. phpunit.xml 的内容如下:

.

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>
<testsuites>
<testsuite name="Test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

我正在尝试在 tests/unit 目录中构建测试,在该目录中我的源文件项目结构将按描述进行镜像 in the manual .例如:

// project files:
ClassOne.php
vendor/
ClassTwo.php
Utility.php

// test files
tests/unit/
ClassOneTest.php
vendor/
ClassTwoTest.php
UtilityTest.php

不过我有两个问题:

首先,我不知道如何配置 PhpStorm 以在 tests/unit/ 中创建测试以反射(reflect)项目根目录的结构。当我创建一个测试时,默认情况下该文件与项目文件放在同一目录中。

其次,我不知道如何让PhpStorm 索引PHPUnit 源代码。尽管我已经链接到如上所示的 phpunit-5.7.21.phar 文件,但在我创建测试时 IDE 会报错:

namespace vendor;
class UtilityTest extends \PHPUnit_Framework_TestCase{}

Undefined class PHPUnit_Framework_TestCase

更新 1

我通过将保存 .phar 的目录添加到 PhpStorm 包含路径解决了第二个问题,在 Settings >> Languages & Frameworks >> PHP >> Include Path 中设置选项卡。或者,我可以将 .phar 文件放在项目目录中,它将被索引。

我的第一个问题仍然需要帮助。

更新2

感谢 Ástþór 的回答,我想出了如何让 PhpStorm 在专用测试目录中镜像项目结构。转到 PhpStorm 设置 >> 目录 并选择基本测试目录。单击顶部附近的 Test 将其标记为 Test Sources Root

enter image description here

下次您创建测试时,它将自动放置在该目录中。

最佳答案

将包含源类的目录标记为“Source root”,将包含测试的目录标记为“Test Sources Root”。之后,目录将在测试创建时预先填充(例如,在源类上通过 ctrl+shift+T)。
不确定这是否适用于您的“镜像”系统:我想您仍然需要为测试部分手动调整目录

关于php - 为什么 PhpStorm 不知道 PHPUnit_Framework_TestCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45363750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com