get(Connection::class), $this->em->getRepository(Representation::class), new RequestStack(), ); } private function editLogCount(): int { return (int) static::getContainer()->get(Connection::class) ->fetchOne("SELECT COUNT(*) FROM app_log WHERE channel = 'representation_edit'"); } private function newRepresentative(): User { $user = $this->createUser(['ROLE_USER', 'ROLE_REPRESENTATION']); $this->em->persist(new Representation($user, 'نمایندهٔ لاگ')); $this->em->flush(); return $user; } public function testEditByRepresentativeWritesOneRow(): void { $user = $this->newRepresentative(); $before = $this->editLogCount(); $this->logger()->logEdit($user, 'doctor', 'uuid-under-test', ['info' => 'x', 'images' => []]); self::assertSame($before + 1, $this->editLogCount()); } public function testTheRowNamesTheRepresentativeAndTheChangedFields(): void { $user = $this->newRepresentative(); $uuid = 'uuid-' . uniqid(); $this->logger()->logEdit($user, 'clinic', $uuid, ['clinic_logo' => 'https://a/b.png', 'info' => 'y']); $row = static::getContainer()->get(Connection::class)->fetchAssociative( "SELECT message, context, level FROM app_log WHERE channel = 'representation_edit' ORDER BY id DESC LIMIT 1" ); self::assertSame('info', $row['level']); self::assertStringContainsString($uuid, $row['message']); $context = json_decode((string) $row['context'], true); self::assertSame('clinic', $context['entity_type']); self::assertSame(['clinic_logo', 'info'], $context['fields']); // فقط کلیدها ثبت می‌شوند، نه مقادیر. self::assertStringNotContainsString('https://a/b.png', (string) $row['context']); } public function testUserWithoutARepresentationRowWritesNothing(): void { $user = $this->createUser(['ROLE_USER']); $before = $this->editLogCount(); $this->logger()->logEdit($user, 'doctor', 'uuid-x', ['info' => 'x']); self::assertSame($before, $this->editLogCount()); } }