generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MySQL Visual Explain macro's for the query builders.
- Loading branch information
1 parent
c2bedfd
commit 30a0e4b
Showing
4 changed files
with
70 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelRay\Payloads; | ||
|
||
use Spatie\Ray\Payloads\Payload; | ||
|
||
class MySqlVisualExplainPayload extends Payload | ||
{ | ||
protected string $url; | ||
|
||
public function __construct(string $url) | ||
{ | ||
$this->url = $url; | ||
|
||
} | ||
|
||
public function getType(): string | ||
{ | ||
return 'mysql_visual_explain'; | ||
} | ||
|
||
public function getContent(): array | ||
{ | ||
return [ | ||
'url' => $this->url, | ||
]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Facades\DB; | ||
use Spatie\LaravelRay\Tests\TestClasses\User; | ||
use Tpetry\MysqlExplain\Facades\MysqlExplain; | ||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||
use Illuminate\Database\Query\Builder as QueryBuilder; | ||
use Tpetry\MysqlExplain\Mixins\BuilderMixin; | ||
|
||
beforeEach(function() { | ||
EloquentBuilder::mixin(new BuilderMixin()); | ||
QueryBuilder::mixin(new BuilderMixin()); | ||
}); | ||
|
||
it('works', function ($builder) { | ||
MysqlExplain::shouldReceive('submitBuilder') | ||
->once() | ||
->andReturn('https://dummy-url-f6V7VImZnz.local'); | ||
|
||
$builder->rayVisualExplain(); | ||
|
||
expect($this->client->sentPayloads())->toHaveCount(1); | ||
|
||
$payload = $this->client->sentPayloads()[0]; | ||
|
||
expect(Arr::get($payload, 'type'))->toEqual('mysql_visual_explain'); | ||
expect($payload['content']['url'])->toEqual('https://dummy-url-f6V7VImZnz.local'); | ||
})->with([ | ||
fn() => User::where('email', '[email protected]'), | ||
fn() => DB::table('users')->where('email', '[email protected]') | ||
]); |