Skip to content

Commit d35323b

Browse files
committed
add ability to short circuit booting the trait before any deferences to the framework are attempted
1 parent 4a05fb5 commit d35323b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Auditable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ trait Auditable
4545
*/
4646
public static function bootAuditable()
4747
{
48-
if (static::isAuditingEnabled()) {
48+
if (!self::$auditingDisabled && static::isAuditingEnabled()) {
4949
static::observe(new AuditableObserver());
5050
}
5151
}

tests/Unit/AuditableTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ public function itWillAlwaysAuditModelsWhenNotRunningFromTheConsole()
6565
$this->assertTrue(Article::isAuditingEnabled());
6666
}
6767

68+
/**
69+
* @group Auditable::bootAuditable
70+
* @test
71+
*/
72+
public function itWillNotBootTraitWhenStaticFlagIsSet()
73+
{
74+
App::spy();
75+
76+
Article::$auditingDisabled = true;
77+
78+
new Article();
79+
80+
App::shouldNotHaveReceived('runningInConsole');
81+
82+
Article::$auditingDisabled = false;
83+
}
84+
6885
/**
6986
* @group Auditable::getAuditEvent
7087
* @test

0 commit comments

Comments
 (0)