Skip to content

Instantly share code, notes, and snippets.

@tkaratug
Created April 24, 2022 11:26
Show Gist options
  • Save tkaratug/dece28e5b84054c3a2cf3c9cd5e0c15c to your computer and use it in GitHub Desktop.
Save tkaratug/dece28e5b84054c3a2cf3c9cd5e0c15c to your computer and use it in GitHub Desktop.
<?php
namespace Tests;
use Illuminate\Support\Facades\Event;
use App\Events\ModelScopeCalled;
trait HasScopeAssertion
{
public function assertScopeCalled(string $scope, string $model)
{
$triggeredScopes = [];
Event::assertDispatched(ModelScopeCalled::class);
Event::assertDispatched(function (ModelScopeCalled $event) use (&$triggeredScopes) {
$triggeredScopes[$event->model][] = $event->scope;
return true;
});
$this->assertTrue(in_array($scope, $triggeredScopes[$model]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment