File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments