Answer the question
In order to leave comments, you need to log in
How to initialize Yii::$app for a test?
I created an application based on https://github.com/trntv/yii2-starter-kit
I'm trying to master TDD, there is a model with such validation rules
public function rules()
{
return [
[['brand_name', 'article_name', 'amount', 'price'], 'required'],
[['price'], 'number'],
[['amount'], 'number'],
[['brand_name'], 'string', 'max'=>Part::BRAND_NAME_MAX_LENGTH, 'min'=>Part::BRAND_NAME_MIN_LENGTH],
[['article_name'], 'string', 'max'=>Part::ARTICLE_NAME_MAX_LENGTH, 'min'=>Part::ARTICLE_NAME_MIN_LENGTH],
];
}
[yii\base\ErrorException] Trying to get property of non-object
#1 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\validators\StringValidator.php:85
#2 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\base\Object.php:107
#3 yii\base\Object->__construct
#4 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\di\Container.php:372
#5 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\di\Container.php:151
#6 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\BaseYii.php:344
#7 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\validators\Validator.php:206
#8 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\base\Model.php:441
#9 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\base\Model.php:405
#10 D:\OpenServer_\OpenServer\domains\abparts.local\vendor\yiisoft\yii2\base\Model.php:185
$config = require(__DIR__ . '/../../config/backend/unit.php');
(new \yii\console\Application($config));
class FooTest extends TestCase
{
protected function setUp()
{
parent::setUp(); //важно вызвать родительский метод
}
//....
}
Answer the question
In order to leave comments, you need to log in
https://github.com/yiisoft/yii2/blob/master/tests/...
protected function setUp()
{
parent::setUp();
$this->mockApplication();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question