jeudi 26 mai 2016

yii2 unit testing having error of call to a member function getDb() on null

<?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->getDb();
    }

    public function testIsEmailAvailable()
    {
        $account = AccountService::model();


        // 1. Existing email check
        $email = 'alk@gmail.com';
        $this->assertEquals(true, $account->isEmailAvailable($email));

        // 2. New email check
        $email = 'arulvel@gmail.com';
        $this->assertEquals(false, $account->isEmailAvailable($email));

        // 3. Not an email check only character
        $email = 'arulvel';
        $this->assertEquals(false, $account->isEmailAvailable($email));

        // 4. Not an email check only numbers
        $email = '549876315';
        $this->assertEquals(false, $account->isEmailAvailable($email));

        // 5. Empty check
        $email = '';
        $this->assertEquals(false, $account->isEmailAvailable($email));

        return true;
    }

}

while running the test it showing an error like this

Trying to test is email available (AccountServiceTest::testIsEmailAvailable)...

PHP Fatal error: Call to a member function getDb() on null in

/var/www/html/rewards/shopsup-rewards-

web/htdocs/vendor/yiisoft/yii2/db/ActiveRecord.php on line 133

FATAL ERROR. TESTS NOT FINISHED. Call to a member function getDb() on null

when accessing that ActiveRecord.php on line 133 it is like

enter image description here

is there any configuration need to be made??

Aucun commentaire:

Enregistrer un commentaire