|
2 | 2 |
|
3 | 3 | namespace Barryvdh\Debugbar\Tests\DataCollector; |
4 | 4 |
|
5 | | -use Barryvdh\Debugbar\Tests\Jobs\OrderShipped; |
6 | | -use Barryvdh\Debugbar\Tests\Jobs\SendNotification; |
| 5 | +use Barryvdh\Debugbar\Tests\Models\Person; |
| 6 | +use Barryvdh\Debugbar\Tests\Models\User; |
7 | 7 | use Barryvdh\Debugbar\Tests\TestCase; |
8 | | -use Illuminate\Database\Migrations\Migration; |
9 | | -use Illuminate\Database\Schema\Blueprint; |
10 | 8 | use Illuminate\Foundation\Testing\RefreshDatabase; |
11 | | -use Illuminate\Support\Facades\Schema; |
| 9 | +use Illuminate\Support\Facades\Hash; |
12 | 10 |
|
13 | | -class JobsCollectorTest extends TestCase |
| 11 | +class ModelsCollectorTest extends TestCase |
14 | 12 | { |
15 | 13 | use RefreshDatabase; |
16 | 14 |
|
17 | | - protected function getEnvironmentSetUp($app) |
18 | | - { |
19 | | - $app['config']->set('debugbar.collectors.jobs', true); |
20 | | - // The `sync` and `null` driver don't dispatch events |
21 | | - // `database` or `redis` driver work great |
22 | | - $app['config']->set('queue.default', 'database'); |
23 | | - |
24 | | - parent::getEnvironmentSetUp($app); |
25 | | - } |
26 | | - |
27 | | - public function testItCollectsDispatchedJobs() |
| 15 | + public function testItCollectsRetrievedModels() |
28 | 16 | { |
29 | 17 | $this->loadLaravelMigrations(); |
30 | | - $this->createJobsTable(); |
31 | | - |
32 | 18 | debugbar()->boot(); |
33 | 19 |
|
34 | 20 | /** @var \DebugBar\DataCollector\ObjectCountCollector $collector */ |
35 | | - $collector = debugbar()->getCollector('jobs'); |
| 21 | + $collector = debugbar()->getCollector('models'); |
36 | 22 | $collector->setXdebugLinkTemplate(''); |
| 23 | + $collector->collectCountSummary(false); |
37 | 24 | $collector->setKeyMap([]); |
38 | 25 | $data = []; |
39 | 26 |
|
| 27 | + $this->assertEquals( |
| 28 | + ['data' => $data, 'key_map' => [], 'count' => 0, 'is_counter' => true], |
| 29 | + $collector->collect() |
| 30 | + ); |
| 31 | + |
| 32 | + User::create([ |
| 33 | + 'name' => 'John Doe', |
| 34 | + |
| 35 | + 'password' => Hash::make('password'), |
| 36 | + ]); |
| 37 | + |
| 38 | + User::create([ |
| 39 | + 'name' => 'Jane Doe', |
| 40 | + |
| 41 | + 'password' => Hash::make('password'), |
| 42 | + ]); |
| 43 | + |
| 44 | + $data[User::class] = ['created' => 2]; |
40 | 45 | $this->assertEquals( |
41 | 46 | [ |
42 | 47 | 'data' => $data, |
43 | | - 'count' => 0, |
| 48 | + 'count' => 2, |
44 | 49 | 'is_counter' => true, |
45 | | - 'key_map' => [] |
| 50 | + 'key_map' => [ |
| 51 | + ], |
46 | 52 | ], |
47 | 53 | $collector->collect() |
48 | 54 | ); |
49 | 55 |
|
50 | | - OrderShipped::dispatch(1); |
| 56 | + $user = User::first(); |
| 57 | + |
| 58 | + $data[User::class]['retrieved'] = 1; |
| 59 | + $this->assertEquals( |
| 60 | + ['data' => $data, 'key_map' => [], 'count' => 3, 'is_counter' => true], |
| 61 | + $collector->collect() |
| 62 | + ); |
| 63 | + |
| 64 | + $user->update(['name' => 'Jane Doe']); |
51 | 65 |
|
52 | | - $data[OrderShipped::class] = ['value' => 1]; |
| 66 | + $data[User::class]['updated'] = 1; |
53 | 67 | $this->assertEquals( |
54 | 68 | [ |
55 | 69 | 'data' => $data, |
56 | | - 'count' => 1, |
| 70 | + 'count' => 4, |
57 | 71 | 'is_counter' => true, |
58 | | - 'key_map' => ['value' => 'Count'] |
| 72 | + 'key_map' => [], |
59 | 73 | ], |
60 | 74 | $collector->collect() |
61 | 75 | ); |
62 | 76 |
|
63 | | - dispatch(new SendNotification()); |
64 | | - dispatch(new SendNotification()); |
65 | | - dispatch(new SendNotification()); |
| 77 | + Person::all(); |
66 | 78 |
|
67 | | - $data[SendNotification::class] = ['value' => 3]; |
| 79 | + $data[Person::class] = ['retrieved' => 2]; |
| 80 | + $this->assertEquals( |
| 81 | + ['data' => $data, 'key_map' => [], 'count' => 6, 'is_counter' => true], |
| 82 | + $collector->collect() |
| 83 | + ); |
| 84 | + |
| 85 | + $user->delete(); |
| 86 | + |
| 87 | + $data[User::class]['deleted'] = 1; |
68 | 88 | $this->assertEquals( |
69 | 89 | [ |
70 | 90 | 'data' => $data, |
71 | | - 'count' => 4, |
| 91 | + 'count' => 7, |
72 | 92 | 'is_counter' => true, |
73 | | - 'key_map' => ['value' => 'Count'] |
| 93 | + 'key_map' => [ |
| 94 | + ] |
74 | 95 | ], |
75 | 96 | $collector->collect() |
76 | 97 | ); |
77 | 98 | } |
78 | | - |
79 | | - protected function createJobsTable() |
80 | | - { |
81 | | - (new class extends Migration |
82 | | - { |
83 | | - public function up() |
84 | | - { |
85 | | - if (Schema::hasTable('jobs')) { |
86 | | - return; |
87 | | - } |
88 | | - |
89 | | - Schema::create('jobs', function (Blueprint $table) { |
90 | | - $table->bigIncrements('id'); |
91 | | - $table->string('queue')->index(); |
92 | | - $table->longText('payload'); |
93 | | - $table->unsignedTinyInteger('attempts'); |
94 | | - $table->unsignedInteger('reserved_at')->nullable(); |
95 | | - $table->unsignedInteger('available_at'); |
96 | | - $table->unsignedInteger('created_at'); |
97 | | - }); |
98 | | - } |
99 | | - })->up(); |
100 | | - } |
101 | 99 | } |
0 commit comments