I am writing PHP Laravel 5 unit test to check my form submission is happening properly. Below is my form. (Form attach an image file too)
<form action="upload_question123" method="post" id="story_upload_form" enctype="multipart/form-data" class="form-horizontal">
@if(isset($edit_Q_Status))
<div id="great" class="form-group">
<div class="col-sm-3 col-md-3 col-lg-2"></div>
<div class=" col-sm-3 col-md-3 col-lg-5 alert alert-success alert-block">
<a class="close" data-dismiss="alert" href="#">×</a>
<h4 class="alert-heading">Success!</h4>
{{ $edit_Q_Status }}
</div>
</div>
@endif
<div class="form-group">
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Subject</label>
<div class="col-sm-3 col-md-3 col-lg-2">
<select name="subject">
@foreach($sub as $rowSub)
<option value=<?php echo '"'.$rowSub->id.'" '; ?> >{{ $rowSub->subject }}</option>
@endforeach
</select>
</div>
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Age category</label>
<div class="col-sm-3 col-md-3 col-lg-2">
<select name="ageCategory">
@foreach($agecat as $rowAge)
<option value=<?php echo '"'.$rowAge->id.'" '; ?>>{{ $rowAge->agefrom }} - {{ $rowAge->ageto }}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Question</label>
<div class="col-sm-3 col-md-3 col-lg-8">
<textarea name="question" id="question" class="col-sm-3 col-md-3 col-lg-10" placeholder="Enter the question here"></textarea>
</div>
<div class="col-sm-3 col-md-3 col-lg-2"></div>
</div>
<div class="form-group">
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Select Image</label>
<div class="col-sm-3 col-md-3 col-lg-2">
<input type="file" name="file[]" id="file" required="yes"/>
</div>
<div class="col-sm-3 col-md-3 col-lg-2"></div>
<div class="col-sm-3 col-md-3 col-lg-2">
<input type="button" id="add_more" class="upload" value="Add More Files"/>
</div>
</div>
<div id="before_this" class="form-group">
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Answer 1</label>
<div class="col-sm-3 col-md-3 col-lg-4">
<textarea class="col-sm-3 col-md-3 col-lg-12" id="ans1" name="ans1"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Answer 2</label>
<div class="col-sm-3 col-md-3 col-lg-4">
<textarea class="col-sm-3 col-md-3 col-lg-12" id="ans2" name="ans2"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Answer 3</label>
<div class="col-sm-3 col-md-3 col-lg-4">
<textarea class="col-sm-3 col-md-3 col-lg-12" id="ans3" name="ans3"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-md-3 col-lg-2 control-label">Answer 4</label>
<div class="col-sm-3 col-md-3 col-lg-4">
<textarea class="col-sm-3 col-md-3 col-lg-12" id="ans4" name="ans4"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-3 col-md-3 col-lg-2"></div>
<div class="col-sm-3 col-md-3 col-lg-2"></div>
<div class="col-sm-3 col-md-3 col-lg-2"></div>
<div class="col-sm-3 col-md-3 col-lg-2">
<a href="#"
onclick="javascript:submitOfQuestion();"
data-toggle="dropdown"
class="btn btn-primary dropdown-toggle"><i
class="fa fa-upload icon-white"></i> Upload </a>
</div>
</div>
</div>
</form>
And I wrote the below test method.
/** @test */
public function testUploadQuestion(){
$this->select('Computer', 'subject')
->select('7 - 10', 'ageCategory')
->type('Test Case Test Question 1', 'question')
->attach('C:\xampp\htdocs\IntelliKid\public\test_resources\Capture2.JPG', 'file[]')
->type('Test Case Test Answer 1', 'ans1')
->type('Test Case Test Answer 2', 'ans2')
->type('Test Case Test Answer 3', 'ans3')
->type('Test Case Test Answer 4', 'ans4')
->press('Upload')
->see('Success!');
}
But I get the following error and I have no idea where it is going wrong.
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
.....
Fatal error: Call to a member function filter() on a non-object in C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php on line 793
Fatal error: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.' in C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Container\Container.php:752
Stack trace:
#0 C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Container\Container.php(633): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 C:\xampp\htdocs\IntelliKid\vendor\ in C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 752
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire