|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Foundation\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Foundation\Abstracts\Tests\TestCase; |
|
6
|
|
|
use Foundation\Cache\ModelCache; |
|
7
|
|
|
use Modules\Account\Entities\Account; |
|
8
|
|
|
|
|
9
|
|
|
class CacheObserverTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testCache() |
|
12
|
|
|
{ |
|
13
|
|
|
$user = $this->createUser(); |
|
14
|
|
|
$user->fresh(); |
|
15
|
|
|
unset($user->role_ids); |
|
|
|
|
|
|
16
|
|
|
$this->assertEquals($user->toArray(), $user::cache()->find($user->id, false)->toArray()); |
|
17
|
|
|
$this->assertEquals($user->toArray(), $user::cache()->findBy('identity_id', $user->identity_id, false)->toArray()); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testCacheSpeed(){ |
|
21
|
|
|
$model = Account::create(["testthisshit"=>5]); |
|
22
|
|
|
\Cache::put('testmodel',$model); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
$time_db_start = microtime(true); |
|
25
|
|
|
for($i=0; $i<1000;$i++){ |
|
26
|
|
|
Account::find($model->id); |
|
27
|
|
|
} |
|
28
|
|
|
$time_db_end = microtime(true); |
|
29
|
|
|
|
|
30
|
|
|
$dbTime = $time_db_end - $time_db_start; |
|
31
|
|
|
|
|
32
|
|
|
$time_cache_start = microtime(true); |
|
33
|
|
|
|
|
34
|
|
|
for($i=0; $i<1000;$i++){ |
|
35
|
|
|
\Cache::get('testmodel'); |
|
36
|
|
|
} |
|
37
|
|
|
$time_cache_end = microtime(true); |
|
38
|
|
|
|
|
39
|
|
|
$cacheTime = $time_cache_end - $time_cache_start; |
|
40
|
|
|
|
|
41
|
|
|
$this->assertGreaterThan($cacheTime, $dbTime); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testClearModelsCache() |
|
45
|
|
|
{ |
|
46
|
|
|
$user = $this->createUser(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertNotNull($user::cache()->find($user->id)); |
|
49
|
|
|
ModelCache::clearAll(); |
|
50
|
|
|
$this->assertNull($user::cache()->find($user->id)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testClearSpecificModelCache() |
|
54
|
|
|
{ |
|
55
|
|
|
$user = $this->createUser(); |
|
56
|
|
|
$this->assertNotNull($user::cache()->find($user->id)); |
|
57
|
|
|
$user::cache()->clearModelCache(); |
|
58
|
|
|
$this->assertNull($user::cache()->find($user->id)); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.