美文网首页
laravel API测试session及cache构造

laravel API测试session及cache构造

作者: 会飞一下 | 来源:发表于2019-03-27 17:00 被阅读0次

使用laravel 开发完api接口后 , 为api编写测试脚本可以大大提高测试效率
phpunit vendor/custom/test/exampleTest.php

laravel 的 session 及cache 是通过数组进行构造的 , 如下

class exampleTest extends testCase{

    public function abTest(){
    
        $session = ['key'=>value];
        $cache = ['key' => value];
        
        Cache::shouldReceive('get')->with('key')->addReturn($cache);  //Cache::get('key')  == $cache
        Cache::shouldReceive('pull')->with('key')->addReturn(null);  //Cache::pull('key') == null
        
        $res = $this->withSession($session)->json('get','http://',$data);
        $res->assertStatus(200);
    
    }
    
}

相关文章

网友评论

      本文标题:laravel API测试session及cache构造

      本文链接:https://www.haomeiwen.com/subject/bhiyvqtx.html