algolia / scout-extended

Scout Extended: The Full Power of Algolia in Laravel
https://www.algolia.com/doc/framework-integration/laravel/getting-started/introduction-to-scout-extended/
MIT License
395 stars 85 forks source link

Ignore import errors when scannig for searchables #262

Closed georgeboot closed 3 years ago

georgeboot commented 3 years ago

Fixes #213

Re-submit of #214

DevinCodes commented 3 years ago

Thank you for re-opening the PR @georgeboot !

I re-ran the tests with the right credentials, but the tests fail with the following error, would you mind having a look please?

There was 1 error:

1) Tests\Features\SearchableFinderTest::testWhenThereIsAnUnresolvableClass
Mockery\Exception\BadMethodCallException: Received Mockery_5_Illuminate_Console_OutputStyle::askQuestion(), but no expectations were specified

/home/circleci/project/vendor/symfony/console/Style/SymfonyStyle.php:288
/home/circleci/project/src/Console/Commands/SyncCommand.php:55
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Container/Util.php:37
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Container/Container.php:590
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Console/Command.php:134
/home/circleci/project/vendor/symfony/console/Command/Command.php:255
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Console/Command.php:121
/home/circleci/project/vendor/symfony/console/Application.php:1009
/home/circleci/project/vendor/symfony/console/Application.php:273
/home/circleci/project/vendor/symfony/console/Application.php:149
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Console/Application.php:93
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Console/Application.php:185
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:273
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/PendingCommand.php:137
/home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/PendingCommand.php:223
/home/circleci/project/tests/Features/SearchableFinderTest.php:20
georgeboot commented 3 years ago

@DevinCodes I can not replicate that error. How can I run tests locally without real Algolia credentials?

It seems like SyncCommand aks some interactive questions regarding on the status of the searchable and the index. The command is mocked and is not expecting this question.

If I can figure out which question it is asking, I can just add that to the mock chain and we should be good to go. Bit of a small, but it'll do.

DevinCodes commented 3 years ago

I tried to run the tests locally to see if I can reproduce. The weird thing is that the test passes when I run it in isolation, but it fails when I run the full test suite. There might be something (a mock or something similar) that happens in another test that makes this test fail.

I'll try to dig a bit deeper today.

DevinCodes commented 3 years ago

I found the issue: we only run the logic in getProjectClasses once, because we cache the retrieved classes in a static property. This prevents your test from including the non-existing file if the getProjectClasses method already ran before.

Could you please refactor this static property ($declaredClasses, see line 34 of the SearchableFinder class) so that it's not static anymore? This still allows for caching of the classes, albeit on the instance level instead of on the class level. This change should fix the issue and make the tests green. Thank you in advance!

georgeboot commented 3 years ago

@DevinCodes done