File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Casts ;
6+
7+ use Illuminate \Encryption \Encrypter ;
8+ use MongoDB \Laravel \Tests \Models \Casting ;
9+ use MongoDB \Laravel \Tests \TestCase ;
10+
11+ class EncryptionTest extends TestCase
12+ {
13+ protected function setUp (): void
14+ {
15+ parent ::setUp ();
16+
17+ Casting::truncate ();
18+ }
19+
20+ public function testEncryptedString (): void
21+ {
22+ $ model = Casting::query ()->create (['encryptedString ' => 'encrypted ' ]);
23+
24+ self ::assertIsString ($ model ->encryptedString );
25+ self ::assertEquals ('encrypted ' , $ model ->encryptedString );
26+ self ::assertNotEquals ('encrypted ' , $ model ->getRawOriginal ('encryptedString ' ));
27+ self ::assertEquals ('encrypted ' , app ()->make (Encrypter::class)->decryptString ($ model ->getRawOriginal ('encryptedString ' )));
28+ }
29+ }
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class Casting extends Eloquent
3232 'datetimeWithFormatField ' ,
3333 'immutableDatetimeField ' ,
3434 'immutableDatetimeWithFormatField ' ,
35+ 'encryptedString ' ,
3536 ];
3637
3738 protected $ casts = [
@@ -52,5 +53,6 @@ class Casting extends Eloquent
5253 'datetimeWithFormatField ' => 'datetime:j.n.Y H:i ' ,
5354 'immutableDatetimeField ' => 'immutable_datetime ' ,
5455 'immutableDatetimeWithFormatField ' => 'immutable_datetime:j.n.Y H:i ' ,
56+ 'encryptedString ' => 'encrypted ' ,
5557 ];
5658}
You can’t perform that action at this time.
0 commit comments