think-testing
think-testing copied to clipboard
对HTTP状态码断言异常
控制器如下:
<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function index(){
return 'test';
}
public function index2(){
$this->redirect('http://www.baidu.com',302);
}
}
测试类如下:
<?php
namespace tests;
//针对Index控制器
class IndexTest extends TestCase
{
public function testOutput(){
$this->visit('/index/index/index')->assertResponseOk();
}
public function testNo(){
$response=$this->visit('/index/index/index2');
$response->assertResponseStatus(200);//不是302
$response->see('test');//OK
}
}
$this->clearInputs()->followRedirects()->assertPageLoaded($uri);
因为这里对于302的状态码都会再次解析,因此会导致对于外域的地址,比如跳转到百度,会造成定位到index控制器下的index方法。