php - Phpunit fails when redirect on laravel5.1 -


when ran phpunit, failed though performed test on actual browser.

what expect when user registers therapist, put required information , press button transit next screen assign him/her branch.

can explain what's wrong?

phpunit's stack trace follows:

phpunit 5.0.10 sebastian bergmann , contributors.  f.                                                                  2 / 2 (100%)  time: 2.46 seconds, memory: 24.25mb  there 1 failure:  1) therapistscontrollertest::testcreate request [http://nuatthai.loc/therapists/77/assign] failed. received status code [500].  /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/foundation/testing/interactswithpages.php:165 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/foundation/testing/interactswithpages.php:63 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/foundation/testing/interactswithpages.php:109 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/foundation/testing/interactswithpages.php:63 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/foundation/testing/interactswithpages.php:85 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/foundation/testing/interactswithpages.php:658 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/foundation/testing/interactswithpages.php:645 /users/kondonator/documents/htdocs/nuatthai/tests/therapistscontrollertest.php:21  caused exception 'errorexception' message 'undefined index: request_uri' in /users/kondonator/documents/htdocs/nuatthai/storage/framework/views/9eeab8e0b5ecca2e976774be0813d5d7:24 stack trace: #0 /users/kondonator/documents/htdocs/nuatthai/storage/framework/views/9eeab8e0b5ecca2e976774be0813d5d7(24): illuminate\foundation\bootstrap\handleexceptions->handleerror(8, 'undefined index...', '/users/kondonat...', 24, array) #1 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/view/engines/phpengine.php(42): include('/users/kondonat...') #2 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/view/engines/compilerengine.php(58): illuminate\view\engines\phpengine->evaluatepath('/users/kondonat...', array) #3 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/view/view.php(135): illuminate\view\engines\compilerengine->get('/users/kondonat...', array) #4 /users/kondonator/documents/htdocs/nuatthai/vendor/laravel/framework/src/illuminate/view/view.php(106): illuminate\view\view->getcontents() : 

test this:

12    public function testcreate() 13    { 14      $user = self::getowner(); 15      $this->assertnotnull($user); 16      $this->actingas($user) 17              ->visit('/therapists/register') 18              ->see('register new therapist') 19              ->type('test therapist 4', 'name') 20              ->select('false', 'lmt') 21              ->press('register') 22              ->seepage('new therapist registered. please assign branches / belongs to.') 23              ->seepage('assign branches therapist') 24              ; 25    } 

and blade code this:

@section('content')           @include('common.message')            <h1>register new therapist</h1>            {!! form::open(array('action' => ['therapistscontroller@doregister'])) !!}           @include('therapists.form', ['modifier' => 'required'])              <div style="text-align:right;">               {!! form::submit('register', ['class' => 'submit btn btn-primary btn-lg']) !!}             </div>           {!! form::close() !!} @endsection 

then code of controller this:

  public function doregister(request $request)   {     $therapist = self::createdata($request);     \session::flash('flash_success', 'new therapist registered. please assign branches / belongs to.');     return redirect()->route('therapists.preassign', $therapist->therapist_id);   } 

i have similar codes passes without errors.

test code follows:

  public function testcreate()   {     $user = self::getaccountant();     $this->assertnotnull($user);     $this->actingas($user)             ->visit('/categories/create')             ->see('add new expense category')             ->type(self::category_name, 'name')             ->press('add')             ->see('view existing expense category')             ->see('new category registered.')             ->see(self::category_name)             ;    } 

the blade follows:

@section('content')           @include('common.message')            <h1>add new expense category</h1>            {!! form::open(array('action' => ['categoriescontroller@docreate'])) !!}             @include('categories.form', ['modifier' => 'required'])              <div style="text-align:right;">               {!! form::submit('add', ['class' => 'submit btn btn-primary btn-lg']) !!}             </div>           {!! form::close() !!}  @endsection 

and controller follows:

  public function docreate(request $request)   {     $name = $request->name;     $category = category::create(['name' => $name]);     $item = item::create(['name' => $name]);     categoryitem::create(["category_id" => $category->category_id, "item_id" => $item->item_id]);     \session::flash('flash_success', 'new category registered. default, same item registered under category.');     return redirect()->route('categories.show', [$category]);       } 

i appreciate of support in advance.

phpunit telling when tried access url http://nuatthai.loc/therapists/77/assign, ran error: undefined index: request_uri in view file.

therefore, seems me, whatever view you're loading @ url trying access $_server['request_uri'] without first checking see if request_uri key exists.

entries in $_server array never guaranteed exist. idea check existence before accessing.


Comments