Skip to content

Commit

Permalink
Merge pull request #6 from datalogix/feat-model-strict
Browse files Browse the repository at this point in the history
Add model strict
  • Loading branch information
ricardogobbosouza authored Dec 13, 2024
2 parents 3f3c6df + 9626627 commit 56625c2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

return [
'model' => [
'strict' => env('UTILS_MODEL_STRICT', ! app()->environment('production')),
'unguard' => env('UTILS_MODEL_UNGUARD', false),
],

Expand Down
4 changes: 4 additions & 0 deletions src/UtilsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ private function bootPublishes()
*/
private function bootModel()
{
if (method_exists(Model::class, 'shouldBeStrict')) {
Model::shouldBeStrict(config('utils.model.strict'));
}

Model::unguard(config('utils.model.unguard'));
}

Expand Down
6 changes: 6 additions & 0 deletions tests/CustomValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected function getEnvironmentSetUp($app): void
{
$app->config->set('utils', [
'model' => [
'strict' => false,
'unguard' => true,
],

Expand Down Expand Up @@ -45,6 +46,11 @@ public function test_model_unguarded()
$this->assertTrue(Model::isUnguarded());
}

public function test_model_strict()
{
$this->assertFalse(Model::preventsLazyLoading());
}

public function test_locale()
{
$this->app->setLocale('en');
Expand Down
9 changes: 9 additions & 0 deletions tests/DefaultValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ public function test_model_unguarded()
$this->assertFalse(Model::isUnguarded());
}

public function test_model_strict()
{
if (method_exists(Model::class, 'shouldBeStrict')) {
$this->assertTrue(Model::preventsLazyLoading());
} else {
$this->markTestSkipped();
}
}

public function test_events_locale_updated()
{
Event::fake();
Expand Down

0 comments on commit 56625c2

Please sign in to comment.