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

Error When Running Lighthouse Test Cases: Class ‘Overtrue\LaravelVersionable\ServiceProvider’ Not Found

运行 Lighthouse 的测试用例时,报错:Class 'Overtrue\LaravelVersionable\ServiceProvider' not found

1. When running the Lighthouse test cases, an error occurred: Class ‘Overtrue\LaravelVersionable\ServiceProvider’ not found. See Figure 1.

When running the Lighthouse test cases, an error occurred: Class 'Overtrue\LaravelVersionable\ServiceProvider' not found
Figure 1
Plaintext

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

E                                                                   1 / 1 (100%)

Time: 350 ms, Memory: 30.00 MB

There was 1 error:

1) Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest::testGetThemeById
Error: Class 'Overtrue\LaravelVersionable\ServiceProvider' not found

E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:208
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:144
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:61
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:593
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterProviders.php:17
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:219
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:320
E:\wwwroot\object\tests\CreatesApplication.php:18
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:102
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:81
E:\wwwroot\object\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php:76
phpvfscomposer://E:\wwwroot\object\vendor\phpunit\phpunit\phpunit:60

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
PS E:\wwwroot\object>

2. Searched for the class Overtrue\LaravelVersionable\ServiceProvider in the IDE, but it was not found. See Figure 2.

Searched for the class Overtrue\LaravelVersionable\ServiceProvider in the IDE, but it was not found
Figure 2

3. Searched for the code LaravelVersionable in the project and found that the file /bootstrap/cache/packages.phpunit.php contains: Overtrue\\LaravelVersionable\\ServiceProvider. See Figure 3.

Searched for the code LaravelVersionable in the project and found that the file /bootstrap/cache/packages.phpunit.php contains: Overtrue\\LaravelVersionable\\ServiceProvider
Figure 3

4. Checked the directory /vendor/overtrue, and the folder laravel-versionable does not exist. This confirms that the package is not installed, yet it is still declared in the cache. See Figure 4.

Checked the directory /vendor/overtrue, and the folder laravel-versionable does not exist. This confirms that the package is not installed, yet it is still declared in the cache
Figure 4

5. Viewed the existing cache files under /bootstrap/cache, as shown in Figure 5.

Viewed the existing cache files under /bootstrap/cache
Figure 5

6. The cause is likely a previous local Git reset, which resulted in an incorrect cache. The cache should not have been committed to Git in the first place. I ultimately decided to manually delete the cache files under the /bootstrap/cache directory. I ran the tests again, and they passed. See Figure 6.

The cause is likely a previous local Git reset, which resulted in an incorrect cache. The cache should not have been committed to Git in the first place. I ultimately decided to manually delete the cache files under the /bootstrap/cache directory. I ran the tests again, and they passed
Figure 6
Plaintext

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

.                                                                   1 / 1 (100%)

Time: 9.42 seconds, Memory: 60.00 MB

OK (1 test, 14 assertions)
PS E:\wwwroot\object>

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系