title: Laravel 5.5 api unit testing
body: <p>I have issue on laravel api unit testing, these are my configs and simple code, but getting "Expected status code 201 but received 500". But with postman everything is ok, why??? please help <a href="https://i.stack.imgur.com/wjPba.png" rel="nofollow noreferrer">config1</a> <a href="https://i.stack.imgur.com/gw4Vz.png" rel="nofollow noreferrer">config2</a> <a href="https://i.stack.imgur.com/1q6Yx.png" rel="nofollow noreferrer">test</a> <a href="https://i.stack.imgur.com/xWjF0.png" rel="nofollow noreferrer">controller</a> <a href="https://i.stack.imgur.com/j0Y1P.png" rel="nofollow noreferrer">result</a></p>
  
  <p>There is a trait in RegisterController called RegistersUsers and in it is register() method  </p>
  
  <p><code>Route::post('register', 'Auth\RegisterController@register');</code>  </p>
  
  <p>it calls a register() method and the register method calls registered()</p>
  
  <p><strong><em>config 1 - config/database.php</em></strong></p>
  
  <pre><code>   'connections' =&gt; [
  
      'sqlite' =&gt; [
          'driver' =&gt; 'sqlite',
          'database' =&gt; ':memory:',
          'prefix' =&gt; '',
      ],
  </code></pre>
  
  <p><strong><em>config 2 - phpunit.xml</em></strong></p>
  
  <pre><code>   &lt;php&gt;
      &lt;env name="APP_ENV" value="testing"/&gt;
      &lt;env name="CACHE_DRIVER" value="array"/&gt;
      &lt;env name="SESSION_DRIVER" value="array"/&gt;
      &lt;env name="QUEUE_DRIVER" value="sync"/&gt;
      &lt;env name="DB_CONNECTION" value="sqlite"/&gt;
  &lt;/php&gt;
  </code></pre>
  
  <p><strong><em>test</em></strong></p>
  
  <pre><code>public function testRegisterSuccessfully()
  {
      $register = [
          'name' =&gt; 'UserTest',
          'email' =&gt; 'user2@test.com',
          'password' =&gt; 'testpass',
          'password_confirmation' =&gt; 'testpass'
      ];
  
      $this-&gt;json('POST', 'api/register', $register)
          -&gt;assertStatus(201)
          -&gt;assertJsonStructure([
              'token',
              'user' =&gt; [
                  'id',
                  'name',
                  'email',
                  'created_at',
                  'updated_at'
              ]
          ]);
   }
  </code></pre>
  
  <p><strong><em>controller method</em></strong></p>
  
  <pre><code>public function registered(Request $request)
  {
      $user = $this-&gt;guard()-&gt;user();
      $success['token'] = $user-&gt;createToken('WAI')-&gt;accessToken;
      $success['user'] = $user;
      return response()-&gt;json($success, 201);
  }
  </code></pre>
  
  <p><strong><em>result</em></strong></p>
  
  <pre><code> developer@developer-v3:/var/www/WAI$ composer test
   &gt; vendor/bin/phpunit
   PHPUnit 6.5.8 by Sebastian Bergmann and contributors.
  
    ..F..                                                               5 /   5 (100%)
  
  Time: 3.78 seconds, Memory: 20.00MB
  
   There was 1 failure:
  
  1) Tests\Feature\Auth\RegisterControllerTest::testRegisterSuccessfully
  Expected status code 201 but received 500.
  Failed asserting that false is true.
  
  /var/www/WAI/vendor/laravel/framework/src/Illuminate/Foundation/Testing         /TestResponse.php:78
  /var/www/WAI/tests/Feature/Auth/RegisterControllerTest.php:26
  
  FAILURES!
  Tests: 5, Assertions: 6, Failures: 1.
  Script vendor/bin/phpunit handling the test event returned with error code   1
  </code></pre>