title: Unable to run multiple controller tests in Laravel
body: <p>I'm attempting to clean up an existing application by writing unit tests for some legacy code (and updating it along the way). I've rewritten a number of libraries and I've really been loving the TDD approach. However, now it's time to move on to testing some controllers, and I've run into a problem on the very first set of tests. I'm following the explanations in Jeffery Way's <em>Laravel Testing Decoded</em>.</p>
  
  <p>The goal here is to test my login route: <code>http://my-development-server/login</code>. The code should work like this: first, check to see if someone is already logged in - if they are, redirect them to the dashboard (the main page in the app). Otherwise, render the login page. Pretty straight forward.</p>
  
  <p>Here are the routes involved:</p>
  
  <pre><code>Route::get('login', array(
          'as'        =&gt; 'login',
          'uses'      =&gt; 'MyApp\Controllers\AccountController@getLogin',
      ));
  
  Route::get('/', array(
          'as'        =&gt; 'dashboard',
          'uses'      =&gt; 'MyApp\Controllers\DashboardController@showDashboard',
          'before'    =&gt; 'acl:dashboard.view',
      ));
  </code></pre>
  
  <p>Here's the <code>AccountController::getLogin</code> method:</p>
  
  <pre><code>public function getLogin()
  {
      // Are we logged in?
      if (\Sentry::check())
          return Redirect::route('dashboard');
  
      // Show the page.
      return View::make('account.login');
  }
  </code></pre>
  
  <p>I'm using the <code>Sentry</code> library for user authentication.</p>
  
  <p>And here's my first test:</p>
  
  <pre><code>class AccountControllerTest extends TestCase {
  
      public function tearDown()
      {
          Mockery::close();
      }
  
      public function test_login_alreadyLoggedIn()
      {
          // arrange
          //
          \Sentry::shouldReceive("check")
              -&gt;once()
              -&gt;andReturn(true);
  
          // act
          //
          $response = $this-&gt;call("GET", "/login");
  
          // assert
          //
          $this-&gt;assertRedirectedToRoute("dashboard");
      }
  }
  </code></pre>
  
  <p>This test emulates the "user attempts to log in when they're already logged in" case. <code>check</code> returns true (already logged in) and the user is redirected to the route named <code>dashboard</code>. It works perfectly, test passes.</p>
  
  <p>Next, I add a new test, to test the "user attempts to log in when nobody's logged in" case. Here's the code for that test:</p>
  
  <pre><code>public function test_login_notLoggedIn()
  {
      // arrange
      //
      \Sentry::shouldReceive("getUser")
          -&gt;twice()
          -&gt;andReturn(null);
  
      \Sentry::shouldReceive("check")
          -&gt;once()
          -&gt;andReturn(false);
  
      // act
      //
      $response = $this-&gt;client-&gt;request("GET", "/login");
  
      // assert
      //
      $h2 = $response-&gt;filter("h2");
  
      $this-&gt;assertEquals("Please sign in", $h2-&gt;text());
  }
  </code></pre>
  
  <p>When I run this test, the first test passes but I get a <code>NotFoundHttpException</code> in the second test method.</p>
  
  <p>There are a couple of strange things about this problem:</p>
  
  <ol>
  <li><p>if I comment out the first test method (<code>test_login_alreadyLoggedIn</code>), the second test passes.</p></li>
  <li><p>if I reverse the order of the two test methods, <code>test_login_notLoggedIn</code> passes and <code>test_login_alreadyLoggedIn</code> fails (ie. the first method in the class passes and the second fails).</p></li>
  </ol>
  
  <p>This looks to me like some sort of configuration issue - after the first test (which passes), something is messed up and it cannot make the request in the second test - but I'm at a loss. I've gone over the book several times and google but can't find any reference to any configuration that I'm missing.</p>
  
  <p>Any suggestions?</p>