1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 12:34:03 +00:00

Handle encrypted columns which are set to null (#19)

* 🧪 Add a test for a null value

* 🐛 Don't consider null types for decryption
This commit is contained in:
Nick 2024-04-07 20:26:29 +02:00 committed by GitHub
parent 7371aac2ab
commit 65f9000328
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -143,13 +143,16 @@ class VirtualColumnTest extends TestCase
'json' => json_encode(['foo', 'bar']), // 'encrypted:json'
'object' => (object) json_encode(['foo', 'bar']), // 'encrypted:object'
'custom' => 'foo', // Custom castable 'EncryptedCast::class'
'null_value' => null, // 'encrypted'
]);
foreach($encryptedAttributes as $key => $expectedValue) {
$savedValue = $model->getAttributes()[$key]; // Encrypted
$this->assertTrue($model->valueEncrypted($savedValue));
$this->assertNotEquals($expectedValue, $savedValue);
if ($savedValue !== null) {
$this->assertTrue($model->valueEncrypted($savedValue));
$this->assertNotEquals($expectedValue, $savedValue);
}
$retrievedValue = $model->$key; // Decrypted
@ -178,6 +181,7 @@ class MyModel extends ParentModel
'json' => 'encrypted:json',
'object' => 'encrypted:object',
'custom' => EncryptedCast::class,
'null_value' => 'encrypted',
];
}