From 543286f2ad8a93f364d4cb4dcece0d9bb43f9d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Wit?= Date: Mon, 27 Jan 2025 14:08:55 +0100 Subject: [PATCH] Update ServiceProvider to be deferred --- ...perHookTranslatableServiceProviderTest.php | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/tests/Integration/LaravelIdeHelperHookTranslatableServiceProviderTest.php b/tests/Integration/LaravelIdeHelperHookTranslatableServiceProviderTest.php index 5a7352f..d884bec 100644 --- a/tests/Integration/LaravelIdeHelperHookTranslatableServiceProviderTest.php +++ b/tests/Integration/LaravelIdeHelperHookTranslatableServiceProviderTest.php @@ -4,19 +4,22 @@ namespace DanielDeWit\LaravelIdeHelperHookTranslatable\Tests\Integration; +use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider; use DanielDeWit\LaravelIdeHelperHookTranslatable\Hooks\TranslatableHook; use DanielDeWit\LaravelIdeHelperHookTranslatable\Providers\LaravelIdeHelperHookTranslatableServiceProvider; +use Illuminate\Contracts\Config\Repository; +use Illuminate\Foundation\Application; use Orchestra\Testbench\TestCase; class LaravelIdeHelperHookTranslatableServiceProviderTest extends TestCase { /** - * @param \Illuminate\Foundation\Application $app - * @return string[] + * {@inheritDoc} */ protected function getPackageProviders($app): array { return [ + IdeHelperServiceProvider::class, LaravelIdeHelperHookTranslatableServiceProvider::class, ]; } @@ -24,8 +27,40 @@ protected function getPackageProviders($app): array /** * @test */ - public function it_adds_the_translatable_hook_to_the_config(): void + public function it_auto_registers_model_hook(): void { - static::assertContains(TranslatableHook::class, config('ide-helper.model_hooks')); + /** @var Application $app */ + $app = $this->app; + + $app->loadDeferredProvider(IdeHelperServiceProvider::class); + $app->loadDeferredProvider(LaravelIdeHelperHookTranslatableServiceProvider::class); + + /** @var Repository $config */ + $config = $app->get('config'); + + $this->assertContains( + TranslatableHook::class, + (array) $config->get('ide-helper.model_hooks', []), + ); + } + + /** + * @test + */ + public function it_auto_registers_model_hook_with_wrong_service_provider_order(): void + { + /** @var Application $app */ + $app = $this->app; + + $app->loadDeferredProvider(LaravelIdeHelperHookTranslatableServiceProvider::class); + $app->loadDeferredProvider(IdeHelperServiceProvider::class); + + /** @var Repository $config */ + $config = $app->get('config'); + + $this->assertContains( + TranslatableHook::class, + (array) $config->get('ide-helper.model_hooks', []), + ); } }