Testing a secure route laravel 5.5 NotFoundHttpException

Posted 3 months ago by longestdrive

Hi

Today's testing question is on secure routes.

Within my routes file I have:

if (App::environment() == 'deployed') {
\URL::forceScheme("https");
}

Route::get('/contact', array(
    'https',
    'as' => 'contact.secure.page',
    'uses' => '[email protected]'
));

This works on the live server. On my testing development machine I don't have any certificates installed so always get an error message about security etc but ignored until now as it didn't affect my development.

Now I'm trying to write a test to ensure the page is visible and here's my test:

    namespace Tests\Feature;
 
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ContactFormTest extends TestCase
{

    use DatabaseMigrations;

    public function setUp()
    {
        parent::setUp();

        $this->disableExceptionHandling();

    }

    public function test_visitor_can_see_contact_form()
    {

        $response = $this->get('/contact');

        $response->assertResponseStatus(200)
            ->assertSee('CONTACT US');
    }


    }

But the test fails because with an httpNotFound exception

In earlier versions of Laravel I could use

$response = $this->callSecure('GET', '/contact');

But this no longer works in Laravel 5.5.

How can I specify the test creates and calls an https url for this test?

Thanks

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.