Skip to content

Commit 41e4c80

Browse files
committed
unlint
1 parent 9357577 commit 41e4c80

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Auditable.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,22 @@ trait Auditable
7171
*/
7272
public static function bootAuditable()
7373
{
74-
if (static::isAuditingEnabled()) {
74+
try {
75+
$isAuditingEnabled = static::isAuditingEnabled();
76+
} catch (\RuntimeException $e) {
77+
if ($e->getMessage() !== 'A facade root has not been set.') {
78+
throw $e;
79+
}
80+
81+
/**
82+
* Facade root has not been set. The user may be attempting to use
83+
* their Auditable outside of the application context. We will
84+
* just skip booting for now.
85+
*/
86+
return;
87+
}
88+
89+
if ($isAuditingEnabled) {
7590
static::observe(new AuditableObserver());
7691
}
7792
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace OwenIt\Auditing\Tests\Unit;
4+
5+
use OwenIt\Auditing\Tests\Models\Article;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class OutsideOfAppContextTest extends TestCase
9+
{
10+
public function test_can_create_new_model(): void
11+
{
12+
$article = new Article();
13+
$this->assertInstanceOf(Article::class, $article);
14+
}
15+
}

0 commit comments

Comments
 (0)