D
D
des1roer2016-03-23 14:49:57
Yii
des1roer, 2016-03-23 14:49:57

Yii 2 codeception enable model?

I want to write a unit test. But I ran into the fact that I can not connect the model from the application
yii2basic\tests\codeception\unit\models\BehaviorTest.php

<?php
namespace models;
use Yii;
use app\modules\video\models\Video;

class BehaviorTest extends \Codeception\TestCase\Test {

    /**
     * @var \UnitTester
     */
    protected $tester;

    protected function _before()
    {

    }

    protected function _after()
    {

    }

    // tests
    public function testMe()
    {
        $video = new Video();
        $video = $video::findAll();
        $this->assertEquals(0, count($video->id), 'Review count after save');
    }

}

php I:\OpenServer\domains\yii2itmh\vendor\codeception\codeception\codecept run unit Codeception PHP Testing Framework v2.1.7 Powered by PHPUnit 5.2.12 by Sebastian Bergmann and contributors.
Unit Tests (1)---------------------------------------------------- ------------------------------------------------- Trying to test me (models\BehaviorTest::testMe)... Fatal error: Class 'app\modules\video\models\Video' not found in I:\OpenServer\domains\yii2itmh\tests\codeception\unit\models\BehaviorTest .php on line 26

UPD try
<?php
namespace models;
use app\modules\video\models\Video;

class BehaviorTest extends \yii\codeception\DbTestCase {
    // tests
    public function testMe()
    {
        $var = new Video();
        codecept_debug($var);
        $video = $var::findAll();
        $this->assertEquals(0, count($video->id), 'Review count after save');
    }
}

get

Test me (models\BehaviorTest::testMe) Error
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
------------------------------ -------------------------------------------------- -----------------------------
Time: 1.14 seconds, Memory: 8.50Mb
There was 1 error:
------- --
1) Test me (models\BehaviorTest::testMe)
[yii\base\ErrorException] Missing argument 1 for yii\db\BaseActiveRecord::findAll(), called in I:\OpenServer\domains\yii2itmh\tests\codeception \unit\models\BehaviorTest.php on line 12 and defined
#1 I:\OpenServer\domains\yii2itmh\vendor\yiisoft\yii2\db\BaseActiveRecord.php:109
#2 I:\OpenServer\domains\yii2itmh\tests\codeception\unit\models\BehaviorTest.php:12
#3 models\BehaviorTest->testMe
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

how to apply correctly?
what happened des1roer.blogspot.com/2016/03/yii-2-codeception.html

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena Stepanova, 2016-03-23
@des1roer

take away

protected function _before()
{
}
protected function _after()
{
}

inherit from \yii\codeception\DbTestCase or from its successor with the given configuration

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question