. */ namespace SP\Tests\Core\Crypt; use PHPUnit\Framework\Attributes\Group; use SP\Core\Crypt\Crypt; use SP\Domain\Core\Exceptions\CryptException; use SP\Tests\UnitaryTestCase; /** * Class CryptTest */ #[Group('unitary')] class CryptTest extends UnitaryTestCase { /** * Comprobar la generación de una llave de cifrado * * @throws CryptException */ public function testMakeSecuredKey() { (new Crypt())->makeSecuredKey(self::$faker->password); $this->assertTrue(true); } /** * Comprobar la generación de una llave de cifrado * * @throws CryptException */ public function testMakeSecuredKeyNoAscii() { (new Crypt())->makeSecuredKey(self::$faker->password, false); $this->assertTrue(true); } /** * Comprobar la encriptación y desencriptado de datos * * @throws CryptException */ public function testEncryptAndDecrypt() { $crypt = new Crypt(); $password = self::$faker->password; $key = $crypt->makeSecuredKey($password); $data = self::$faker->text; $out = $crypt->encrypt($data, $key, $password); $this->assertSame($data, $crypt->decrypt($out, $key, $password)); } /** * Comprobar la encriptación y desencriptado de datos * * @throws CryptException */ public function testEncryptAndDecryptWithDifferentPassword() { $crypt = new Crypt(); $password = self::$faker->password; $key = $crypt->makeSecuredKey($password); $data = $crypt->encrypt('prueba', $key, $password); $this->expectException(CryptException::class); $crypt->decrypt($data, $key, 'test'); } }