Answer the question
In order to leave comments, you need to log in
Testing Laravel 5.1 View facade?
There is a getIndex method for HomeController:
public function getIndex()
{
return \View::make('home');
}
Route::get('/', ['as' => 'home', 'uses' => '[email protected]']);
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class HomeControllerTest extends TestCase
{
public function testIndexPage()
{
\View::shouldReceive('make')->with('home')->andReturn('test');
$response = $this->action('GET', '[email protected]');
$this->assertResponseOk();
$this->assertEquals('test', $response->content());
}
}
Answer the question
In order to leave comments, you need to log in
I tested this code on L5:
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class HomeControllerTest extends TestCase
{
public function testIndexPage()
{
\View::shouldReceive('make')->with('home')->andReturn('test');
View::shouldReceive('share');
$response = $this->action('GET', '[email protected]');
$this->assertResponseOk();
$this->assertEquals('test', $response->getContent());
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question