Laravel 5.2 PHPUnit attach()不会移动文件

时间:2016-10-17 16:26:54

标签: laravel phpunit

我有这种方法来存储新用户

ghci> doubleMe x = x + x
ghci> doubleMe 1
2

我有这个单元测试

public function register(CreateUserRequest $request){

    $file = $request->file('idcard');
    $fileName = rand(0, 99999).$file->getClientOriginalName();
    if($request->hasFile('idcard') && $request->file('idcard')->isValid()){
      $request->file('idcard')->move("images/idcard/", $fileName);
    }

    User::create([
      'role_id' => 1,
      'email' => $request->email,
      'password' => $request->password,
      'full_name' => $request->full_name,
      'address' => $request->address,
      'phone' => $request->phone,
      'family_name' => $request->family_name,
      'family_address' => $request->family_address,
      'family_phone' => $request->family_phone,
      'idcard' => $fileName,
      'status' => 'unconfirmed',
      'balance' => 0,
    ]);
    Session::flash('success', 'Please check your email to activate your account.');
    return redirect('/register');

}

如果我通过浏览器测试我的功能,它会成功输入数据库并移动文件。

但是当我通过PHPUnit进行测试时,它通过了测试,成功输入数据库,但图像没有移动。

我的attach()或其他错误是否有问题?

谢谢,任何帮助表示赞赏。

0 个答案:

没有答案