setName('Max Mustermann'); $user->setEmail('max@example.com'); $user->setRole(UserRole::USER); $this->assertEquals('Max Mustermann', $user->getName()); $this->assertEquals('max@example.com', $user->getEmail()); $this->assertEquals(UserRole::USER, $user->getRole()); $this->assertNotNull($user->getApiKey()); $this->assertNotNull($user->getCreatedAt()); } public function testApiKeyGeneration(): void { $user = new User(); $user->setName('Test User'); $user->setEmail('test@example.com'); $apiKey = $user->getApiKey(); $this->assertNotEmpty($apiKey); $this->assertEquals(64, strlen($apiKey)); // SHA256 hash length } public function testRegenerateApiKey(): void { $user = new User(); $user->setName('Test User'); $user->setEmail('test@example.com'); $originalKey = $user->getApiKey(); $user->regenerateApiKey(); $newKey = $user->getApiKey(); $this->assertNotEquals($originalKey, $newKey); $this->assertEquals(64, strlen($newKey)); } public function testUserRoles(): void { // Test USER role $user = new User(); $user->setRole(UserRole::USER); $this->assertContains('ROLE_USER', $user->getRoles()); // Test ADMIN role $admin = new User(); $admin->setRole(UserRole::ADMIN); $this->assertContains('ROLE_ADMIN', $admin->getRoles()); $this->assertContains('ROLE_USER', $admin->getRoles()); // Test TECHNICAL role $technical = new User(); $technical->setRole(UserRole::TECHNICAL); $this->assertContains('ROLE_TECHNICAL', $technical->getRoles()); $this->assertContains('ROLE_USER', $technical->getRoles()); // Test MODERATOR role $moderator = new User(); $moderator->setRole(UserRole::MODERATOR); $this->assertContains('ROLE_MODERATOR', $moderator->getRoles()); $this->assertContains('ROLE_USER', $moderator->getRoles()); } public function testUserIdentifier(): void { $user = new User(); $user->setEmail('identifier@example.com'); $this->assertEquals('identifier@example.com', $user->getUserIdentifier()); } public function testDefaultRole(): void { $user = new User(); // Default role should be USER $this->assertEquals(UserRole::USER, $user->getRole()); } }