You've already forked php-auth
generated from siteworxpro/Php-Template
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\Tests\Attributes\Guards;
|
|
|
|
use Siteworxpro\App\Attributes\Guards\Scope;
|
|
use Siteworxpro\Tests\Unit;
|
|
|
|
class ScopeTest extends Unit
|
|
{
|
|
public function testGetsClassSingle(): void
|
|
{
|
|
$reflection = new \ReflectionClass(TestClassSingle::class);
|
|
$attributes = $reflection->getAttributes(Scope::class);
|
|
$this->assertCount(1, $attributes);
|
|
|
|
/** @var Scope $instance */
|
|
$instance = $attributes[0]->newInstance();
|
|
$this->assertEquals(['read:users'], $instance->getScopes());
|
|
}
|
|
|
|
public function testGetsClassFromCustom(): void
|
|
{
|
|
$reflection = new \ReflectionClass(TestClassMultiple::class);
|
|
$attributes = $reflection->getAttributes(Scope::class);
|
|
$this->assertCount(1, $attributes);
|
|
|
|
/** @var Scope $instance */
|
|
$instance = $attributes[0]->newInstance();
|
|
$this->assertEquals(['read:users', 'write:users'], $instance->getScopes());
|
|
}
|
|
}
|
|
|
|
#[Scope(['read:users', 'write:users'])]
|
|
class TestClassMultiple // @codingStandardsIgnoreLine
|
|
{
|
|
}
|
|
|
|
#[Scope(['read:users'])]
|
|
class TestClassSingle // @codingStandardsIgnoreLine
|
|
{
|
|
}
|