vendredi 21 août 2015

Phpunit throws an error when testing a from which has a partial view in Laravel

I just start writing unit testing recently, so the concept it's self is still not really clear for me, I'm trying to learn it by writing unit testing on a current project that I'm working on, I have tested the auth it's all good, when I wanted to test a form submission, it throws errors an 'ErrorException' with message 'Undefined variable: errors' when I was debugging I came across that the view variable $errors is not defined for Phpunit, The form I'm testing was abstracted to a partial view to reference from it for CREATE/UPDATEbut it turns out that Phpunit can't handle the partial views, I have tested it when I comment the @include('view.name') form the view I'm testing it passes it.

so, My question is there any workaround to this, How can I test the views that has partial views, or I'm writing something wrong.

Exception:

Caused by
exception 'ErrorException' with message 'Undefined variable: errors' in                  /Users/***/Developpement/***/storage/framework/views/36f0b5638ab33     be6eca70d4986f07ad2:2
Stack trace:
#0     /Users/***/Developpement/***/storage/framework/views/36f0b5638ab33    be6eca70d4986f07ad2(2):     Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined     varia...', '/Users/***/D...', 2, Array)
#1     /Users/***/Developpement/***/vendor/laravel/framework/src/Illumina    te/View/Engines/PhpEngine.php(42): include('/Users/***/D...')
#2     /Users/***/Developpement/***/vendor/laravel/framework/src/Illumina    te/View/Engines/CompilerEngine.php(58): ***        minate\View\Engines\PhpEngine->evaluatePath('/Users/***/D...', Array)
#3         /Users/***/Developpement/***/vendor/laravel/framework/src/Illumina    te/View/View.php(138): Illuminate\View\Engines\CompilerEngine-    >get('/Users/***/D...', Array)

Parent View

<div class="container">

    {!! Form::open(['route' => 'admin.festivals.create.post', 'enctype' => 'multipart/form-data']) !!}

    <legend>Create</legend>
    <div class="pull-right">
        <a class="btn btn-info" href="   {{route('admin.festivals.list')}}">Home</a>
    </div>

     // HERE IS THE LINE WHEN I COMMENT IT IT WORKS
    {{--@include('admin.festivals._form')--}}

        {!! Form::submit('Create', ['class' => 'btn btn-primary col-md-2']) !!}
    {!! Form::close() !!}


</div>

Partial View

<div class="form-group row {{ $errors->has('start_date') ? 'has-error' : '' }}">
<label class="control-label col col-md-2" for="start_date">Start Date</label>

<div class="col col-md-4">
    {!! Form::datepicker('start_date', (isset($festival)) ? $festival->start_date : null) !!}
    {!! $errors->first('start_date', '<span class="help-block">:message</span>') !!}
</div>

Aucun commentaire:

Enregistrer un commentaire