S
S
Serrrgio2016-06-05 18:56:00
Yii
Serrrgio, 2016-06-05 18:56:00

How to bypass dependency on yii\web\Request in unit test?

Application based on basic. The dragonjet\opengraph\OpenGraph component is used.
Trying to run standard tests, started with unit. The first error:

1) tests\codeception\unit\models\ContactFormTest::testContact
yii\base\InvalidConfigException: Unable to determine the request URI.
#1  C:\dev\OpenServer524\domains\mysite\vendor\yiisoft\yii2\web\Request.php:769

What is the right way to get around this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Makarov, 2016-06-06
@SamDark

You can try running the unit through phpunit rather than through CodeCeption.

A
Alexander N++, 2017-08-09
@sanchezzzhak

some necroposting
config

paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
actor_suffix: Tester
settings:
    bootstrap: _bootstrap.php
    colors: false
    memory_limit: 1024M
extensions:
    enabled:
        - Codeception\Extension\RunFailed

file
unit.suite.yml
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests.

class_name: UnitTester
modules:
    enabled:
        - Asserts
        - Yii2:
            part: [orm, fixtures, email]
            configFile: 'tests/_config/unit.php'

unit.php file
\yii\helpers\FileHelper::createDirectory(\Yii::getAlias('@tests/_output/assets'));

return [
    'id' => 'test-console',
    'class' => 'yii\web\Application',
    'basePath' => \Yii::getAlias('@tests'),
    'runtimePath' => \Yii::getAlias('@tests/_output'),
    'components' => [
        'request' => [
            'cookieValidationKey' => 'wefJDF8s',
            'scriptFile' => \Yii::getAlias('@tests/_output/index.php'),
            'url' => '/',      # задаем  и ошибки не будет
            'scriptUrl' => '/index.php',
        ],
        'assetManager' => [
            'bundles' => [
                // отрубаем публикацию ассетов
                'yii\grid\GridViewAsset' => false,
                'yii\web\JqueryAsset' => false,
            ],
        ],
    ],
];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question