Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thiagocoelho's avatar

Testing routes / page render?

Hi everybody,

I'm wondering what kind of test should I research when we are talking about page render?

I just want to checkout all my routes that render a view, to see if any of them return some kind of error (ErrorException (E_ERROR))

Imagine this scenario: I have a variable that is shared across all my views and for some reason this variable isn't available / accessible and my page is not rendered.

I can't test (navigate) all my routes manually whenever I run a new deploy.

I'm not sure if it's clear what I'm saying.

0 likes
5 replies
bobbybouwmann's avatar

I know you can do something like this (unit test)

// app/Http/Controllers/PostsController.php

public function index()
{
    $posts = Post::all();

    return view('posts.index', compact('posts'));
}

// tests/controllers/PostsControllerTest.php
 
public function testIndex()
{
    $this->call('GET', 'posts');

    $this->assertViewHas('posts');
}

This will check if a route holds a certain variable. However you can't use this to test injected services and so on.

Source: http://code.tutsplus.com/tutorials/testing-laravel-controllers--net-31456#highlighter_383269

kxj003's avatar

@bobbybouwmann,hello, The link you provide is laravel 4, There are many difference between 5 and 4 about testing controllers.I am confused about testing controllers.

bobbybouwmann's avatar

@kxj003 My reply was also 7 months ago.... The principles are still the same for testing Laravel 4 or 5 controllers.

Please or to participate in this conversation.