1. When writing automated test cases for Lighthouse 5, PhpStorm cannot autocomplete. Clicking $response->assertJson fails to find the declaration to go to. Method ‘assertJson’ not found in \Illuminate\Testing\TestResponse. See Figure 1.

2. Printing the $response object reveals its actual path is: \Illuminate\Foundation\Testing\TestResponse. See Figure 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. In another project, PhpStorm can autocomplete. See Figure 3.

4. In the other project, printing the $response object reveals its actual path is: \Illuminate\Testing\TestResponse. Compared to the project where the method cannot be located, it is missing \Foundation. See Figure 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. Reference URL: https://www.shuijingwanwq.com/2022/01/26/5827/ . I suspect it is similar to this issue. In Laravel Framework 6.20.44 and nuwave/lighthouse v5.36.0, this is caused by a version mismatch. In the other project, the versions are Laravel Framework 8.78.1 and nuwave/lighthouse v5.35.0, which are matching.
6. I plan to roll back nuwave/lighthouse v5.36.0 to ~4.10.1 in the current project. Run the composer remove nuwave/lighthouse command to uninstall nuwave/lighthouse. Run the composer require nuwave/lighthouse:~4.10.1 command to install nuwave/lighthouse. After rolling back to nuwave/lighthouse v4.10.2, autocompletion works. See Figure 5.

7. Clicking to jump to it shows the file path is: \Illuminate\Foundation\Testing\TestResponse. See Figure 6.

8. Searching for \Illuminate\Testing\TestResponse in the Issues confirms that someone else has encountered a similar problem: Refine test helper return types for static analysis. See Figure 7.

9. Because Laravel moved TestResponse in v7. The official recommendation is to use: https://github.com/nuwave/lighthouse/releases/tag/v4.12.2 . It works perfectly with Laravel 7 and is still compatible with Laravel 6. See Figure 8.

