英文:
PHPUnit warning : Class NodeModelExtensionsTest cannot be found, but it is a trait not a class
问题
我在 PhpUnit 中遇到了以下错误:
类 NodeModelExtensionsTest 无法在 /home/runner/work/baum/baum/tests/Main/Concerns/NodeModelExtensionsTest.php 中找到
奇怪的是,NodeModelExtensionsTest 是 NodeModelExtensionsTest.php 中的一个特性(trait),而不是一个类。
<?php
namespace Baum\Tests\Main\Concerns;
use Baum\Tests\Main\Models\Category;
use Baum.Tests\Main\Models\MultiScopedCategory;
use Baum.Tests\Main.Models\OrderedCategory;
use Baum.Tests\Main.Models\ScopedCategory;
use Baum.Tests\Main.Models\SoftCategory;
use Baum.Tests\Main\Support\PopulateData;
trait NodeModelExtensionsTest
{
// 下面是代码的其余部分...
}
可能的原因是什么导致了这个问题,以及如何修复它?
更多细节:
PHPUnit 10.0.7
运行时:PHP 8.1.15
这是一个开源项目的错误,可以在这里找到:GitHub Actions 失败的测试
谢谢。
英文:
I am getting the following error in PhpUnit:
> Class NodeModelExtensionsTest cannot be found in
> /home/runner/work/baum/baum/tests/Main/Concerns/NodeModelExtensionsTest.php
Odd thing is that NodeModelExtensionsTest is a trait not a class in NodeModelExtensionsTest.php
<?php
namespace Baum\Tests\Main\Concerns;
use Baum\Tests\Main\Models\Category;
use Baum\Tests\Main\Models\MultiScopedCategory;
use Baum\Tests\Main\Models\OrderedCategory;
use Baum\Tests\Main\Models\ScopedCategory;
use Baum\Tests\Main\Models\SoftCategory;
use Baum\Tests\Main\Support\PopulateData;
trait NodeModelExtensionsTest
{
//Rest of the code below...
What could be causing this issue and how can it be fixed?
More details:
> PHPUnit 10.0.7
>
> Runtime: PHP 8.1.15
This is for an open source project. Error can be found here: github actions failed test
Thanks,
答案1
得分: 2
你可以将NodeModelExtensionsTest
的trait重命名为NodeModelExtensionsTestTrait
。
从PHPUnit 10开始,你配置的测试目录中以配置的后缀结尾(参见phpunit.xml
中的testsuites>testsuite>directory
)的文件必须是扩展自PHPUnit\Framework\TestCase
的类。
不幸的是,我找不到为什么发生这种变化的解释。以下是GitHub上的一个相关问题,供参考:https://github.com/sebastianbergmann/phpunit/issues/4979。
英文:
You can rename the trait from NodeModelExtensionsTest
to NodeModelExtensionsTestTrait
.
Starting with PHPUnit 10, files in your configured test directory that end with a configured suffix (see testsuites>testsuite>directory
) in phpunit.xml
must be classes extending PHPUnit\Framework\TestCase
.
I couldn't find an explanation for why it was changed unfortunately. A related issue on GitHub for some context:
https://github.com/sebastianbergmann/phpunit/issues/4979.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论