title: Setting attributes on models while testing
body: <p>I am trying to test a controller and am mocking the models.  All seems to go well until the view is loaded, it's unable to retrieve properties on that view that are supposed to be loaded via relationships.</p>
  
  <p>I've tried setting those properties using <code>andSet()</code> on the mocked object, but then that gives me an error <code>getAttribute() does not exist on this mocked object.</code>.</p>
  
  <p>Here's my controller method.</p>
  
  <pre><code>public function __construct(ApplicationRepositoryInterface $application)
  {
      $this-&gt;beforeFilter('consumer_application');
  
      $this-&gt;application = $application;
  }
  
  public function edit($application_id)
  {
      $application = $this-&gt;application-&gt;find($application_id);
  
      $is_consumer = Auth::user()-&gt;isAdmin() ? 'false' : 'true';
  
      return View::make('application.edit')
          -&gt;with('application', $application)
          -&gt;with('is_consumer', $is_consumer)
          -&gt;with('consumer', $application-&gt;consumer);
  }
  </code></pre>
  
  <p>And my test...</p>
  
  <pre><code>public function setUp()
  {
      parent::setUp();
      $this-&gt;mock = Mockery::mock($this-&gt;app-&gt;make('ApplicationRepositoryInterface'));
  }
  
  public function testEdit()
  {
      $this-&gt;app-&gt;instance('ApplicationRepositoryInterface', $this-&gt;mock);
  
      $this-&gt;mock
          -&gt;shouldReceive('find')
          -&gt;once()
          -&gt;andReturn(Mockery::mock('Application'))
          -&gt;andSet('consumer', Mockery::mock('Consumer'));
  
      Auth::shouldReceive('user')
          -&gt;once()
          -&gt;andReturn(Mockery::mock(array('isAdmin' =&gt; 'true')));
  
      $application_id = Application::first()-&gt;id;
      $this-&gt;call('GET', 'consumer/application/'.$application_id.'/edit');
  
      $this-&gt;assertResponseOk();
      $this-&gt;assertViewHas('application');
      $this-&gt;assertViewHas('is_consumer');
      $this-&gt;assertViewHas('consumer');
  }
  </code></pre>
  
  <p>The furthest I have gotten is removing the the <code>andSet()</code> portion which takes care of the <code>getAttribute() does not exist on this mock object</code> but then it tells me <code>consumer</code> is undefined when the view is loaded and still fails.</p>