在laravel5.1上重定向时Phpunit失败
当我运行phpunit时,它失败了,即使我在实际的浏览器上执行了测试 我期望的是,当用户注册治疗师时,输入所需信息并按下按钮,然后转到下一个屏幕,将他/她分配到分支机构 有人能解释一下怎么回事吗 phpunit的堆栈跟踪如下所示:在laravel5.1上重定向时Phpunit失败,php,laravel,phpunit,Php,Laravel,Phpunit,当我运行phpunit时,它失败了,即使我在实际的浏览器上执行了测试 我期望的是,当用户注册治疗师时,输入所需信息并按下按钮,然后转到下一个屏幕,将他/她分配到分支机构 有人能解释一下怎么回事吗 phpunit的堆栈跟踪如下所示: PHPUnit 5.0.10 by Sebastian Bergmann and contributors. F. 2 / 2 (100
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 2.46 seconds, Memory: 24.25Mb
There was 1 failure:
1) TherapistsControllerTest::testCreate
A request to [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 by
exception 'ErrorException' with 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()
:
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 was registered.')
->see(self::CATEGORY_NAME)
;
}
@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
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 was registered. As default, the same item is also registered under the category.');
return redirect()->route('categories.show', [$category]);
}
测试是这样的:
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 was registered. Please assign the branches that he / she belongs to.')
23 ->seePage('Assign Branches to Therapist')
24 ;
25 }
@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
public function doRegister(Request $request)
{
$therapist = self::createData($request);
\Session::flash('flash_success', 'New therapist was registered. Please assign the branches that he / she belongs to.');
return redirect()->route('therapists.preAssign', $therapist->therapist_id);
}
刀片代码如下所示:
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 was registered. Please assign the branches that he / she belongs to.')
23 ->seePage('Assign Branches to Therapist')
24 ;
25 }
@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
public function doRegister(Request $request)
{
$therapist = self::createData($request);
\Session::flash('flash_success', 'New therapist was registered. Please assign the branches that he / she belongs to.');
return redirect()->route('therapists.preAssign', $therapist->therapist_id);
}
我也有类似的代码,但它通过没有任何错误
测试代码如下:
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 2.46 seconds, Memory: 24.25Mb
There was 1 failure:
1) TherapistsControllerTest::testCreate
A request to [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 by
exception 'ErrorException' with 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()
:
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 was registered.')
->see(self::CATEGORY_NAME)
;
}
@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
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 was registered. As default, the same item is also registered under the category.');
return redirect()->route('categories.show', [$category]);
}
刀片如下所示:
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 2.46 seconds, Memory: 24.25Mb
There was 1 failure:
1) TherapistsControllerTest::testCreate
A request to [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 by
exception 'ErrorException' with 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()
:
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 was registered.')
->see(self::CATEGORY_NAME)
;
}
@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
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 was registered. As default, the same item is also registered under the category.');
return redirect()->route('categories.show', [$category]);
}
我提前感谢您的支持。phpunit告诉您,当它试图访问url
http://nuatthai.loc/therapists/77/assign
,它在视图文件中遇到错误:未定义索引:REQUEST\u URI
因此,在我看来,您在该url加载的任何视图都试图访问$\u服务器['REQUEST\u URI']
,而不首先检查请求URI
键是否存在
$\u服务器
数组中的条目永远不能保证存在。在访问之前检查是否存在总是一个好主意。是的,正如您提到的,我在您指向的URL中有代码。这是为了从URL“”生成URL,如“”。在这种情况下,用户首先看到URL“”,如果用户使用关键字“test”搜索,则将URL“”连同当前URL和关键字之间的组合传递给应用程序。如何修复代码以达到我的目的?当我将表单的操作设置为空时,它就起作用了。但我仍然怀疑它是否正确。