Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model strict #6

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -63,6 +63,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
16 changes: 11 additions & 5 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 All @@ -40,12 +41,17 @@ protected function getEnvironmentSetUp($app): void
]);
}

public function testModelUnguarded()
public function test_model_unguarded()
{
$this->assertTrue(Model::isUnguarded());
}

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

public function test_locale()
{
$this->app->setLocale('en');
$this->assertEquals('en', Carbon::getLocale());
Expand All @@ -56,19 +62,19 @@ public function testLocale()
$this->assertEquals('janeiro', Str::lower(Carbon::parse('2020-01-01')->getTranslatedMonthName()));
}

public function testSchemaDefaultStringLength()
public function test_schema_default_string_length()
{
$this->assertEquals(255, Builder::$defaultStringLength);
}

public function testHttpsEnabled()
public function test_https_enabled()
{
$kernel = $this->app->make(Kernel::class);
$this->assertTrue($kernel->hasMiddleware(HttpsProtocolMiddleware::class));
$this->assertEquals('https://localhost', Url::to('/'));
}

public function testPaginatorDefaultView()
public function test_paginator_default_view()
{
$this->assertEquals('paginator-defaultView', Paginator::$defaultView);
$this->assertEquals('paginator-defaultSimpleView', Paginator::$defaultSimpleView);
Expand Down
19 changes: 14 additions & 5 deletions tests/DefaultValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@

class DefaultValuesTest extends TestCase
{
public function testModelUnguarded()
public function test_model_unguarded()
{
$this->assertFalse(Model::isUnguarded());
}

public function testEventsLocaleUpdated()
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 All @@ -26,19 +35,19 @@ public function testEventsLocaleUpdated()
Event::assertDispatched('Illuminate\Foundation\Events\LocaleUpdated');
}

public function testSchemaDefaultStringLength()
public function test_schema_default_string_length()
{
$this->assertEquals(150, Builder::$defaultStringLength);
}

public function testHttpsIsDisabledOnDevelopmentMode()
public function test_https_is_disabled_on_development_mode()
{
$kernel = $this->app->make(Kernel::class);
$this->assertFalse($kernel->hasMiddleware(HttpsProtocolMiddleware::class));
$this->assertEquals('http://localhost', Url::to('/'));
}

public function testPaginatorDefaultView()
public function test_paginator_default_view()
{
$this->assertEquals('pagination::tailwind', Paginator::$defaultView);
$this->assertEquals('pagination::simple-tailwind', Paginator::$defaultSimpleView);
Expand Down
2 changes: 1 addition & 1 deletion tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class HelpersTest extends TestCase
{
public function testStatesBR()
public function test_states_br()
{
$this->assertIsArray(statesBR());
$this->assertArrayHasKey('SP', statesBR());
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Datalogix\Utils\Tests;

use Carbon\Laravel\ServiceProvider as CarbonServiceProvider;
use Datalogix\Translation\TranslationServiceProvider;
use Datalogix\Utils\UtilsServiceProvider;
use GrahamCampbell\TestBench\AbstractPackageTestCase;

Expand All @@ -15,6 +16,6 @@ protected static function getServiceProviderClass(): string

protected static function getRequiredServiceProviders(): array
{
return [CarbonServiceProvider::class];
return [CarbonServiceProvider::class, TranslationServiceProvider::class];
}
}
Loading