Skip to content

Commit c66abe7

Browse files
Merge pull request owen-it#462 from dallincoons/short-circuiting-trait-boot
Add ability to short circuit trait booting
2 parents ec19c35 + d35323b commit c66abe7

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
@@ -46,7 +46,7 @@ trait Auditable
4646
*/
4747
public static function bootAuditable()
4848
{
49-
if (static::isAuditingEnabled()) {
49+
if (!self::$auditingDisabled && static::isAuditingEnabled()) {
5050
static::observe(new AuditableObserver());
5151
}
5252
}

tests/Unit/AuditableTest.php

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

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

0 commit comments

Comments
 (0)