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/wshop/platform> ./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/wshop/platform>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250759.html