Created
April 24, 2022 11:26
-
-
Save tkaratug/dece28e5b84054c3a2cf3c9cd5e0c15c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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