This repository has been archived by the owner on Apr 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
/
ExceptionTest.php
90 lines (73 loc) · 2.51 KB
/
ExceptionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* tests/Traits/ExceptionTest.php
*
* @package laravel-database-encryption
* @link https://github.com/austinheap/laravel-database-encryption
* @author Austin Heap <me@austinheap.com>
* @version v0.2.1
*/
namespace AustinHeap\Database\Encryption\Tests\Traits;
use AustinHeap\Database\Encryption\Tests\TestCase;
use AustinHeap\Database\Encryption\Traits\HasEncryptedAttributes;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Encryption\EncryptException;
/**
* ExceptionTest
*/
class ExceptionTest extends TestCase
{
public function testDoEncryptAttribute()
{
$command = new class()
{
use HasEncryptedAttributes;
protected $attributes = ['testing-attribute' => 123456789];
public function encryptedAttribute($value): ?string
{
throw new EncryptException('testing value: ' . $value);
}
protected function shouldEncrypt($key): bool
{
return true;
}
protected function isEncrypted($key): bool
{
return false;
}
public function doEncryptAttributePublic($key)
{
return $this->doEncryptAttribute($key);
}
};
$command->doEncryptAttributePublic('testing-attribute');
$this->assertNotNull($command->getLastEncryptionException());
$this->assertSame(EncryptException::class, get_class($command->getLastEncryptionException()));
}
public function testDoDecryptAttribute()
{
$command = new class()
{
use HasEncryptedAttributes;
public function decryptedAttribute($value): ?string
{
throw new DecryptException('testing value: ' . $value);
}
protected function shouldEncrypt($key): bool
{
return true;
}
protected function isEncrypted($key): bool
{
return true;
}
public function doDecryptAttributePublic($key, $value)
{
return $this->doDecryptAttribute($key, $value);
}
};
$command->doDecryptAttributePublic($this->newRandom('key-%s'), $this->newRandom('value-%s'));
$this->assertNotNull($command->getLastEncryptionException());
$this->assertSame(DecryptException::class, get_class($command->getLastEncryptionException()));
}
}