[英]PHPUnit in Laravel 5.1 flush request()?
看来我对PHPUnit不了解一些基本知识。 我的问题:
在AppServiceProvider.php中
class AppServiceProvider extends ServiceProvider{
public function boot() {
request()->country_id = 100;
}
}
在IndexController.php中
public function index(Request $request) {
dd(request()->country_id);
}
例如,这里的控制器,可以在视图,控制器,任何地方使用...
从框的基本测试ExampleTest.php
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
public function testBasicExample()
{
$this->visit('/')
->see('Laravel 5');
}
}
在浏览器中它将显示100 ,当我在CLI中使用“ phpunit tests / ExampleTest”时,它将返回null 。 为什么?
以这种方式使用request()是否正确? 因为每个国家/地区都有自己的域,所以域(主机)是一部分或要求。 因此,我决定也将国家/地区作为请求的一部分,这在我的逻辑中是有道理的。
我找到了解决方案。 是我的错 它应该在RouteServiceProvider中,而不是AppServiceProvider中 。 谢谢大家!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.