A
A
artem782017-09-26 00:23:12
Yii
artem78, 2017-09-26 00:23:12

Why are tests not running in Yii2?

When trying to run the standard yii2 advanced test suite, the following error pops up:

Call to a member function haveFixtures() on a non-object 
in /home/user/www/test/yii/myshop/common/tests/unit/models/LoginFormTest.php:22

LoginFormTest.php content:
spoiler
<?php

namespace common\tests\unit\models;

use Yii;
use common\models\LoginForm;
use common\fixtures\UserFixture as UserFixture;

/**
 * Login form test
 */
class LoginFormTest extends \Codeception\Test\Unit
{
    /**
     * @var \common\tests\UnitTester
     */
    protected $tester;


    public function _before()
    {
        $this->tester->haveFixtures([       #   <-------- Здесь происходит ошибка
            'user' => [
                'class' => UserFixture::className(),
                'dataFile' => codecept_data_dir() . 'user.php'
            ]
        ]);
    }

    public function testLoginNoUser()
    {
        $model = new LoginForm([
            'username' => 'not_existing_username',
            'password' => 'not_existing_password',
        ]);

        expect('model should not login user', $model->login())->false();
        expect('user should not be logged in', Yii::$app->user->isGuest)->true();
    }

    public function testLoginWrongPassword()
    {
        $model = new LoginForm([
            'username' => 'bayer.hudson',
            'password' => 'wrong_password',
        ]);

        expect('model should not login user', $model->login())->false();
        expect('error message should be set', $model->errors)->hasKey('password');
        expect('user should not be logged in', Yii::$app->user->isGuest)->true();
    }

    public function testLoginCorrect()
    {
        $model = new LoginForm([
            'username' => 'bayer.hudson',
            'password' => 'password_0',
        ]);

        expect('model should login user', $model->login())->true();
        expect('error message should not be set', $model->errors)->hasntKey('password');
        expect('user should be logged in', Yii::$app->user->isGuest)->false();
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
artem78, 2017-09-26
@artem78

It turned out that the old version of codeception was installed globally. Launched from <путь к проекту>/vendor/bin/codeceptand everything earned.

M
Maxim Fedorov, 2017-09-26
@Maksclub

something with fixtures... try loading fixtures by hand
Managing fixtures
Loading fixtures

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question