我在yii2中使用codecept功能测试来测试我的API.我将这些参数硬编码用于测试
use tests\codeception\backend\FunctionalTester;
$I = new FunctionalTester($scenario);
$I->wantTo('Check when authenticated');
$I->sendPOST('/login', ['password' => '11111111', 'email'=>'check@check.com']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('"result"');
$I->seeResponseContains('"message"');
$I->haveHttpHeader('Accept','application/json');
$I->seeResponseContains('"message":"OK"');
Run Code Online (Sandbox Code Playgroud)
我想通过codecept运行函数loginCept运行测试用例时给出这些参数,或者将这些参数保存在一个文件中,并在运行测试时分配给测试用例.我应该如何实现?
我在yii2中通过此链接创建了一个模型 http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html 我使用POST请求将文件发布到API并在我的控制器中获取所有文件信息但是使用这个Yii2.0模型无法上传文件使用上面链接正常的PHP文件上传代码工作正常.这是我的控制器代码
public function actionUploadFile()
{
$upload = new UploadForm();
var_dump($_FILES);
$upload->imageFile = $_FILES['image']['tmp_name'];
//$upload->imageFile = $_FILES;
var_dump($upload->upload());
}
Run Code Online (Sandbox Code Playgroud)
我的模型代码是
class UploadForm extends Model
{
/**
* @var UploadedFile
*/
public $imageFile;
public function rules()
{
return [
[['imageFile'], 'safe'],
[['imageFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
];
}
public function upload()
{
try {
if ($this->validate()) {
$this->imageFile->saveAs('/var/www/html/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
var_dump("Jeree");
return true;
} else {
var_dump($this->getErrors());
return false;
}
}catch (ErrorException …Run Code Online (Sandbox Code Playgroud)