k; } }; return new AttributeCipher($settings); } #[Test] public function it_round_trips_a_value_when_a_key_is_configured(): void { $cipher = $this->cipher('TajneHaslo123'); $encrypted = $cipher->encrypt('p.zielinski.secret'); $this->assertNotSame('p.zielinski.secret', $encrypted); $this->assertSame('p.zielinski.secret', $cipher->decrypt($encrypted)); } #[Test] public function it_does_not_re_encrypt_an_already_encrypted_value(): void { $cipher = $this->cipher('TajneHaslo123'); $encrypted = $cipher->encrypt('abc'); $this->assertSame($encrypted, $cipher->encrypt($encrypted)); } #[Test] public function it_passes_values_through_unchanged_when_no_key_is_configured(): void { $cipher = $this->cipher(''); $this->assertSame('abc', $cipher->encrypt('abc')); $this->assertSame('abc', $cipher->decrypt('abc')); $this->assertFalse($cipher->isConfigured()); } #[Test] public function it_returns_the_raw_value_when_it_cannot_be_decrypted(): void { $cipher = $this->cipher('TajneHaslo123'); // Wartość nie w naszym formacie (np. wpisana ręcznie / inny klucz). $this->assertSame('not-our-ciphertext', $cipher->decrypt('not-our-ciphertext')); } #[Test] public function null_and_empty_values_are_left_alone(): void { $cipher = $this->cipher('TajneHaslo123'); $this->assertNull($cipher->encrypt(null)); $this->assertSame('', $cipher->encrypt('')); $this->assertNull($cipher->decrypt(null)); } }