| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace Tests\Unit;
- use App\Authority;
- use App\Carrier;
- use App\Role;
- use App\Services\CacheService;
- use App\User;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use Ramsey\Uuid\Uuid;
- use Tests\TestCase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- class GetOrExecuteTest extends TestCase
- {
- /** @var CacheService $cacheService */
- public $cacheService;
- public function setUp(): void
- {
- parent::setUp();
- $this->cacheService = app('CacheService');
- }
- public function testPutAndGet(){
- $key = md5(microtime(true));
- $result=$this->cacheService->getOrExecute($key,function (){
- return 'yes';
- });
- $this->assertEquals('yes',$result);
- $this->assertEquals('yes',Cache::pull($key));//销毁
- }
- public function testNullFunction(){
- $this->expectException(\Exception::class);
- $key = md5(microtime(true));
- $this->cacheService->getOrExecute($key,null);
- }
- }
|