没有不值得去解决的问题,也没有不值得去学习的技术!

编写 Lighthouse 5 的自动化测试用例时,PhpStorm 不能够自动完成(无法找到要转到的声明)的解决

编写 Lighthouse 5 的自动化测试用例时,PhpStorm 不能够自动完成。点击 $response->assertJson 时,无法找到要转到的声明。方法 'assertJson' 在 \Illuminate\Testing\TestResponse 中未找到
1、编写 Lighthouse 5 的自动化测试用例时,PhpStorm 不能够自动完成。点击 $response->assertJson 时,无法找到要转到的声明。方法 ‘assertJson’ 在 \Illuminate\Testing\TestResponse 中未找到。如图1
编写 Lighthouse 5 的自动化测试用例时,PhpStorm 不能够自动完成。点击 $response->assertJson 时,无法找到要转到的声明。方法 'assertJson' 在 \Illuminate\Testing\TestResponse 中未找到
图1
2、打印 $response 对象,其实际路径为:\Illuminate\Foundation\Testing\TestResponse。如图2
打印 $response 对象,其实际路径为:\Illuminate\Foundation\Testing\TestResponse
图2


PS E:\wwwroot\object> ./vendor/bin/phpunit --process-isolation .\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

E..                                                                 3 / 3 (100%)

Time: 11.89 seconds, Memory: 16.00 MB

There was 1 error:

1) Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest::testGetThemeById
PHPUnit\Framework\Exception: Illuminate\Foundation\Testing\TestResponse Object
(
    [baseResponse] => Illuminate\Http\Response Object
        (
            [headers] => Symfony\Component\HttpFoundation\ResponseHeaderBag Object
                (
                    [computedCacheControl:protected] => Array
                        (
                            [no-cache] => 1
                            [private] => 1
                        )

                    [cookies:protected] => Array
                        (
                        )

                    [headerNames:protected] => Array
                        (
                            [cache-control] => Cache-Control
                            [date] => Date
                            [content-type] => Content-Type
                        )

                    [headers:protected] => Array
                        (
                            [cache-control] => Array
                                (
                                    [0] => no-cache, private
                                )

                            [date] => Array
                                (
                                    [0] => Thu, 17 Feb 2022 06:16:07 GMT
                                )

                            [content-type] => Array
                                (
                                    [0] => application/json
                                )

                        )

                    [cacheControl:protected] => Array
                        (
                        )

                )

            [content:protected] => {"data":{"onlineStoreTheme":{"id":"vogue","editable":false,"createdAt":"2022-02-17 14:16:07","name":"vogue"}}}
            [version:protected] => 1.1
            [statusCode:protected] => 200
            [statusText:protected] => OK
            [charset:protected] =>
            [original] => Array
                (
                    [data] => Array
                        (
                            [onlineStoreTheme] => Array
                                (
                                    [id] => vogue
                                    [editable] =>
                                    [createdAt] => 2022-02-17 14:16:07
                                    [name] => vogue
                                )

                        )

                )

            [exception] =>
        )

    [streamedContent:protected] =>
)

phpvfscomposer://E:\wwwroot\object\vendor\phpunit\phpunit\phpunit:60



3、在另一个项目中,PhpStorm 能够自动完成。如图3
在另一个项目中,PhpStorm 能够自动完成
图3
4、在另一个项目中,打印 $response 对象,其实际路径为:\Illuminate\Testing\TestResponse。相对于无法定位方法的项目,缺少了 \Foundation。如图4
在另一个项目中,打印 $response 对象,其实际路径为:\Illuminate\Testing\TestResponse。相对于无法定位方法的项目,缺少了 \Foundation
图4


PS E:\wwwroot\lighthouse-tutorial> ./vendor/bin/phpunit --process-isolation .\tests\Feature\PostsGraphQlApiTest.php
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 00:07.704, Memory: 12.00 MB

There was 1 error:

1) Tests\Feature\PostsGraphQlApiTest::testQueriesPosts
PHPUnit\Framework\Exception: Illuminate\Testing\TestResponse Object
(
    [baseResponse] => Illuminate\Http\Response Object
        (
            [headers] => Symfony\Component\HttpFoundation\ResponseHeaderBag Object
                (
                    [computedCacheControl:protected] => Array
                        (
                            [no-cache] => 1
                            [private] => 1
                        )

                    [cookies:protected] => Array
                        (
                        )

                    [headerNames:protected] => Array
                        (
                            [cache-control] => Cache-Control
                            [date] => Date
                            [content-type] => Content-Type
                        )

                    [headers:protected] => Array
                        (
                            [cache-control] => Array
                                (
                                    [0] => no-cache, private
                                )

                            [date] => Array
                                (
                                    [0] => Thu, 17 Feb 2022 06:25:24 GMT
                                )

                            [content-type] => Array
                                (
                                    [0] => application/json
                                )

                        )

                    [cacheControl:protected] => Array
                        (
                        )

                )



5、参考网址:https://www.shuijingwanwq.com/2022/01/26/5827/ ,怀疑与此问题类似。在 Laravel Framework 6.20.44、nuwave/lighthouse v5.36.0 中,版本不匹配所导致。因为在另一个项目中,版本分别为:Laravel Framework 8.78.1、nuwave/lighthouse v5.35.0,版本是匹配的。 6、计划在当前项目中,将 nuwave/lighthouse v5.36.0 回退至 ~4.10.1。执行 composer remove nuwave/lighthouse 命令,卸载 nuwave/lighthouse。执行 composer require nuwave/lighthouse:~4.10.1 命令,安装 nuwave/lighthouse。回退至 nuwave/lighthouse v4.10.2 后,已经能够自动完成。如图5
计划在当前项目中,将 nuwave/lighthouse v5.36.0 回退至 ~4.10.1。执行 composer remove nuwave/lighthouse 命令,卸载 nuwave/lighthouse。执行 composer require nuwave/lighthouse:~4.10.1 命令,安装 nuwave/lighthouse。回退至 nuwave/lighthouse v4.10.2 后,已经能够自动完成
图5
7、点击跳转,其文件路径为:\Illuminate\Foundation\Testing\TestResponse。如图6
点击跳转,其文件路径为:\Illuminate\Foundation\Testing\TestResponse
图6
8、在 Issues 中搜索:\Illuminate\Testing\TestResponse,确认已经有人遇见过类似的问题:Refine test helper return types for static analysis。如图7
在 Issues 中搜索:\Illuminate\Testing\TestResponse,确认已经有人遇见过类似的问题:Refine test helper return types for static analysis。
图7
9、因为 Laravel 在 v7 中移动了 TestResponse。官方建议使用:https://github.com/nuwave/lighthouse/releases/tag/v4.12.2 。可与 Laravel 7 完美配合。仍然与 Laravel 6 兼容。如图8
因为 Laravel 在 v7 中移动了 TestResponse。官方建议使用:https://github.com/nuwave/lighthouse/releases/tag/v4.12.2 。可与 Laravel 7 完美配合。仍然与 Laravel 6 兼容
图8

PHP / Laravel / Yii2 老项目维护与长期技术支持

如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。

适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护

可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查

如需咨询,请联系我,并注明:PHP 维护咨询

联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理