tests/Entity/AnalyticsTest.php (nouveau, 8 tests): - AnalyticsUniqId: constructor (id null, createdAt, events vide), setters (uid, hash, ipHash, userAgent, deviceType), screen (width, height), optionals (language, os, browser), user (nullable, set/get) - AnalyticsEvent: constructor (id null, createdAt), setters (visitor, eventName, url, title, referrer), nullables (title, referrer null par defaut) tests/Entity/AppLogTest.php (nouveau, 6 tests): - testConstructor: method, url, route, action, user null, ip null, hmac non vide, createdAt - testConstructorWithUser: user et ip passes au constructeur - testVerifyHmacValid: meme secret retourne true - testVerifyHmacInvalid: secret different retourne false - testHmacDeterministic: hmac identique a chaque verification - testDifferentDataProducesDifferentHmac: donnees differentes produisent des hmac differents tests/Entity/AttestationTest.php (nouveau, 9 tests): - testConstructor: type, ip, email, reference non vide, hmac non vide, status='pending', createdAt - testReferencePrefix: 'access' contient ACC, 'deletion' contient DEL, 'no_data' contient ABS dans la reference - testPdfFiles: unsigned, signed, certificate get/set nullable - testSubmitterId: get/set nullable - testMarkAsSigned: status passe a 'signed' - testMarkAsSent: status passe a 'sent' - testVerifyValid: meme secret retourne true - testVerifyInvalid: secret different retourne false - testEmailTracking: null par defaut Resultat: 338 tests, 670 assertions, 0 failures Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
use App\Entity\AppLog;
|
|
use App\Entity\User;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AppLogTest extends TestCase
|
|
{
|
|
public function testConstructor(): void
|
|
{
|
|
$log = new AppLog('GET', '/admin/dashboard', 'app_admin_dashboard', 'Consultation du tableau de bord', 'secret');
|
|
$this->assertNull($log->getId());
|
|
$this->assertSame('GET', $log->getMethod());
|
|
$this->assertSame('/admin/dashboard', $log->getUrl());
|
|
$this->assertSame('app_admin_dashboard', $log->getRoute());
|
|
$this->assertSame('Consultation du tableau de bord', $log->getAction());
|
|
$this->assertNull($log->getUser());
|
|
$this->assertNull($log->getIp());
|
|
$this->assertNotEmpty($log->getHmac());
|
|
$this->assertInstanceOf(\DateTimeImmutable::class, $log->getCreatedAt());
|
|
}
|
|
|
|
public function testConstructorWithUser(): void
|
|
{
|
|
$user = new User();
|
|
$user->setEmail('admin@test.com');
|
|
$user->setFirstName('Admin');
|
|
$user->setLastName('User');
|
|
$user->setPassword('h');
|
|
|
|
$log = new AppLog('POST', '/admin/clients/create', 'app_admin_clients_create', 'Creation client', 'secret', $user, '192.168.1.1');
|
|
$this->assertSame($user, $log->getUser());
|
|
$this->assertSame('192.168.1.1', $log->getIp());
|
|
$this->assertSame('POST', $log->getMethod());
|
|
}
|
|
|
|
public function testVerifyHmacValid(): void
|
|
{
|
|
$log = new AppLog('GET', '/admin', 'route', 'action', 'my-secret');
|
|
$this->assertTrue($log->verifyHmac('my-secret'));
|
|
}
|
|
|
|
public function testVerifyHmacInvalid(): void
|
|
{
|
|
$log = new AppLog('GET', '/admin', 'route', 'action', 'my-secret');
|
|
$this->assertFalse($log->verifyHmac('wrong-secret'));
|
|
}
|
|
|
|
public function testHmacDeterministic(): void
|
|
{
|
|
$log = new AppLog('GET', '/admin', 'route', 'action', 'secret');
|
|
$hmac1 = $log->getHmac();
|
|
$this->assertTrue($log->verifyHmac('secret'));
|
|
$this->assertSame($hmac1, $log->getHmac());
|
|
}
|
|
|
|
public function testDifferentDataProducesDifferentHmac(): void
|
|
{
|
|
$log1 = new AppLog('GET', '/admin/a', 'route_a', 'action_a', 'secret');
|
|
$log2 = new AppLog('GET', '/admin/b', 'route_b', 'action_b', 'secret');
|
|
$this->assertNotSame($log1->getHmac(), $log2->getHmac());
|
|
}
|
|
}
|