YII2错误-必须为应用程序配置“ id”

时间:2018-06-22 13:25:56

标签: php yii2-advanced-app

当我从frontend \ tests \ unit \ models \ ContactFormTest.php在yii2高级php框架中运行单元测试用例时,出现以下错误

这是我的ContactFormTest.php

 namespace frontend\tests\unit\models;

 use Yii;
 use frontend\models\ContactForm;

class ContactFormTest extends \Codeception\Test\Unit
{

   public function testSendEmail()
   {
    $model = new ContactForm();

    $model->attributes = [
        'name' => 'vinayak',
        'email' => 'vinayak.tanksali@effone.com',
        'subject' => 'very important letter subject',
        'body' => 'hi',
    ];

    expect_that($model->sendEmail('vinayak.tanksali@effone.com'));

    // using Yii2 module actions to check email was sent
    $this->tester->seeEmailIsSent();

    $emailMessage = $this->tester->grabLastSentEmail();
    expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
    expect($emailMessage->getTo())->hasKey('admin@example.com');
    expect($emailMessage->getFrom())->hasKey('tester@example.com');
    expect($emailMessage->getSubject())->equals('very important letter subject');
     expect($emailMessage->toString())->contains('body of current    message');
        }
  }

第一个错误

[yii \ base \ InvalidConfigException]需要应用程序的“ id”配置。

1 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ base \ Application.php:220

2 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ base \ Application.php:202

3 yii \ base \ Application-> __ construct

4 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ di \ Container.php:383

5 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ di \ Container.php:156

6 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ BaseYii.php:349

之前的7 Codeception \ Subscriber \ Module->

8 C:\ xampp \ htdocs \ yii2_test \ vendor \ symfony \ event-dispatcher \ EventDispatcher.php:212

9 C:\ xampp \ htdocs \ yii2_test \ vendor \ symfony \ event-dispatcher \ EventDispatcher.php:44

第二个错误

[yii \ base \ InvalidConfigException]未知组件ID:i18n

1 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ di \ ServiceLocator.php:139

2 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ base \ Module.php:742

3 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ base \ Application.php:580

4 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ BaseYii.php:526

5 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ validators \ RequiredValidator.php:60

6 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ base \ BaseObject.php:109

7 yii \ base \ BaseObject-> __ construct

8 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ di \ Container.php:383

9 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ di \ Container.php:156

10 C:\ xampp \ htdocs \ yii2_test \ vendor \ yiisoft \ yii2 \ BaseYii.php:349

错误! 测试:1,断言:0,错误:2。

有人可以在此先谢谢我吗

1 个答案:

答案 0 :(得分:1)

尝试在您的配置文件(即main.php)中添加ID,如下所示:

recyclerView
yii2需要

ID参数。您需要在前端中进行设置(即frontend / config / main.php)