Lars-Janssen's avatar

Why do I always get a 404 in my test?

Hi,

In my package I'm testing an api endpoint, but I always get a 404 response!?!?

Here is the file (see unsuccessfulLogin method):

https://github.com/larsjanssen6/underconstruction/blob/master/tests/Integration/UnderConstructionModeTest.php

$this->post('/under/check', ['code' => 1235])

In my service provider:

https://github.com/larsjanssen6/underconstruction/blob/master/src/UnderConstructionServiceProvider.php

  $routeConfig = [
            'namespace'  => 'LarsJanssen\UnderConstruction\Controllers',
            'prefix'     => 'under',
            'middleware' => [
                'web',
            ],
        ];
        $this->getRouter()->group($routeConfig, function ($router) {
            $router->post('check', [
                'uses' => 'CodeController@check',
                'as'   => 'underconstruction.check',
            ]);
            $router->get('construction', [
                'uses' => 'CodeController@index',
                'as'   => 'underconstruction.index',
            ]);
            $router->get('js', [
                'uses' => 'AssetController@js',
                'as'   => 'underconstruction.js',
            ]);
        });

I register these routes! And in postman it's working. So why is it not working in my test?

0 likes
1 reply
Jaytee's avatar

routes go in the boot method, not the register method. If that still doesn't work with your current setup, use this from the docs in the boot method.

Put them into a routes file and then use $this->loadRoutesFrom(__DIR__ . '/routes.php');

Please or to participate in this conversation.