Skip to content

Commit

Permalink
unlint
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech committed Aug 7, 2024
1 parent 9357577 commit 41e4c80
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Auditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,22 @@ trait Auditable
*/
public static function bootAuditable()
{
if (static::isAuditingEnabled()) {
try {
$isAuditingEnabled = static::isAuditingEnabled();
} catch (\RuntimeException $e) {
if ($e->getMessage() !== 'A facade root has not been set.') {
throw $e;
}

/**
* Facade root has not been set. The user may be attempting to use
* their Auditable outside of the application context. We will
* just skip booting for now.
*/
return;
}

if ($isAuditingEnabled) {
static::observe(new AuditableObserver());
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/OutsideOfAppContextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace OwenIt\Auditing\Tests\Unit;

use OwenIt\Auditing\Tests\Models\Article;
use PHPUnit\Framework\TestCase;

class OutsideOfAppContextTest extends TestCase
{
public function test_can_create_new_model(): void
{
$article = new Article();
$this->assertInstanceOf(Article::class, $article);
}
}

0 comments on commit 41e4c80

Please sign in to comment.