feat : Ajout de tests unitaires
This commit is contained in:
48
tests/State/MeProviderTest.php
Normal file
48
tests/State/MeProviderTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use App\Entity\User;
|
||||
use App\State\MeProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class MeProviderTest extends TestCase
|
||||
{
|
||||
public function testProvideReturnUser(): void
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$security = $this->createStub(Security::class);
|
||||
$security->method('getUser')->willReturn($user);
|
||||
|
||||
$provider = new MeProvider($security);
|
||||
|
||||
$result = $provider->provide($this->createStub(Operation::class));
|
||||
|
||||
self::assertSame($user, $result);
|
||||
self::assertInstanceOf(User::class, $result);
|
||||
}
|
||||
|
||||
public function testProvideThrowAccessDeniedException(): void
|
||||
{
|
||||
$user = null;
|
||||
|
||||
$security = $this->createStub(Security::class);
|
||||
$security->method('getUser')->willReturn($user);
|
||||
|
||||
$provider = new MeProvider($security);
|
||||
|
||||
$this->expectException(AccessDeniedException::class);
|
||||
$this->expectExceptionMessage('User not authenticated.');
|
||||
|
||||
$provider->provide($this->createStub(Operation::class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user