PHPUnit警告:找不到类NodeModelExtensionsTest,但它是一个特性而不是一个类。

huangapple go评论64阅读模式
英文:

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

&lt;?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&gt;testsuite&gt;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.

huangapple
  • 本文由 发表于 2023年2月16日 18:20:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470822.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定