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
32
32
'datetimeWithFormatField ' ,
33
33
'immutableDatetimeField ' ,
34
34
'immutableDatetimeWithFormatField ' ,
35
+ 'encryptedString ' ,
35
36
];
36
37
37
38
protected $ casts = [
@@ -52,5 +53,6 @@ class Casting extends Eloquent
52
53
'datetimeWithFormatField ' => 'datetime:j.n.Y H:i ' ,
53
54
'immutableDatetimeField ' => 'immutable_datetime ' ,
54
55
'immutableDatetimeWithFormatField ' => 'immutable_datetime:j.n.Y H:i ' ,
56
+ 'encryptedString ' => 'encrypted ' ,
55
57
];
56
58
}
You can’t perform that action at this time.
0 commit comments