Yii2 内置服务器从 index.php 开始

Yii2 build-in server starts from index.php

我正在尝试根据 https://github.com/yiisoft/yii2-app-basic/blob/master/README.md#testing

执行代码接收验收测试

我不明白为什么 yii serve 以 entryScript index.php 开始,而我期望的是 index-test.php。这导致 YII_DEBUG = false,因此无法将电子邮件保存到文件中。

这是我的codeception.yml

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
coverage:
    enabled: true
    remote: false
    c3_url: 'http://localhost:8080/index-test.php'
    include:
      - commands/*
      - components/*
      - controllers/*
      - models/*
      - modules/*
settings:
    bootstrap: _bootstrap.php
    memory_limit: 1024M
    colors: true
modules:
    config:
        Yii2:
            configFile: 'config/test.php'
            entryScript: index-test.php
            cleanup: false

这是我的 acceptance.yml:

actor: AcceptanceTester
extensions:
    enabled:
        - Codeception\Extension\RunProcess:
            - ./tests/bin/yii serve
            - wait 2
modules:
    enabled:
    - WebDriver:
        url: 'http://localhost:8080/'
        window_size: 1920x1080
        browser: chrome
        capabilities:
            chromeOptions:
                args: ["--no-sandbox", "--headless", "--disable-gpu"]
                binary: "/usr/bin/google-chrome-stable"
            unexpectedAlertBehaviour: 'accept'

    - Yii2:
        part: [orm, email]
        entryScript: index-test.php

我已将 c3.php 添加到我的索引 - test.php。这是与原始文件的唯一对比。

您没有为 Webdriver 模块指定索引-test.php。试试这个:

 - WebDriver:
     url: 'http://localhost:8080/index-test.php'
     window_size: 1920x1080

我遇到过类似的问题。也许不是理想的解决方案,但它在本地机器上对我来说工作正常:

在acceptance.yml中:

extensions:
    enabled:
        - Codeception\Extension\RunProcess:
            - php ./tests/bin/yii serve -r=web/index-test.php
            - wait 2

在web/index-test.php:

<?php

// NOTE: Make sure this file is not accessible when deployed to production
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
   die('You are not allowed to access this file.');
}

chdir(__DIR__);

// ignore query params
$file = preg_replace('/\?.*$/', '', $_SERVER["REQUEST_URI"]);
$filePath = realpath(ltrim($file, '/'));

if ($filePath && is_file($filePath)) {
    // 1. check that file is not outside of this directory for security
    // 2. check for circular reference to router
    // 3. don't serve dotfiles
    if (strpos($filePath, __DIR__ . DIRECTORY_SEPARATOR) === 0 &&
        $filePath != __DIR__ . DIRECTORY_SEPARATOR . 'index-test.php' &&
        substr(basename($filePath), 0, 1) != '.'
    ) {
        if (strtolower(substr($filePath, -4)) == '.php') {
            // php file; serve through interpreter
            include $filePath;
        } else {
            // asset file; serve from filesystem
            return false;
        }
    } else {
        // disallowed file
        header("HTTP/1.1 404 Not Found");
        echo "404 Not Found";
    }
} else {
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'test');
    
    require(__DIR__ . '/../vendor/autoload.php');
    require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

    $config = require(__DIR__ . '/../config/test.php');

    (new yii\web\Application($config))->run();
}

链接:

yii2/framework/console/controllers/ServeController.php

PHP: Built-in web server - Manual

PHP built in server and .htaccess mod rewrites