Skip to content

Commit

Permalink
Update ServiceProvider to be deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-de-wit committed Jan 27, 2025
1 parent 5d590ed commit 543286f
Showing 1 changed file with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,63 @@

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,
];
}

/**
* @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', []),
);
}
}

0 comments on commit 543286f

Please sign in to comment.