title: yii2 unit testing having error of call to a member function getDb() on null
body: <pre><code>&lt;?php
  
  namespace tests\codeception\engine;
  
  use engine\components\BaseException;
  
  use engine\components\BaseService;
  
  use engine\modules\account\models\AccUser;
  
  use engine\modules\account\models\AccUserActivity;
  
  use engine\modules\account\services\AccountService;
  
  use yii\db\Connection;
  
  
  
  class AccountServiceTest extends \Codeception\TestCase\Test
  
  {
  
      protected $tester;
  
      protected function _before()
      {
      }
  
      protected function _after()
      {
      }
  
      public function getDb()
      {
          $connection=Yii::$app-&gt;getDb();
      }
  
      public function testIsEmailAvailable()
      {
          $account = AccountService::model();
  
  
          // 1. Existing email check
          $email = 'alk@gmail.com';
          $this-&gt;assertEquals(true, $account-&gt;isEmailAvailable($email));
  
          // 2. New email check
          $email = 'arulvel@gmail.com';
          $this-&gt;assertEquals(false, $account-&gt;isEmailAvailable($email));
  
          // 3. Not an email check only character
          $email = 'arulvel';
          $this-&gt;assertEquals(false, $account-&gt;isEmailAvailable($email));
  
          // 4. Not an email check only numbers
          $email = '549876315';
          $this-&gt;assertEquals(false, $account-&gt;isEmailAvailable($email));
  
          // 5. Empty check
          $email = '';
          $this-&gt;assertEquals(false, $account-&gt;isEmailAvailable($email));
  
          return true;
      }
  
  }
  </code></pre>
  
  <p>while running the test it showing an error like this</p>
  
  <p>Trying to test is email available (AccountServiceTest::testIsEmailAvailable)... </p>
  
  <p>PHP Fatal error:  Call to a member function getDb() on null in </p>
  
  <p>/var/www/html/rewards/shopsup-rewards-</p>
  
  <p>web/htdocs/vendor/yiisoft/yii2/db/ActiveRecord.php on line 133</p>
  
  <p>FATAL ERROR. TESTS NOT FINISHED.
  Call to a member function getDb() on null </p>
  
  <p>when accessing that ActiveRecord.php on line 133 it is like</p>
  
  <p><a href="http://i.stack.imgur.com/eMiHV.png" rel="nofollow">enter image description here</a></p>
  
  <p>is there any configuration need to be made??</p>