laravel API测试session及cache构造

2019-03-27  本文已影响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);
    
    }
    
}
上一篇 下一篇

猜你喜欢

热点阅读