首页 文章

YII2错误 - 需要应用程序的“id”配置

提问于
浏览
0

当我从前端\ tests \ unit \ models \ ContactFormTest.php运行yii2高级php框架中的单元测试用例时,我收到一些错误,如下所示

This is my 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');
        }
  }

First Error

[yii \ base \ InvalidConfigException]需要Application的“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

Second Error

[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 .

Can any one please help me out on this thanks in advance

1 回答

  • 1

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

    return [
        'id' => 'app-frontend',
        'basePath' => dirname(__DIR__),
        'controllerNamespace' => 'backend\controllers',
       'bootstrap' => ['log'],
        :::::::::::::
    ]
    

    yii2中需要ID参数 . 你需要在你的前端设置(即frontend / config / main.php)

相关问题