title: Symfony - authentication of user in test env
body: <p>I am trying to run tests in my Symfony test environment but keep getting an error.</p>
  <blockquote>
  <pre><code>Error: Call to a member function getContainer() on null
  </code></pre>
  </blockquote>
  <p>I figured I have problem with authentication of the user.</p>
  <p>I have loaded a fixture to persist one user object into test database fort the needs of authentications (even if i do not know it that is needed).</p>
  <pre><code>protected function createAuthenticatedClient(): KernelBrowser
  {
      self::ensureKernelShutdown();
      $client = static::createClient();
  
      $session = $this-&gt;client-&gt;getContainer()-&gt;get('session');
  
      $firewall = 'secured_area';
      $token = new UsernamePasswordToken('admin', null, $firewall, array('ROLE_ADMIN'));
      $session-&gt;set('_security_'.$firewall, serialize($token));
      $session-&gt;save();
  
      $cookie = new Cookie($session-&gt;getName(), $session-&gt;getId());
      $client-&gt;getCookieJar()-&gt;set($cookie);
      return $client;
  }
  </code></pre>
  <p>I do not know what am I doing wrong?</p>
  <p>I have to note that my project does the authentication trough <code>x-api-key</code> value in header.</p>
  <p>This is a whole new world in Symfony regarding tests for me, so any guidance and help is highly appreciated.</p>