generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
114c2ba
commit 8570d28
Showing
6 changed files
with
33 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ | |
$this->assertSame('[email protected]', $user->email); | ||
}); | ||
|
||
it('can show only type queries', function (Closure $rayShowMethod, Closure $rayStopMethod, string $sqlCommand) { | ||
$rayShowMethod(); | ||
it('can show only type queries', function (string $rayShowMethod, string $rayStopMethod, string $sqlCommand) { | ||
ray()->$rayShowMethod(); | ||
|
||
// Run all query types | ||
$user = User::query()->firstOrCreate(['email' => '[email protected]']); | ||
|
@@ -33,9 +33,9 @@ | |
|
||
// Assert the one we want is picked up. | ||
$payload = $this->client->sentPayloads(); | ||
$this->assertStringStartsWith($sqlCommand, Arr::get($payload, '0.content.sql')); | ||
$this->assertSqlContains(Arr::get($payload, '0.content'), $sqlCommand); | ||
|
||
$rayStopMethod(); | ||
ray()->$rayStopMethod(); | ||
|
||
// Assert that watcher has stopped. | ||
$user = User::query()->firstOrCreate(['email' => '[email protected]']); | ||
|
@@ -44,15 +44,15 @@ | |
|
||
expect($this->client->sentPayloads())->toHaveCount(1); | ||
})->with([ | ||
'update' => [function () {ray()->showUpdateQueries();}, function () {ray()->stopShowingUpdateQueries();}, 'update'], | ||
'delete' => [function () {ray()->showDeleteQueries();}, function () {ray()->stopShowingDeleteQueries();}, 'delete'], | ||
'insert' => [function () {ray()->showInsertQueries();}, function () {ray()->stopShowingInsertQueries();}, 'insert'], | ||
'select' => [function () {ray()->showSelectQueries();}, function () {ray()->stopShowingSelectQueries();}, 'select'], | ||
'update' => ['showUpdateQueries', 'stopShowingUpdateQueries', 'update'], | ||
'delete' => ['showDeleteQueries', 'stopShowingDeleteQueries', 'delete'], | ||
'insert' => ['showInsertQueries', 'stopShowingInsertQueries', 'insert'], | ||
'select' => ['showSelectQueries', 'stopShowingSelectQueries', 'select'], | ||
]); | ||
|
||
it('can take a custom condition and only return those queries', function () { | ||
ray()->showConditionalQueries(function (QueryExecuted $query) { | ||
return Str::contains($query->toRawSql(), 'joan'); | ||
return Arr::first($query->bindings, fn ($binding) => Str::contains($binding, 'joan')); | ||
}); | ||
|
||
User::query()->create(['email' => '[email protected]']); | ||
|
@@ -61,7 +61,7 @@ | |
expect($this->client->sentPayloads())->toHaveCount(1); | ||
|
||
$payload = $this->client->sentPayloads(); | ||
$this->assertStringContainsString('[email protected]', Arr::get($payload, '0.content.sql')); | ||
$this->assertSqlContains(Arr::get($payload, '0.content'), '[email protected]'); | ||
|
||
ray()->stopShowingConditionalQueries(); | ||
|
||
|
@@ -73,12 +73,12 @@ | |
it('can handle multiple conditional query watchers', function () { | ||
$john = ray()->showConditionalQueries( | ||
function (QueryExecuted $query) { | ||
return Str::contains($query->toRawSql(), 'joan'); | ||
return Arr::first($query->bindings, fn ($binding) => Str::contains($binding, 'joan')); | ||
}, | ||
function (): User { | ||
ray()->showConditionalQueries( | ||
function (QueryExecuted $query) { | ||
return Str::contains($query->toRawSql(), 'john'); | ||
return Arr::first($query->bindings, fn ($binding) => Str::contains($binding, 'john')); | ||
}, | ||
null, | ||
'look for john' | ||
|
@@ -101,11 +101,11 @@ function (QueryExecuted $query) { | |
$payload = $this->client->sentPayloads(); | ||
|
||
// Assert that ray received the correct order | ||
$this->assertStringContainsString('[email protected]', Arr::get($payload, '0.content.sql')); | ||
$this->assertStringContainsString('[email protected]', Arr::get($payload, '1.content.sql')); | ||
$this->assertSqlContains(Arr::get($payload, '0.content'), '[email protected]'); | ||
$this->assertSqlContains(Arr::get($payload, '1.content'), '[email protected]'); | ||
|
||
// Looking for joan has been disabled so this should not be sent | ||
$joan = User::query()->where('email', '[email protected]')->sole(); | ||
$joan = User::query()->where('email', '[email protected]')->first(); | ||
expect($this->client->sentPayloads())->toHaveCount(2); | ||
|
||
// Looking for john is still enabled so this should be sent | ||
|
@@ -134,5 +134,5 @@ function (QueryExecuted $query) { | |
expect($this->client->sentPayloads())->toHaveCount(1); | ||
|
||
$payload = $this->client->sentPayloads(); | ||
$this->assertStringStartsWith('select', Arr::get($payload, '0.content.sql')); | ||
$this->assertSqlContains(Arr::get($payload, '0.content'), 'select'); | ||
}); |