GateCollector tests (#1545)

This commit is contained in:
erikn69 2024-02-22 09:08:00 -05:00 committed by GitHub
parent 47f25f2cd0
commit bdc2d62e4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,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, result => null, user => 1, arguments => []]',
$gateError['message']
);
$gateSuccess = $collect['messages'][1];
$this->assertEquals('success', $gateSuccess['label']);
$this->assertEquals(
'[ability => test, result => true, user => 1, arguments => []]',
$gateSuccess['message']
);
}
}

View File

@ -2,7 +2,7 @@
namespace Barryvdh\Debugbar\Tests\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Model;
class User extends Model
{