Answer the question
In order to leave comments, you need to log in
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
<?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');
}
}
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.
Answer the question
In order to leave comments, you need to log in
take away
protected function _before()
{
}
protected function _after()
{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question