title: How do i unit test the auth filter in Laravel 4.1?
body: <p>I want to write a unit test that should check if an unauthenticated user can view the user list (which he shouldnt be able to).</p>
  
  <p><strong>My routes</strong></p>
  
  <pre><code>Route::group(array('prefix' =&gt; 'admin'), function() {
      Route::get('login', function() {
          return View::make('auth.login');
      });
      Route::post('login', function() {
          Auth::attempt( array('email' =&gt; Input::get('email'), 'password' =&gt; Input::get('password')) );
          return Redirect::intended('admin');
      });
      Route::get('logout', 'AuthController@logout');
  
      Route::group(array('before' =&gt; 'auth'), function() {
          Route::get('/', function() {
              return Redirect::to('admin/users');
          });
          Route::resource('users', 'UsersController');
      });
  });
  </code></pre>
  
  <p><strong>My test</strong></p>
  
  <pre><code>public function testUnauthenticatedUserIndexAccess() {
      $response = $this-&gt;call('GET', 'admin/users');
  
      $this-&gt;assertRedirectedTo('admin/login');
  }
  </code></pre>
  
  <p><strong>My filter</strong></p>
  
  <pre><code>Route::filter('auth', function() {
      if (Auth::guest()) return Redirect::guest('admin/login');
  });
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <p>Failed asserting that Illuminate\Http\Response Object (...) is an instance of class "Illuminate\Http\RedirectResponse".</p>
  
  <p>If i log the $response from the test, it shows the full user list like if an admin was logged in during testing.</p>
  
  <p>If i browse to admin/users using a browser without logging in I'm redirected to login like i should, so the auth filter is indeed working.</p>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li>Is there something in Laravel that logs in the first user during testing for you by default? Or is Auth::guest() always false by default during testing?</li>
  <li>If so, how do i become "logged out" during unit testing? I tried $this->be(null) but got an error saying the object passed must implement UserInterface.</li>
  </ol>