feat: comprehensive audit log
This commit is contained in:
1 parent
867bd413c8
commit
02e0d672bd
20 files changed
+932
-82
No files matched your search
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Logger;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Logger\AuditActorProcessor;
|
||||
use Monolog\Level;
|
||||
use Monolog\LogRecord;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
/**
|
||||
* The actor is the one field an audit record cannot be allowed to get wrong, so it is taken from
|
||||
* the token rather than from any call site -- which is what these cover.
|
||||
*/
|
||||
class AuditActorProcessorTest extends TestCase
|
||||
{
|
||||
public function testTheActorIsTheSignedInUsersEmailAddress(): void
|
||||
{
|
||||
$record = $this->process(new User('[email protected]', 'Admin'));
|
||||
|
||||
self::assertSame('[email protected]', $record->extra['actor']);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPUnit runs under the CLI SAPI, which is the same context a console command or the
|
||||
* message worker writes from -- so this is the system branch, not the anonymous one.
|
||||
*/
|
||||
public function testAWriteWithNoUserBehindItIsAttributedToTheSystem(): void
|
||||
{
|
||||
$record = $this->process(null);
|
||||
|
||||
self::assertSame(AuditActorProcessor::SYSTEM, $record->extra['actor']);
|
||||
}
|
||||
|
||||
private function process(?User $user): LogRecord
|
||||
{
|
||||
$security = $this->createStub(Security::class);
|
||||
$security->method('getUser')->willReturn($user);
|
||||
|
||||
$processor = new AuditActorProcessor($security);
|
||||
|
||||
return $processor(new LogRecord(
|
||||
new \DateTimeImmutable(),
|
||||
'audit',
|
||||
Level::Info,
|
||||
'Booking created.',
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user