mercredi 3 janvier 2018

Orchestra Testbench current route always return null

I'm working on a Laravel package it is working when I use it in my Laravel project, but when I want to test it with Orchestra Testbench I always get current route null inside middlware.

Test directory on Github: http://ift.tt/2CvgyMu

Base TestCase:

class TestCase extends Orchestra\Testbench\TestCase
{
    protected function getEnvironmentSetUp($app)
    {
        $kernel = app('Illuminate\Contracts\Http\Kernel');

        $kernel->pushMiddleware(\Illuminate\Session\Middleware\StartSession::class);
        $kernel->pushMiddleware(\Yoeunes\Larafast\Middlewares\BlacklistRoutes::class);
    }
}

WebControllerTest:

class WebControllerTest extends TestCase
{
    public function setUp()
    {
        parent::setUp();

        /** @var \Illuminate\Routing\Router $router */
        $router = $this->app['router'];

        $router->resource('lessons', 'Yoeunes\Larafast\Tests\Stubs\Controllers\Web\LessonController');
    }

    /** @test */
    public function it_show_create_page()
    {
        /** @var TestResponse $response */
        $response = $this->call('get', '/lessons/create');
        dd($response);
        $response->assertSuccessful();
        $response->assertSee('<title>lessons create |  Larafast</title>');
        $response->assertSee('<i class="fa fa-plus-circle"></i> lessons create');
        $response->assertSee('<form method="POST" action="http://localhost/lessons" accept-charset="UTF-8" enctype="multipart/form-data">');
    }
}

BlacklistRoutes Middleware:

class BlacklistRoutes
{
    public function handle($request, Closure $next)
    {
        dd(app('router')->getCurrentRoute()); // always get null
        if (null !== ($route = app('router')->getCurrentRoute())
            && is_a($controller = $route->getController(), Controller::class)
            && in_array($route->getActionMethod(), $controller->getBlacklist(), true)) {
            throw new BlacklistRouteException();
        }

        return $next($request);
    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AiR6DT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire