title: Laravel 8 Unit Test
body: <p>I am new to Unit Testing. The application has <code>helpers</code> (<code>App\Helpers\Helper</code>, <code>'Helper' =&gt; App\Helpers\Helper::class</code> added to the aliases in the <code>config</code>).</p>
  <p>For tests, it is necessary to use the functionality of the helpers, since authorization goes through another service, and I send all requests there from the helpers.</p>
  <p>Test code itself:</p>
  <pre class="lang-php prettyprint-override"><code>class ParticipantsTest extends TestCase
  {
      use RefreshDatabase;
  
      public function test_createParticipants()
      {
          $participant = Helper::getRandParticipant();
          $type_participant = Helper::getType(2);
          $token = Helper::chooseToken($type_participant);
  
          $response = $this-&gt;post('/api/participants/create', [
              'token' =&gt; Helper::renewToken($participant, $token),
              'type_participant' =&gt; $type_participant,
              'callback' =&gt; $this-&gt;faker-&gt;sentence(20),
          ]);
  
          $response-&gt;assertStatus(200);
  
          $this-&gt;assertTrue(count(Task::all()) &gt; 1);
      }
  }
  </code></pre>
  <p>When passing the test, I get an error:</p>
  <blockquote>
  <p>Attempt to read property &quot;participant&quot; on <code>null</code></p>
  </blockquote>
  <p>Although when I send a test request to the API using the <code>getRandParticipnat</code> method, I get a random participant, and in the tests it is <code>null</code>, how I can fix it?</p>
  <p>Thanks</p>
  <p><strong>UPD:</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;php&gt;
      &lt;server name=&quot;APP_ENV&quot; value=&quot;testing&quot;/&gt;
      &lt;server name=&quot;BCRYPT_ROUNDS&quot; value=&quot;4&quot;/&gt;
      &lt;server name=&quot;CACHE_DRIVER&quot; value=&quot;array&quot;/&gt;
      &lt;server name=&quot;DB_CONNECTION&quot; value=&quot;sqlite&quot;/&gt; 
      &lt;server name=&quot;DB_DATABASE&quot; value=&quot;:memory:&quot;/&gt; 
      &lt;server name=&quot;MAIL_MAILER&quot; value=&quot;array&quot;/&gt;
      &lt;server name=&quot;QUEUE_CONNECTION&quot; value=&quot;sync&quot;/&gt;
      &lt;server name=&quot;SESSION_DRIVER&quot; value=&quot;array&quot;/&gt;
      &lt;server name=&quot;TELESCOPE_ENABLED&quot; value=&quot;false&quot;/&gt;
  &lt;/php&gt;
  </code></pre>
  <p>I think I'm need to reconfig for mysql connection? If I'm do that, can test clear DB with my real data?</p>