jeudi 29 janvier 2015

Functional testing Laravel ViewComposer

I am trying to test controllers in Laravel using the standard set up this works fine. The test below passes.



class ExampleTest extends TestCase {



/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{

$crawler = $this->client->request('GET', '/');
$this->assertTrue($this->client->getResponse()->isOk());
}


However once I introduce a ViewComposer - registered with a ServiceProvider



class MenuComposer {

const NONE = 0;
const READWRITE = 1;
const READONLY = 2;




/**
* constructor largely for testing purposes
* @param View $view
* @param Auth $auth
*/
public function __construct()
{



}

public function compose($view)
{
$access = $this->getAccessLevel();

$view->with('menuItems',$this->menuItems($access));

}


The production code works as expected - but the test fails because it **ErrorException: Trying to get property of non-object (View: **


So the $view variable passed into the compose method is null/empty ? Can anyone suggest what I could do to make tests run and continue to use the viewcomposer functionality?


Aucun commentaire:

Enregistrer un commentaire