Skip to content

Commit

Permalink
feat: Add method to clear post hooks. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
owenconti authored Apr 7, 2020
1 parent 5a20afa commit f2b0524
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/LaravelServerAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public function addPostHook($callback): void
$this->postHooks[] = $callback;
}

/**
* Clears the post hooks.
*
* @return void
*/
public function clearPostHooks(): void
{
$this->postHooks = [];
}

/**
* Relates the given Model to the current analytics record.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/PostHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,22 @@ function (RequestDetails $requestDetails, Analytics $analytics) use ($relatedAna
'relation_type' => Analytics::class
]);
}

/** @test */
public function it_clears_post_hooks()
{
// Given
$spy = Mockery::spy(function () {
// no op
});
ServerAnalytics::addPostHook($spy);

ServerAnalytics::clearPostHooks();

// When
$this->get('/analytics');

// Then
$spy->shouldNotHaveBeenCalled();
}
}

0 comments on commit f2b0524

Please sign in to comment.