1、在 Laravel 6.20.43、Lighthouse 5.45.0 中,类 ‘ClearsSchemaCache’ 已弃用 。如图1

<?php
namespace Modules\ThemeStore\Tests\Functional\GraphQl;
use Nuwave\Lighthouse\Testing\MakesGraphQLRequests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Nuwave\Lighthouse\Testing\ClearsSchemaCache;
use Tests\CreatesApplication;
class ThemeAssetGraphQlApiTest extends BaseTestCase
{
use CreatesApplication,
ClearsSchemaCache,
MakesGraphQLRequests;
protected function setUp(): void
{
parent::setUp();
$this->bootClearsSchemaCache();
}
}2、缘由应该在于 Lighthouse 的版本变化所导致。类 ‘ClearsSchemaCache’ 的作用为在运行任何测试之前先清除掉模式缓存。
3、参考:https://lighthouse-php.com/5/testing/phpunit.html#setup ,决定替换为 类 ‘RefreshesSchemaCache’
4、编辑 /Modules/ThemeStore/Tests/Functional/GraphQl/ThemeAssetGraphQlApiTest.php。如图2

<?php
namespace Modules\ThemeStore\Tests\Functional\GraphQl;
use Nuwave\Lighthouse\Testing\MakesGraphQLRequests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Nuwave\Lighthouse\Testing\RefreshesSchemaCache;
use Tests\CreatesApplication;
class ThemeAssetGraphQlApiTest extends BaseTestCase
{
use CreatesApplication,
ClearsSchemaCache,
MakesGraphQLRequests;
protected function setUp(): void
{
parent::setUp();
$this->bootRefreshesSchemaCache();
}
}
5、运行测试,测试通过。如图3

PS E:\wwwroot\object> .\vendor\bin\phpunit --process-isolation .\Modules\ThemeStore\Tests\Functional\GraphQl\ThemeAssetGraphQlApiTest.php
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
... 3 / 3 (100%)
Time: 7.73 seconds, Memory: 16.00 MB
OK (3 tests, 11 assertions)
PS E:\wwwroot\object>
PHP / Laravel / Yii2 老项目维护与长期技术支持
如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。
适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护
可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查
如需咨询,请联系我,并注明:PHP 维护咨询。
联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com
