title: Laravel 4 - Unit Tests
body: <p>I am trying to write unit tests for my application, I think I know how to test a GET request for example;
  The controller I am testing has the following function, which is supposed to get the 'account create view'</p>
  
  <pre><code>public function getCreate() {
      return View::make('account.create');
  }
  </code></pre>
  
  <p>Also, this is referenced in the routes file like this</p>
  
  <pre><code>/*
  Create account (GET)
  */
  Route::get('/account/create', array(
      'as'  =&gt;  'account-create',
      'uses'  =&gt;  'AccountController@getCreate'
  ));
  </code></pre>
  
  <p>and what I am doing for testing looks like this: </p>
  
  <pre><code>public function testGetAccountCreate()
  { 
    $response = $this-&gt;call('GET', '/account/create');
  
    $this-&gt;assertTrue($response-&gt;isOk()); 
  
    $this-&gt;assertResponseOk();
  }
  </code></pre>
  
  <p>Now this test passes, but what if I want to test the POST request? 
  The post function I want to test is the following:</p>
  
  <pre><code>    public function postCreate() {
      $validator = Validator::make(Input::all(),
          array(
              'email'           =&gt; 'required|max:50|email|unique:users',
              'username'        =&gt; 'required|max:20|min:3|unique:users',
              'password'        =&gt; 'required|min:6',
              'password_again'  =&gt; 'required|same:password'
          )
      );
  
      if ($validator-&gt;fails()) {
          return Redirect::route('account-create')
                  -&gt;withErrors($validator)
                  -&gt;withInput();
      } else {
  
          $email    = Input::get('email');
          $username = Input::get('username');
          $password = Input::get('password');
  
          // Activation code
          $code     = str_random(60);
  
          $user = User::create(array(
              'email' =&gt; $email,
              'username' =&gt; $username,
              'password' =&gt; Hash::make($password),
              'password_temp' =&gt; '',
              'code'  =&gt; $code,
              'active'  =&gt; 0
          ));
  
          if($user) {
  
              Mail::send('emails.auth.activate', array('link' =&gt; URL::route('account-activate', $code), 'username' =&gt; $username), function($message) use ($user) {
                  $message-&gt;to($user-&gt;email, $user-&gt;username)-&gt;subject('Activate your account');
              });
  
              return Redirect::route('account-sign-in')
                    -&gt;with('global', 'Your account has been created! We have sent you an email to activate your account.');
          }
      }
  }
  </code></pre>
  
  <p>This is also referenced in routes file like this: </p>
  
  <pre><code>  /*
    Create account (POST)
    */
    Route::post('/account/create', array(
        'as'  =&gt;  'account-create-post',
        'uses'  =&gt;  'AccountController@postCreate'
    ));
  </code></pre>
  
  <p>I have tried to write the following test but no success. I am not sure what is going wrong, I think its because this needs data and i am not passing them in correctly? Any clue to get started with unit tests, appreciated.</p>
  
  <pre><code>public function testPostAccountCreate()
  {
  $response = $this-&gt;call('POST', '/account/create');
  $this-&gt;assertSessionHas('email');
  $this-&gt;assertSessionHas('username');
  $this-&gt;assertSessionHas('email');
  }
  </code></pre>
  
  <p>The output of the test is: </p>
  
  <pre><code>There was 1 failure:
  
  1) AssetControllerTest::testPostAccountCreate
  Session missing key: email
  Failed asserting that false is true.
  
  /www/assetlibr/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:271
  /www/assetlibr/app/tests/controllers/AssetControllerTest.php:23
  </code></pre>