程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了laravel 8 中的 phpunit 测试得到 ErrorException: Undefined variable: path大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决laravel 8 中的 phpunit 测试得到 ErrorException: Undefined variable: path?

开发过程中遇到laravel 8 中的 phpunit 测试得到 ErrorException: Undefined variable: path的问题如何解决?下面主要结合日常开发的经验,给出你关于laravel 8 中的 phpunit 测试得到 ErrorException: Undefined variable: path的解决方法建议,希望对你解决laravel 8 中的 phpunit 测试得到 ErrorException: Undefined variable: path有所启发或帮助;

我正在对将图像存储到 AWS s3 的表单进行单元测试。在我的控制器中,我根据从视图中的表单字段发送的 $request->file('logo_url') 定义 $path 变量。

当我对其进行单元测试时,出现错误或 ErrorException: Undefined variable: path。

public function store(request $request)
{
    $request->valIDate([
        'logo_url' => 'required','company_name' => 'required','description' => 'required',]);
    if ($request->hasfile('logo_url')) {
        $path = $request->file('logo_url')->store('logo','s3');
        Storage::disk('s3')->setVisibility($path,'public');
    }
    $company = Company::create([
        'file_name' => basename($path),'company_fIEld' => $request->company_fIEld,'logo_url' => Storage::disk('s3')->url($path),'company_name' => $request->company_name,'employer_ID' => $request->employer_ID,'company_address' => $request->company_address,'company_url' => $request->company_url,'email' => $request->email,'phone_number' => $request->phone_number,'description' => $request->description,]);

    $user = $request->employer_ID;

    return redirect()->route('companyList',['user' => $user])->with('status','Company Added successfully!');
}

和我的单元测试:

/**@test */
public function test_user_create_company()
{
    $this->withoutExceptionHandling();
    $user = $this->candIDateRole();
    $this->acTingAs($user);
    $path = 'testpath';
    $response = $this->post('/companIEs-add',[
        'logo_url' => '11.jpg','company_fIEld' => 'Agriculture','file_name' => $path,'company_name' => 'Company One','employer_ID' => $user->ID,'company_address' => 'Jalan BEmliu9pcjKk4dKkb7Vd','company_url' => 'imRGdojN0i','email' => 'www.jN9nJHYZBv0NitDYKOYq.com','phone_number' => '886797','description' => 'IEwyNdrfAyFsOTeqv4OCnI3g2jYDEF3CPjqyqYAZ',]);

    $this->assertCount(1,Company::all());
}

如何将路径变量传递给测试?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

@H_616_26@

大佬总结

以上是大佬教程为你收集整理的laravel 8 中的 phpunit 测试得到 ErrorException: Undefined variable: path全部内容,希望文章能够帮你解决laravel 8 中的 phpunit 测试得到 ErrorException: Undefined variable: path所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。