Laravel 5.1 中的 PHPUnit 刷新请求()?
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);
}
这里以Controller为例,它可以用在views,controllers,无处不在...
盒子里的基本测试 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" 它会 return null.为什么?
这样使用 request() 是否正确?因为每个国家都有自己的域,域(主机)是一个部分或请求。所以我决定让国家也成为请求的一部分,这在我的逻辑中是有意义的。
我找到了解决方案。这是我的错误。它应该在 RouteServiceProvider 而不是 AppServiceProvider。感谢大家!
看来我不了解 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);
}
这里以Controller为例,它可以用在views,controllers,无处不在...
盒子里的基本测试 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" 它会 return null.为什么?
这样使用 request() 是否正确?因为每个国家都有自己的域,域(主机)是一个部分或请求。所以我决定让国家也成为请求的一部分,这在我的逻辑中是有意义的。
我找到了解决方案。这是我的错误。它应该在 RouteServiceProvider 而不是 AppServiceProvider。感谢大家!