-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathGateCollectorTest.php
51 lines (40 loc) · 1.45 KB
/
GateCollectorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Barryvdh\Debugbar\Tests\DataCollector;
use Barryvdh\Debugbar\Tests\Models\User;
use Barryvdh\Debugbar\Tests\TestCase;
use Illuminate\Support\Facades\Gate;
class GateCollectorTest extends TestCase
{
public function testItCollectsGateChecks()
{
debugbar()->boot();
/** @var \Barryvdh\Debugbar\DataCollector\GateCollector $collector */
$collector = debugbar()->getCollector('gate');
$collector->useHtmlVarDumper(false);
$user = new User([
'id' => 1,
'name' => 'John Doe',
'email' => 'john@example.com',
'password' => 'password',
]);
$user->can('test');
Gate::before(function ($user, $ability, $result, $arguments = []) {
return true;
});
$user->can('test');
$collect = $collector->collect();
$this->assertEquals(2, $collect['count']);
$gateError = $collect['messages'][0];
$this->assertEquals('error', $gateError['label']);
$this->assertEquals(
'[ability => test, target => null, result => null, user => 1, arguments => []]',
$gateError['message']
);
$gateSuccess = $collect['messages'][1];
$this->assertEquals('success', $gateSuccess['label']);
$this->assertEquals(
'[ability => test, target => null, result => true, user => 1, arguments => []]',
$gateSuccess['message']
);
}
}