/** * @test */ public function views_should_add_message_to_container() { $this->mock_view_finder->shouldReceive('find')->andReturn('home/index.php'); $messages = new \Jgallred\Simplemessage\Messaging\Typed\Messages(); $messages->addTyped("Test"); $this->mock_session->shouldReceive('isStarted')->andReturn(true); $this->mock_session->shouldReceive('has')->with('messages')->andReturn(true); $this->mock_session->shouldReceive('get')->atLeast(1)->with('messages')->andReturn($messages); $view = $this->factory->make('home.index'); $view->withMessage('Test2'); $this->assertEquals($messages, $view->getData()['messages']); $this->assertNotEmpty($messages); $this->assertCount(2, $messages); }
/** * Register the view environment. * * @return void */ public function registerFactory() { $this->app->bindShared('view', function ($app) { // Next we need to grab the engine resolver instance that will be used by the // environment. The resolver will be used by an environment to get each of // the various engine implementations such as plain PHP or Blade engine. $resolver = $app['view.engine.resolver']; $finder = $app['view.finder']; $env = new Factory($resolver, $finder, $app['events'], $app['translator']); // If the session is set on the application instance, we'll inject it into // the factory instance. This allows the view to use the flash session to // get messages from the redirector if (isset($app['session'])) { $env->setSession($app['session.store']); } // We will also set the container instance on this view environment since the // view composers may be classes registered in the container, which allows // for great testable, flexible composers for the application developer. $env->setContainer($app); $env->share('app', $app); return $env; }); }