N
N
naneri2015-02-26 13:07:43
PHPUnit
naneri, 2015-02-26 13:07:43

Laravel PHPunit AssertViewHas not seeing variables from base controller?

Here is the base controller code:

class BaseController extends Controller {
           public function __construct(){
                $base_config = array('base_url' => URL::to('/'));
    View::share('base_config', $base_config);
          }
}

Here is the controller code:
class MainController extends BaseController {
               public function index($id = 0){
    Log::info('This is some useful information.');
                $rating = Config::get('topic.index_good_topic_rating');
    $topics = Topic::getSubscribedTopics(Auth::user()->id, $rating);
    //echo "<pre>"; print_r($topics); echo "</pre>";exit;
    return View::make('main.index', array('topics' => $topics));
  }
}

Here is the test code:
public function testMainPage(){
    $this->be(User::find(1));
    $crawler = $this->call('GET', 'main/index');
    $this->assertViewHas(['topics']);
    $this->assertViewHas('base_config');

  }

Why doesn't the test see the variable from the base controller?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question