在 Laravel 6.20.43、Lighthouse 5.45.0 中,类 ‘ClearsSchemaCache’ 已弃用

1、在 Laravel 6.20.43、Lighthouse 5.45.0 中,类 ‘ClearsSchemaCache’ 已弃用 。如图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

编辑 /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

运行测试,测试通过

图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

(0)
上一篇 2022年5月1日
下一篇 2022年5月1日

相关推荐

发表回复

登录后才能评论