forked from barryvdh/laravel-debugbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize models collector (barryvdh#1051)
* Optimize models collector Use a wildcard to listen to the `eloquent.retrieved:*` events instead of listening to all the `eloquent.*` events. * Add testsfor ModelsCollector
- Loading branch information
Showing
6 changed files
with
165 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/build | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store | ||
.DS_Store | ||
.phpunit.result.cache |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Laravel Debugbar Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
<php> | ||
<env name="DEBUGBAR_ENABLED" value="true"/> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
</php> | ||
</phpunit> |
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,65 @@ | ||
<?php | ||
|
||
namespace Barryvdh\Debugbar\Tests\DataCollector; | ||
|
||
use Barryvdh\Debugbar\Tests\TestCase; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class ModelsCollectorTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** @test */ | ||
public function it_collects_retrieved_models() | ||
{ | ||
$this->loadLaravelMigrations(); | ||
|
||
$this->debugbar()->boot(); | ||
|
||
/** @var \Barryvdh\Debugbar\DataCollector\ModelsCollector $collector */ | ||
$collector = $this->debugbar()->getCollector('models'); | ||
|
||
User::create([ | ||
'name' => 'John Doe', | ||
'email' => 'john@example.com', | ||
'password' => Hash::make('password'), | ||
]); | ||
|
||
User::create([ | ||
'name' => 'Jane Doe', | ||
'email' => 'jane@example.com', | ||
'password' => Hash::make('password'), | ||
]); | ||
|
||
$this->assertEquals( | ||
['data' => [], 'count' => 0], | ||
$collector->collect() | ||
); | ||
|
||
User::first(); | ||
|
||
$this->assertEquals( | ||
['data' => [User::class => 1], 'count' => 1], | ||
$collector->collect() | ||
); | ||
|
||
Person::all(); | ||
|
||
$this->assertEquals( | ||
['data' => [User::class => 1, Person::class => 2], 'count' => 3], | ||
$collector->collect() | ||
); | ||
} | ||
} | ||
|
||
class User extends Model | ||
{ | ||
protected $table = 'users'; | ||
protected $guarded = []; | ||
} | ||
|
||
class Person extends User | ||
{ | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace Barryvdh\Debugbar\Tests; | ||
|
||
use Barryvdh\Debugbar\Facade; | ||
use Barryvdh\Debugbar\ServiceProvider; | ||
use Orchestra\Testbench\TestCase as Orchestra; | ||
|
||
class TestCase extends Orchestra | ||
{ | ||
/** @var \Barryvdh\Debugbar\LaravelDebugbar */ | ||
private $debugbar; | ||
|
||
/** | ||
* Get package providers. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return array | ||
*/ | ||
protected function getPackageProviders($app) | ||
{ | ||
return [ServiceProvider::class]; | ||
} | ||
|
||
/** | ||
* Get package aliases. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return array | ||
*/ | ||
protected function getPackageAliases($app) | ||
{ | ||
return ['Debugbar' => Facade::class]; | ||
} | ||
|
||
public function getEnvironmentSetUp($app) | ||
{ | ||
} | ||
|
||
/** | ||
* Get the Laravel Debugbar instance. | ||
* | ||
* @return \Barryvdh\Debugbar\LaravelDebugbar | ||
*/ | ||
public function debugbar() | ||
{ | ||
return $this->debugbar ?? $this->debugbar = $this->app->debugbar; | ||
} | ||
} |