Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Dec 15, 2023
1 parent 7a858ba commit 08575b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"extra": {
"laravel": {
"providers": [
"Staudenmeir\\EloquentHasManyDeep\\EloquentHasManyDeepServiceProvider"
"Staudenmeir\\EloquentHasManyDeep\\IdeHelperServiceProvider"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\ServiceProvider;
use Staudenmeir\EloquentHasManyDeep\IdeHelper\DeepRelationsHook;

class EloquentHasManyDeepServiceProvider extends ServiceProvider implements DeferrableProvider
class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProvider
{
public function boot(): void
{
Expand Down Expand Up @@ -37,9 +37,13 @@ protected function registerIdeHelperHook(): void
return;
}

$config->set('ide-helper.model_hooks', array_merge([
DeepRelationsHook::class,
], $config->get('ide-helper.model_hooks', [])));
$config->set(
'ide-helper.model_hooks',
array_merge(
[DeepRelationsHook::class],
$config->get('ide-helper.model_hooks', [])
)
);
}

protected function publishConfig(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@

namespace Tests;

use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider as BarryvdhIdeHelperServiceProvider;
use Illuminate\Foundation\Application;
use Orchestra\Testbench\TestCase;
use Staudenmeir\EloquentHasManyDeep\IdeHelperServiceProvider;
use Staudenmeir\EloquentHasManyDeep\IdeHelper\DeepRelationsHook;
use Staudenmeir\EloquentHasManyDeep\EloquentHasManyDeepServiceProvider;

class EloquentHasManyDeepServiceProviderTest extends TestCase
class IdeHelperServiceProviderTest extends TestCase
{
protected function getPackageProviders($app): array
{
return [
IdeHelperServiceProvider::class,
EloquentHasManyDeepServiceProvider::class,
];
}

public function testAutoRegistrationOfModelHook(): void
{
$this->app->loadDeferredProvider(BarryvdhIdeHelperServiceProvider::class);
$this->app->loadDeferredProvider(IdeHelperServiceProvider::class);
$this->app->loadDeferredProvider(EloquentHasManyDeepServiceProvider::class);

/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $this->app->get('config');
Expand All @@ -34,13 +27,12 @@ public function testAutoRegistrationOfModelHook(): void
}

/**
* @test
* @define-env usesIdeHelperDisabledInConfig
*/
public function testDisabledRegistrationOfModelHookFromConfig(): void
{
$this->app->loadDeferredProvider(BarryvdhIdeHelperServiceProvider::class);
$this->app->loadDeferredProvider(IdeHelperServiceProvider::class);
$this->app->loadDeferredProvider(EloquentHasManyDeepServiceProvider::class);

/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $this->app->get('config');
Expand All @@ -51,8 +43,16 @@ public function testDisabledRegistrationOfModelHookFromConfig(): void
);
}

protected function usesIdeHelperDisabledInConfig($app): void
protected function usesIdeHelperDisabledInConfig(Application $app): void
{
$app['config']->set('eloquent-has-many-deep.ide_helper_enabled', false);
}

protected function getPackageProviders($app): array
{
return [
BarryvdhIdeHelperServiceProvider::class,
IdeHelperServiceProvider::class,
];
}
}

0 comments on commit 08575b7

Please sign in to comment.